Playing around with Tasmota - as the sensing core of an IoT-based swimming pool temperature control system.
Short post today, due to time. I’ve been playing with Tasmota which is embedded firmware for the ESP8266 and ESP32 (in beta). If you want to get started FAST this is what you want.
You need the ability to flash an ESP8266. Once you can do that, you can pluck the generic build and flash the device. It reboots and comes up as a WiFi Access Point (AP). You connect to that AP and configure the credentials for your own AP. It reboots, and then you connect to it again and configure logging, MQTT, and tell it what is connected to the GPIO pins.
This deserves a real post, with screen shots and photos but I don’t have time today.
Beware though, and don’t rush these things. I grabbed the wrong power supply for a test and plugged it into the ESP8266. Yes indeed, the 5V to 3.3V regulator did NOT like 12VDC applied. I turned around to connect to it with the web browser and by the time I realized it was not online I started to smell it. I let the magic smoke out. Ugh.
One blown up ESP9266. I’m glad they are cheap!
I bet you thought I was going to say I dropped it in the pool right? Ha ha ha. I’d tell you a story about building a floating pool temp thermometer but I definitely don’t have time for that.
What I do have time to tell you is that it just works. This is what I am using for my home IoT foundation. I already have it in production use on two outside lights and my basement lights using the Shelly 1 Relays. These are hacker-friendly relays built around the ESP8266 that actually expose the pins so you can re-flash them. Love these devices.
What?
Here are a few of the things I am currently working on:
- Water Flow Sensor (this one)
- Water Tank (Cisterna) Level Detector (these)
- Water Temp Sensor (this sensor) - (this thermowell)
The electronics on all this works, and I can measure and send data to an MQTT broker from the bench with all the sensors connected to a breadboard. It’s the “put in a real world box and power it” part that I’m working on now. The hard part!
I also am measuring sunlight. I am NOT using a light sensor, but instead am using a tiny solar panel (this one) which is $3 each and rugged as hell. Drop the output across a 50-50 volatege divider and read the split using the Analog input on the chip. BEWARE: most ESP8266/ESP32 read full range (0-3.3V) but some are 0-1V. Check it and adjust your divider appropriately. You can put the voltage divider resistors in the package with the panel and pot it with epoxy (this stuff) and run two wires out into the sun with no worries about capacitive issues on an I2C signal. And unlikely to die in the weather.
Of course, none of this is working anywhere but my bench yet. I need to get a move on packaging it up so it can live out in the real world.
Why?
I have a swimming pool, and I have a solar pool heater. It’s basically some black glass tubes that sit in the hot sun and the water inside gets hot. Periodically you open the valve and the water is flushed into the pool, making it warmer. To get the most efficiency you want to open the valve once the water is as hot as it’s going to get, assuming the pool water actually needs to be warmed. The system came with a timer for the electronic valve, which does not work well since sometimes it’s cloudy, sometimes the water is warm enough already, etc.
So, I’m adding a temp sensor in the water recirc flow to tell me what the pool temp actually is. I was building a floating sensor, powered by a solar panel, but… well. Lots of problems with that idea. That’s another post. The valve from the solar water heater will get a Shelly 1 to control it. Basically I will measure the temp of the pool water and the strength of the sunlight. The temp of the water in the glass tubes is harder to measure since it’s not flowing. I can sort of measure it with a temp sensor clamped to the copper piping, which is what I will do. But I don’t trust it, since without flow it’s just the temp at that spot. Plus, it will be in the sun itself. So I don’t really trust that data and if the long wire run has too much capacitance for the one-wire sensor to be read then I won’t even install it.
Basically, I’ll constantly watch the pool water temp and strength of the sun. The solar panel is outputing volage proportional to the energy delivered by the sun. That can be calculated as “volt-seconds” of energy. The temperature rise of the water in the in the heater glass tubes will be proportional to that. A duration of water heating up is a “baking period.” Periodically I will open the valve and measure the increase in pool temp that results. I’ll program it to try different baking periods and measure the resutls. Within a few weeks I’ll have enough empirical data to know how many volt-seconds are needed to accomplish the optimum increase in pool temp. Then I can modify my control algorithm to just go from that and keep my pool at the best temp I can using ONLY the sun for energy.
Now, I have a sense that I could use some ML for this. I could possibly use the data I gather over a few weeks to train an ML model to maintain as close to the desired temperature as possible. And I’ll probably do this as a practical project to “learn by doing” as I start to do more IoT ML work. Should be fun!
That’s the plan anyway. I’ll let you know how it goes in the real world!
Wait, What About the Water Flow and Tank Sensors?
Ah yes. Those. Somone left a hose on to water the yard and that just happened to match up with the City doing some work on the water system. This resulted in my underground water tank (Cisterna) getting drained, which then triggered the float valve on the water pump to shut down to protect it, which resulted in no water pressure in the house at all. Bad juju. Can’t even flush the toilets. Bad juju. A quick test with the hose filling a 2-liter bottle told me the flow rate: my hose delivers 6 liters of water per minute. Yes, Virginia, my 5000 liter cisterna can get drained dry in 13 hours. Overnight, basically. And if no one is home, you can have an unhappy house the next day.
Since we are currently blind to that scenario, especially from remote, I am going to put a flow meter in and if water flow exceeds some normal amount for more than say, and hour, it will send an alarm. Likewise the float valves in the cisterna. If the level starts to go down then we should know it so we can reduce water consumption drastically so we have a water supply at least. I am definitely planning on tying this to AWS Greengrass and use AWS SNS to text me when these kinds of alarms go off.
The water flow meter is easy since it can go inline near the pressure tank where I have easy power available, and it’s in a protected space. The cisterna is under my garage floor. I have 240VAC there for the water pump. So I had to buy one of these small power supply modules and am potting it inside a water proof box to sit near the tank. Not at all sure that’s a good solution, since the WiFi may not get through the concrete to where my AP is. I may end up having to run some long, thin wires and put the ESP8266 somewhere where it’s radio can see. Only testing will tell.
What Else?
Yes, I do plan to tie my Unifi cameras into AWS Rekognition. I’ve worked through a blog about how to do it with an ESP32 as a demo. My actual architecture would be different, and not only because I can react to the Unifi Protect motion sensing and grab an image directly from the camera. It’s a bit hacky. I wish Ubiquity would just expose an MQTT feed, but hey.
I also have a Weather Meter Kit and actually tried to test the wind speed annemometer. No joy. The datasheet says 1 contact closure per second equals 2.4km/hour of wind. But tasmota does not count those pulses, for some reason. Same basic reading as the water flow meter - pulses per second - but no joy. I know the pulses are happening too, because I can see them on my scope:
I set that aside for later. I need the pool and water tank done!
Conclusion
So you see, I have a TON of projects queued up. And these are not just learning projects, but stuff that I really want to get done and use in my normal life. On top of trying to learn Spanish and my very full time job at AWS it’s going to be a busy year.