Project: Water Softener Salt Level Detector

In my house, I have a water softener. This requires topping up with salt at varying intervals, depending on the usage. In the year I’ve been living here, I’ve forgotten twice. Whilst it’s not the end of the world, it does mean that we get some limescale build up on the taps and, more annoyingly, the shower head. I’ve tried a recurring calendar entry to remind me, but the reminds would happen pop up when I was at work, or out and about etc. By the time I got home, I’d forgotten about it. This sort of small annoyance was something I felt could be fixed with a overly complicated, time consuming, technological solution!

The problem

My water softener has a large compartment at the front, which you fill with salt tablets. Overtime, these get used up as the software regenerates itself.

I wanted a way to detect when the level of the salt had dropped to a low level.

How to measure the level?

My first pass at this problem involved using ultra sonic ranging device. I purchased a simple unit that was good for distances up to three metres. More than enough for my needs. To power this unit and make the necessary calculations, I chose a Raspberry Pi Zero, the latest entry to the Raspberry Pi Family. At about £9 it seemed like a good option to get me started on my first IoT project. To be honest, I bought one on a whim and needed to put it to work!

I connected it all up and, in testing, it worked very well. I went as far as to build a simple iOS app to display the current level (I even build a simple web page with SignalR!!!)  Unfortunately, it was useless when it came to the salt. Ultrasonic works best with flat surfaces and the top of the a pile of salt tables is anything but level! I thought about placing a piece of word or plastic on top of the pile, but this seemed like a hack. Okay, the whole thing is a hack, but I have to maintain some standards!

I went back to the web and started researching how people measure levels like this in real life, coal bunkers and whatnot. They use lasers. I didn’t want to spend any more money than absolutely necessary, so I would need a different approach.

The idea when struck me that I could use a reed switch (one that turns on in the presence of a magnetic field) and a wooden rod with a small magnet on it. The rod would rest of the pile of salt and move downwards, inching the magnet closer to the switch. On paper, this seemed like it would work, but in practice, I didn’t have enough space above the softener for the rod to protrude.

 

img_5492

The initial circuit board with the reed switch

I then had another brainwave. Replace the rod with a piece of string and a weight! The effect was the same, but it didn’t require the space! Genius.

img_5493

Waterproofing the *complex* electronics

img_5494

A lid with the mechanism attached

img_5495

Side view showing the string coming through

I put all the electronics into a water proof box and fed in the USB power cable. I added some LEDs to give me some idea it was working (green indicated my software was running and red indicated low salt). I moved the reed switch to the end of a piece of cable, so I could better position it. Some gorilla tape and a straw (to ensure the string moved unimpeded) and my contraption was complete!

I mounted the contraption onto my softener, replacing the lid.

img_5497

The software is designed to send me an alert once the salt runs low. As tempted as I was to write my own app and host a back end server, sanity prevailed and I just used IFTTT to raise an alert.

img_5498

An IFTTT alert telling me to top up the salt

Summary

The contraption has been in place now for a few months (it’s taken me that long to write this bloody blog post!) and it’s not been a mixed bag. I’ve gotten one alert, which arrived at 3 in the morning. Another time, I just checked the softener on a whim to discover that the salt was low, but the string had snagged and got stuck. I freed it and a second later got the IFTTT alert. At least it proved my python script was reliable.

I’ve put some plastic on top of the wood to ensure the string never snags again and I’m expecting an alert in the next few weeks.

The future?

With version one in place and working, I’ve started thinking about version 2. These are the improvements I plan on making:

  1. Switch to an MCU (Micro Control Unit). The Pi is great, but it’s overkill (running a full OS) and uses much more power than necessary. The NodeMCU board, for example, can be put into a deep sleep, which users very little power.
  2. Replace the breadboard with a PCB to reduce space.
  3. Trigger the measurement at fixed intervals and only notify me when I’m *actually* home. The last part I’m not sure about, but I suspect IFTTT can *know* where you are.
  4. Potentially use an IR sensor for distance measurement. Whilst this would eliminate any moving parts, it would require a hole into the salt holder and I’m worried that water might splash out or onto it.

Best laid plans, part 2

After my little boo-boo with measurements, I purchased a new Wiska junction box from RS, this time with a little more width and the Sonoff relay fit perfectly! I also picked up some IP66 glands to help secure the wire from the LED strip.

IMG_5011

This junction box had a membrane covering each hole, so I pierced a hole in it and fed the table through. The gland then screwed into the threaded hole (what makes these Wiska boxes so great).

IMG_5013

I tightened it all up.

Sadly, I didn’t take any pictures of my SWA cable gland process as I did it at lunch time. This was the tricky part of my installation since it required a hacksaw. I found a great YouTube (https://www.youtube.com/watch?v=epmxqFiD9JI)  video and followed that as best I could. I didn’t have the “glanding spanners” as recommended, but I made do with pliers. I do plan on using another armoured cable to connect to the other side of the garden, so I’ll take photos of that.

Anyway, with everything installed, I dropped the box in the garden.

IMG_5014

You can see the thick black SWA cable and the thin LED cable. I should point out that this is not the final resting place of this box!

IMG_5017

The lights look pretty nice in the snow and light the garden pretty well.

This weekend I plan on getting a few metres of SWA and using the small junction box to hook up the lights on the other side of the garden!

Best laid plans…

Wanted to work on my garden LED lighting project weekend. Unfortunately, I may have made a slight miscalculation with my measurements…

IMG_4996

I placed an other with RS for a replacement box, this time a little wider! If all else fails I can always take the circuit board out of the case and place it directly in the junction box, but I’d rather keep it housed.

I did manage to test it out though and the lighting is effective enough.

IMG_5002

Maybe next weekend?

 

WiFi enabling my porch light with a Sonoff Basic Smart Switch.

Having failed to read the warning regarding neutral wires, my attempt at using a Sonoff T1 Smart Switch to control my porch light went down in flames. My plan B was to try using a Sonoff Basic WiFi Smart Switch to perform the same job. My plan to put the relay between the ceiling rose and the bulb holder. It wouldn’t be pretty, but the aim was to test utility before spending £££ on proper smart switches etc.

IMG_4927

As you can see, my porch light is pretty standard.

First step, I turned off the power at the fuse box. Can’t stress this one enough. Don’t go near any mains electricity until you’ve isolated the power. Don’t just turn off the light switch!! I gathered all the parts and tools I’d need.

IMG_4928

I then disconnected the light bulb holder, removing the little red plastic thing and the curved lid.

IMG_4929

Using a short piece of flex, I connected the Smart Switch directly to the light bulb holder.

img_4930.jpg

Next, I connected the Smart Switch to the cable hanging from the ceiling!

img_4933.jpg

As it was hanging a bit low in the porch now, I created a loop and used two tie-wraps to hold it in place.

As it was all hooked up, I turned the power back on. Nothing started to smoke, so I knew I’d gotten that part done okay. The green light appeared on the relay and I started the pairing process. This involved holding down a black switch on the relay for a few seconds until the green light started flashing quickly.

I then launched the EWeLink app and hit the Add Device button. The process is straight forward. When you push the button down on the device, it creates its own WiFi network. You then connect to that WiFi network, enter details of your own WiFi network (SSID and password) and it then connects itself to your EWe account.

IMG_4939

Following the instructions, I found the Smart Switch’s WiFi point and connected.

img_4937.png

Once connected, the pairing process starts.

IMG_4940

IMG_4941

IMG_4942

After a few seconds, you’ll be able to control the device! I tapped on the power and, eh voila, the light came on.

img_4943.jpg

Job done!

Smart switches and the missing neutral!

As part of my learning and experimentation with Homekit and home automation, I recently picked up some Sonoff Basic Smart Switches. I’ve successfully installed one them outside, controlling a few metres of LED strip lighting.

IMG_4901

It’s pretty novel to turn it on and off via Alexa or from my iPhone, but to be honest, it’s not very practical. Flicking a switch is just than saying “Alexa, <pause> turn on the side alley light”. Pause. <click>. “Ok”.  Whilst voice control gives you flexibility (hands full etc.), 99% of the time the light switch is the king.

In my quest to check whether the smart home is practical, I wanted to try out a proper, in the wall, smart switch. I’d found a few companies such as Den Automation (who I’ve actually invested in, but who’s stuff isn’t on sale yet) and Lightwave RF, who make normal looking switches (normal from a UK style). The downside is that this stuff is expensive.

Taking Lightwave for example, a single Lightwave switch will run you £60. They also require a hub or bridge, which means an additional outlay of over £120 before you can even use the switch! Spending the bones of £200 just to check whether a smart switch is useful or useless is a bit much. I needed something cheaper to get me started!

Enter the Sonoff T1 WiFi lightswitch

IMG_4906

I dropped £31 and bought two switches, a two-gang and a three-gang. Aesthetically, I don’t find them appealing since they are just white and I hate touch buttons, preferring something that actually clicks.

I digress. The first step with any new light switch is to actually install it in your house. For me, I wanted to get the maximum value, so I opted to replace the three gang switch in my hallway. The hallway light switch operates the hall light, the porch light and the upstairs light. Three lights that are used pretty frequently.

I started by unscrewing the switch.

Then I stopped.

87511ccd-fec2-47c8-9a21-8614384fd6f2.jpg

There were more wires than I expected!! I knew the upstairs light and the hallway light were three-way switched, but the porch light isn’t.

The back of the T1 looks like this:

be45ce20-c3db-4cf7-839a-94390716b749.jpg

I was going to need some professional help! Thankfully, as my father and two of my brothers are electricians, I could get *free* professional advice.

After getting a handle on the wiring, I realised that the T1 switches just wouldn’t work. No neutral connection was available. I mistakenly the blue wire to be neutral when it is switched live. I should have paid more attention when my father was teaching me this at age 15. I checked a few more of the switches and confirmed that there was no neutral in any of them.

The listing for the Sonoff switches on Amazon does indicate that a neutral is required, but since I mistook the blue switched-live for a neutral, I went ahead and bought them. I’ll be returning them.

This was a disappointment.

My main annoyance was that I’ve only had my house completely rewired last year. I was kicking myself because this should have been something I was aware of. That said, a lost of forum entries seem to indicate that most electricians won’t add a neutral that doesn’t connect to anything. Even if I did ask my electrician to add a neutral to each switch, he could very well have said no.

At this point, I took a step back. The Sonoff switches simply weren’t going to work.

The Lightwave RF stuff was too expensive for the purpose of playing around.

I needed a plan B. I decided to put one of the Sonoff Basic Smart Switch onto my porch light. This would mean leaving it switched on at the wall, but I figured that would be okay. I’ll do another post on that soon.

 

Running my .Net Core mDNS service on Windows IoT

As part of my ongoing experiments with C# and mDNS (to build my own Homekit accessory), I got to the point where I wanted to run my code on a Raspberry Pi.

Microsoft have released a version of Windows 10 that will run on a Raspberry Pi in a headless mode. The main advantage of this is that it contains the .Net Core runtime!

To get started, download Microsoft IoT manage and fire it up. Under the menu, you’ll see an option to Set up a new device. This lets you flash an SD card with the code necessary.

iot flashing UI.PNG

iot flashing.PNG

Once the formatting and flashing is complete, you’ll have an SD card containing Windows IoT. Pop this into your Raspberry PI, and after a minute or five it will appear under the My devices view.

To get me started, I launched Remote Powershell. When it started, I got prompted for credentials.

iot powershell ip.PNG

This includes the IP Address and the account Administrator (the password for which, you set earlier). I found that this just didn’t work. I replaced the IP address with the machine name (minwinpc) and it worked!

iot powershell ip domain.PNG

I just realised this is a real Windows XP dialog!

After Powershell started, I opened a file share and created a directory called Climenole. To get my little Console app ready, I needed to compile it for ARM. Thankfully, this was straightforward. From the command prompted, I ran this command

dotnet publish -r win-arm

This compiles the app for the win-arm architecture. From the project directory, you can access

\bin\Debug\netcoreapp2.0\win-arm

to see all the published files. I took all these files and copied them across to the Climenol directory I created on the Raspberry Pi.

Once the copy completed, I could run my app using Powershell.

iot wrong ip address.PNG

It didn’t work the first time as the hardcoded IP address wasn’t right, but after a tweak,

iot responding to packets.PNG

It started answering responses and even appeared in Homekit.

img_48941.png

A good first step and proved that my mDNS was portable.

Next challenge is getting all the crypto code working, so that I can actually add and control the accessory from Homekit. It was a pain to get it working on the .Net Framework, so I suspect it will be no picnic on Core!