PoolMCU – tripping switches with octocouplers
Today on the hookup we’re going to learn how to connect an automatic pool controller to your smart home using a NodeMCU.
This big box is called a pool controller and it’s basically the brain of my pool. You can buy all kinds of addons for these things to be able to control them remotely. When I had my pool installed we paid for the RF remote to monitor the temperature, switch between spa and pool modes, turn on the cleaner, and control the lights. 3 years after installing this $500 addon it stopped working and I was forced to either pony up another 2 to 3 hundred dollars to replace the burned out transmitter board, or walk out to the control unit every time I wanted to heat up the spa or change a setting on the pool. Another option was to spend $400 to buy the board that lets me access my pool controller via the Pentair Screenlogic app, but that’s yet another app on my phone and it still can’t interface with the rest of my smart home.
As is often the case, the final and best option here was for me to build a solution myself.
For less than $20 in parts I installed a nodeMCU to interface with my pool via MQTT, and it was much easier than you think might expect. Links are down in the description for all of the parts you’ll need for this project.
On my pool controller which is a Pentair easy touch 4 there is an option to connect a set of 4 buttons called a “spa side remote” that is supposed to be mounted somewhere near your spa and can turn the lights on and off, and toggle modes between pool, spa, and cleaner. Don’t be discouraged if you have a jandy, hayward, or some brand of pool controller, spa side remotes are available for almost all of them and they have very similar electrical connections inside.
I don’t actually want a spa side remote, what I want is to emulate a spa side remote from my smart home devices. The connector for the spa side remote has 4 pins for the 4 buttons and one common small positive voltage and an output for an LED. What we need to do is emulate a button press and for this particular case I’m going to use something called a optioisolator.
An optioisolator is sort of like a switch. It’s got an input leg and an output leg with a photoresistor in between. When the photoresistor is not exposed to light the resistance is near infinite which will not allow current to flow, but when a light is shined on the photoresistor the resistance drops to near zero and the current can flow from the input to the output. So what supplies the light? An LED on the other side of the optoisolator is connected to a GPIO pin on your microcontroller and then to ground, when you use the digital write high command it turns on the LED, reducing the photoresistor resistance to near zero, which simulates a button press.
The added benefit of an optoisolator and the reason it got its name is that since the two sides of the circuit are only connected via light, not wiring, the chances of your microcontroller frying your device, or vice versa is significantly reduced, which is a major plus when you consider we’re hooking up an 8 dollar nodeMCU to our 6 hundred dollar pool controller.
To simulate button presses on the spa side remote I’ll connect 4 optoisolators to 4 GPIO pins using 150 ohm resistors to limit the current going to the small LED in the optoisolator. I’ll connect the common positive voltage to the collector on each optoisolator, and the emitters to each of the four buttons. Now I can write a little bit of code that simulates these button presses when an MQTT message is received.
Basically the pubsubclient library allows you to subscribe to specific MQTT topics, watches for commands, and then executes specific functions based on the command. For this project I’m going to subscribe to the MQTT topic commands/pool. When it gets the command “SPA” it will press button 1 on the spa side remote, when it gets the command “Spa_Light” it will press button 2 to turn on the spa light, “Pool_Light” will press button 3 to turn on the pool light, and “Cleaner” will press button 4 to turn on the pool cleaner. I could stop the project right here and have a functional little switch, but I’ve got a whole NodeMCU in here, why not use a few more of the pins?
On the Pentair spa side remote there’s also an LED, this LED is off when the pool is in pool mode, flashing when the spa is heating, and solid on when the spa is fully heated. I can use this to figure out what mode the pool is currently in using arduino’s “pulseIn” function. Basically the “pulseIn” function is supposed to figure out how often a voltage source is turning on/off. If the pin goes from low to high before the timeout period is over (which I’ve set to 3 million milliseconds, or 3 seconds) meaning the LED is blinking that means the spa is heating, if the pin is in the high state meaning the LED is on that means the spa is on, and if there’s no pulse and the pin is low, that means the LED is off it and the pool is in pool mode.
Because we know the current state of the pool, we can also make our spa/pool button a little smarter. If I tell it to turn the pool on, but the pool is already on it shouldn’t press the button to change pool modes, and the same goes for pressing spa while the spa is on.
The last feature I wanted to have was a temperature sensor. My pool controller has a temperature sensor built into it, but decoding the serial data sent from the controller would be a headache, so I’m just going to piggyback off the built in temperature sensor to calculate my own temperature. The thermometer on the pool is a thermistor which means that it is a variable resistor that resists a different amount based on the temperature of the water. To read this thermistor using our NodeMCU we just need to connect the analog pin on the NodeMCU to the negative side of the thermistor and write a little bit of code to sort out the temperature. I had to change this code quite a bit because it was written for a 5 volt source and a 5 volt analog pin, but we’re using a 5 volt source and a 3.3v analog pin.
Now we need to install it in the pool controller. I’m using a buck converter to step down the 15V DC current on the com port to 5v so I can use the Vin pin on the nodeMCU. I’ve also hooked up this little breakout board to hook up the optoisolators and make it easier to manage. One last thing that you may or may not need to do based on your own wifi situation is extend the range of your NodeMCU. I made this before I had google wifi and before the Wemos D1 mini pro with external wifi antennae connection had been released. In order to add an external antennae I scraped away the base of the antennae trace and soldered on a jumper wire. I read online that this would never work because the length of the antennae is specific to the frequency of the wifi, but I did it anyway and it worked perfectly. If I was making another one of these I’d probably just use a D1 mini pro and avoid this extra headache, but it’s nice to know this is an option if need be.
Now that our device is hooked up we can add it to home assistant. I’ve got MQTT sensors for pool status, and temperature, and MQTT switches for pool mode, the pool light, the spa light, and pool cleaner. I’ll add these to my configuration.yaml file using the correct MQTT topics and restart home assistant. Once they’re added my pool is now fully integrated into my smart home, for under $20. Here are some of my favorite node-red automations for the pool. This one is a simple schedule for the pool cleaner, but it disables itself whenever we have company in town since we normally take the cleaner completely out of the pool during those times. And this one sends a message of “pool cleaner malfunctioning” to my phone if the temperature of the pool measured at the pump is greater than 95 degrees and spa mode is not active. This typically happens if someone knocks off the pool cleaner hose by accident and allows me to easily shut off the pool cleaner preventing damage to my pool pump.
Today we made a pool controller, but this general concept of emulating key presses can be used to add almost any dumb device into your smart home. If you’ve got a question about a dumb device you’d love to add to home assistant post it down in the comments and I’ll see if I can give you a good place to start. If you enjoyed this video please consider subscribing, and as always, thanks for watching the hookup.
Project Specific Parts:
Wemos D1 Mini PRO: https://amzn.to/2Jibme7
Buck Converters: https://amzn.to/2xNXGGy
Schematic JPG: https://github.com/thehookup/PoolMCU/blob/master/schematic.JPG
Schematic FZZ: https://github.com/thehookup/PoolMCU/blob/master/switches.fzz
Home Assistant YAML: https://github.com/thehookup/PoolMCU/blob/master/HA_pool.yaml
Music By: www.BenSound.com