Swimming Pool Chemical Dispenser

HI, @auredor,

I’m not using ESPHome. Actually, I wasn’t aware that this existed. I briefly looked at it just now online and it looks interesting. Could be that this is a good solution, but for now at least my implementation doesn’t use it.

I’ll put together some better instructions for this, but briefly my program is written in micropython. So, the main steps are to take your ESP32 DEV board and first flash micropython. Here are some instructions on how to do this. Importantly, my code relies on mqtt_as.py, which only works in relatively recent (mid-May, 2020 or later) releases of micropython for the ESP32. So, when you flash the firmware make sure you are getting a recent release off the micropython site. All of my ESP32s currently use v1.12-450, dated 2020/05/11, but I suppose any of the later releases should also work. Once you have flashed micropython on your device, then you can upload my code (I use uPyLoader, but other tools are available as well). You need to edit the init.txt file first to provide all the configuration details, then upload it with uPyLoader. Once you restart, you should see readings coming over your MQTT broker.

Regarding your idea to “monitor” the tank level by adding up the amount dispensed in various pump runs. This would probably work. I did some experiments using a kitchen scale to measure the amount of bleach dispensed into the pool and the function was very linear with pump run time. I’m not sure how it might vary with pressure in the line (for example, if you have a variable speed pump, the rate of bleach injection MIGHT vary with the speed of the pump). One of the reasons for trying to integrate the load cell is to be able to keep track of the dispense rate under varying conditions. If it proves to be resilient to changes in pressure, temperature, etc. then it may in fact not be necessary to use the load cell and use a calibrated dispense rate instead. Yet to be determined at this point…

I have updated the github site to include the Gerber files and Eagle design files for the main board and daughter board. I’ve also included a BOM for the PCBA (only, at this point). I will prepare a higher-level BOM including the mechanical parts soon.

Thank you.

I’ve just checked the PCB using altium 365 viewer and it looks like they are some missing holes for those Net : N$11, N$20, N$29, N$18, N$17, VCC and GND). It might be the viewer. I don’t know (https://www.altium.com/viewer?token=NnjOq5BcL0akXdUyx0sIi50S).

Any news on the Higher-level BOM?

Thanks.

Hi, All, very sorry for the long delay. I got busy with some other projects and am getting back to this one. I’ve added a document with the higher-level BOM materials to the Resources tab on the Github site. I didn’t include common items like wires, heatshrink, etc. as if you’re contemplating building something like this you hopefully have some spare stuff lying around. I did, so that’s why I don’t have a specific part number recommendation for you. But the main components like the pumps, tubing, housings are all there. Please let me know if you still have questions. @auredor, sorry but the link to Altium has expired (my fault for so long a delay). I had no problems with the boards made from this design, but I’ll double-check the areas you mentioned. If I can find something wrong, I’ll post a solution. Feel free to post another link if you’re still having issues.

Hi @smurry. Thank you for the High-level BOM. Not sure everything is available here in Europe… But at least I’ve got some references.

FYI I’ve just noticed that Atlas-scientific releases some low cost pH and ORP sensors + boards with an analog output. There are much less accurate but my feeling is that is enough for pool chemical control. What do you think ?

Here are a new link to the board file in altium viewer. The link is only available for 48h but you can directly refer to your files from github using the “raw” file address within altium viewer

Hi, @auredor, I checked the viewer link you provided. It is very strange, but you are correct that the viewer doesn’t show the holes for the headers in the locations that you noted. They look fine in Eagle and as I said I had no problem when I sent the Gerbers out for manufacture, so I think the anomaly is something with the viewer, rather than with the files. For your information, the net definition is as follows:
N$11: 3.3V intended to power the temp sensor
N$20: DQ for the temp sensor (DS218), connected through 4700 ohm resistor to IO27
N$29: Serial data out for the load cell amplifier
N$18: Serial Tx for Ph carrier board
N$17: Serial Rx for Ph carrier board

The specific locations where these nets terminate contain holes for pins with 2.54mm spacing. You can use standard headers (male or female as appropriate), or use some wire to connect up the appropriate devices to these pins.

Regarding the analog sensors, yes I did see these. I have not tried them, but I’m sure the accuracy would be good enough for pool monitoring. Might be interesting to try them out.

Are you going to do a ESPhome version or are you happy enough not to want to take the time?
I’m using a Pi with Node Red reading the values now but want ESPHome because I had my Pi overheat multiple times so far this summer

Hi, @DrJeff, I don’t anticipate doing an ESPhome version. I’m not that familiar with ESPhome, although a brief look through the documents makes it sound like it might have been a good option had I known about it when I started. For now, the version that I have built has been working very well for a couple of months and I’ve got a few other projects in mind that I’ll probably work on next.

If anyone does decide to do an ESPhome version, I’d be happy to contribute whatever knowledge I can, though.

1 Like

I’ll hold you to that! :rofl:

very nice project!!

@smurry how hard is it to add all availible GPIO pins to mqtt in MicroPython that would be awesone

I’m not sure I follow your question, but let me try. I think you’re asking about whether you can change GPIO states over MQTT with Micropython. If this is correct, it is pretty easy. So far, I’ve used this approach to create an irrigation (i.e. sprinkler, if you’re in the USA) controller and the pool controller here.

Without a lot of detail (happy to add more if you need), I write a program in Micropython and run in on the ESP32. The program basically connects to Wifi and MQTT. Then, it listens on some topic that you define. If it receives a command over MQTT then it does {something}. {something} can be changing a GPIO, or possibly taking a reading and returning it, or whatever other thing you might want the ESP32 to do. Also, you can quite easily publish whatever you want to any mqtt topic you desire.

So, for example, in my pool controller, I can send a command over MQTT to a topic like “Pool”. Something like ph:on:120. When this is received, the program will toggle a GPIO pin to turn “on” the ph pump (that is, the acid pump) for 120 seconds. ESP-32 turns on the GPIO and starts a timer to wait 120 seconds then turns the GPIO off. Also, after receiving the command, the ESP32 publishes an MQTT response over “Pool/resp” something like ph:on. Then I set up an mqtt sensor in HA to show the state of the ph(acid) pump.

A key module to check out is mqtt_as (https://github.com/peterhinch/micropython-mqtt). This is an asynchronous MQTT driver that handles all the mqtt low-level stuff and makes receiving and publishing really easy.

I hope this answers your question. If I’ve missed the mark, please ask again and I’ll attempt a better response.

Ok I get it now Micropython runs scripts (mini apps), never used it looked at it years ago. I will ask later as needed.

Thanks

Ok I like this Micropython!! :slight_smile:
Do share your sprinkler project I like how you did this pool setup and want to steal your irrigation. Did you do the run time set the same way you do tis one?

I haven’t shared the irrigation controller. I can put it up on Github, though, since you’re interested. But basically the operation is the same. For example, in the irrigation program, the MQTT command zone1:on:10 would turn “on” a GPIO pin connected (through relays, etc.) to a solenoid valve for zone 1. Just like with the pool pump, the ESP32 will respond to a sub-topic with a response zone1:on, which is listened to by an MQTT sensor in HA. After the allotted time (10 minutes using the command example above), the ESP32 will turn off the GPIO pin, and send an MQTT response zone1:off. Really, from the standpoint of the ESP32 there isn’t any fundamental difference between the irrigation controller and the pool chemical dispenser controller. They both just wait and listen for a command, then turn something on for a set period of time, then turn it off again.

Nice! do share
I think I love this, Thanks for the awesome work!!
Is there a way to turn on with out the delay or does the code need to be changed?
I added extra pumps and I want to add valves to your pool setup but currently it is set for timed (wait) only. I want to turn on until the off command is sent.
i.e.
spa_pump:on
and it will stay on indefinitely

@smurry Have you tried coding it in Visual Studio Code with REPL it is a match made for each other.

Currently, all the “on” commands have a delay, but this would be easy enough to remove this. However, a work-around would be to simply use a long delay. For example, you probably don’t really want your spa to be on forever. Maybe you plan to use it for a few hours. You could set it to auto-off after, say 300 minutes (5 hours). The irrigation controller has a “stop” command which can be sent separately. The pool controller doesn’t, but it could be easily added.

1 Like

Yes that would work even better then the timed off. Now it would work like a watchdog timer in the irrigation controller.

Perfect

That is pretty cool. I personally use ATOM as the editor and I open another window in putty to see the output, but I like having both in the same screen like that. Thanks for the tip. One other helpful tool is uPyLoader, which simplifies loading the code on the ESP32.

You use REPL