So, I have a salt water pool. To keep the water healthy I have an automatic chlorinator that takes diluted hydrochloric acid (HCL) and uses that to reduce the pH if required as well as mix it with the salt in the pool to create chlorine to in turn sanitise the water. The chlorinator uses a peristaltic pump to slowly draw HCL out of a plastic container, which in turn needs to be topped up manually - how much the chlorinator uses depends on a number of factors including the concentration of HCL in the container, weather, and pool usage. If the container runs out of HCL, then the feeder tube will fill with air and the pool itself may become dangerous to use and basically it’s a nuisance. So I wanted to get an alert if the HCL level in the container was getting low and needs to be topped up, rather than relying on me remembering to check it regularly.
I couldn’t use standard sensors because they risk contact with the hydrochloric acid which is not great for longevity because, well, acid. Think Indiana Jones and melting faces.
So non contact sensor then. There were a few options, but the best one seemed to be the XKC-Y25. This has some water resistance (important as the sensor would be stuck to the side of the HCL container and could get wet), can detect the presence of liquid over a cm away so would have no issue with the plastic container, and as an added advantage is not expensive.
There are multiple versions available such as XKC-Y25-V, XKC-Y25-RS485, XKC-Y25-PNP, and XKC-Y25-NPN. The RS485 version runs at 48V, the PNP/NPN versions are designed to be connected to loads such as buzzers so will likely need a pull-up resistor. I however just used the XKC-Y25-V which happily works with 5V from the Wemos D1 without any mucking around. You can get these from the usual suspects - I wasn’t in a rush, so got it from Aliexpress. I decided to just get the one - partly because if it didn’t work then I wouldn’t be out of pocket much, and partly because I just wanted to be alerted if the HCL container was getting low. You could if you want get a number of them so you could track different levels - eg with three you could do full, 75%, 50%, and 25% - but you might want to have a separate power supply if you want to hook up a large number of them. As an aside, you can also adjust the sensitivity by twisting a screw under the cap - but for me I didn’t need to do that.
Back to the build. There are four wires - we only need three of them. The black one is used to change it between normally open to normally closed. You might want this if you are hooking it up to something dumb like a buzzer and have a use case where you want it to make a noise if the level is too high. All the smarts for my purposes are covered by Home Assistant, so I just need data (yellow - I ran it to D5), power (brown - ran to 5V), and ground (blue - ran to GRND). Colours seem to be standardised on the things, but double check just in case.
That is literally it. Just need to program the esp826 via esphome.
binary_sensor:
- platform: gpio
pin:
number: D5
device_class: moisture
name: "HCL Level Sensor"
Then an automation eg:
alias: HCL Level Low
description: ''
trigger:
- platform: state
entity_id: binary_sensor.hcl_level_sensor
to: 'off'
from: 'on'
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- service: persistent_notification.create
data:
message: HCL container in pool is getting low 💀
title: HCL container in pool is getting low 💀
mode: single
Then stick the sensor to the side of the container, about a quarter of the way from the bottom, and done. When the container has about 25% left, a warning appears in the web interface.