{"id":362,"date":"2018-06-06T13:00:18","date_gmt":"2018-06-06T17:00:18","guid":{"rendered":"http:\/\/www.thesmarthomehookup.com\/test_install\/?p=362"},"modified":"2023-04-24T15:47:50","modified_gmt":"2023-04-24T19:47:50","slug":"connect-your-pool-to-your-smart-home-for-20-with-arduino","status":"publish","type":"post","link":"http:\/\/www.thesmarthomehookup.com\/test_install\/connect-your-pool-to-your-smart-home-for-20-with-arduino\/","title":{"rendered":"Connect your pool to your smart home for $20 with Arduino!"},"content":{"rendered":"<p><iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/QcaJlpVOJ8U\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen=\"\"><\/iframe><\/p>\n<p><strong>PoolMCU \u2013 tripping switches with octocouplers<\/strong><\/p>\n<p>Today on the hookup we\u2019re going to learn how to connect an automatic pool controller to your smart home using a NodeMCU.<\/p>\n<p>This big box is called a pool controller and it\u2019s basically the brain of my pool.&nbsp; You can buy all kinds of addons for these things to be able to control them remotely.&nbsp; 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.&nbsp; 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.&nbsp; Another option was to spend $400 to buy the board that lets me access my pool controller via the Pentair Screenlogic app, but that\u2019s yet another app on my phone and it still can\u2019t interface with the rest of my smart home.<\/p>\n<p>As is often the case, the final and best option here was for me to build a solution myself.<\/p>\n<p>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.&nbsp; Links are down in the description for all of the parts you\u2019ll need for this project.<\/p>\n<p>On my pool controller which is a Pentair easy touch 4 there is an option to connect a set of 4 buttons called a \u201cspa side remote\u201d 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.&nbsp; Don\u2019t 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.<\/p>\n<p>I don\u2019t actually want a spa side remote, what I want is to emulate a spa side remote from my smart home devices.&nbsp; 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.&nbsp; What we need to do is emulate a button press and for this particular case I\u2019m going to use something called a optioisolator.<\/p>\n<p>An optioisolator is sort of like a switch.&nbsp; It\u2019s got an input leg and an output leg with a photoresistor in between.&nbsp; 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.&nbsp; 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.<\/p>\n<p>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\u2019re hooking up an 8 dollar nodeMCU to our 6 hundred dollar pool controller.<\/p>\n<p>To simulate button presses on the spa side remote I\u2019ll connect 4 optoisolators to 4 GPIO pins using 150 ohm resistors to limit the current going to the small LED in the optoisolator.&nbsp; I\u2019ll connect the common positive voltage to the collector on each optoisolator, and the emitters to each of the four buttons.&nbsp; Now I can write a little bit of code that simulates these button presses when an MQTT message is received.<\/p>\n<p>Basically the pubsubclient library allows you to subscribe to specific MQTT topics, watches for commands, and then executes specific functions based on the command.&nbsp; For this project I\u2019m going to subscribe to the MQTT topic commands\/pool.&nbsp; When it gets the command \u201cSPA\u201d it will press button 1 on the spa side remote, when it gets the command \u201cSpa_Light\u201d it will press button 2 to turn on the spa light, \u201cPool_Light\u201d will press button 3 to turn on the pool light, and \u201cCleaner\u201d will press button 4 to turn on the pool cleaner.&nbsp;&nbsp; I could stop the project right here and have a functional little switch, but I\u2019ve got a whole NodeMCU in here, why not use a few more of the pins?<\/p>\n<p>On the Pentair spa side remote there\u2019s 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.&nbsp; I can use this to figure out what mode the pool is currently in using arduino\u2019s \u201cpulseIn\u201d function.&nbsp; Basically the \u201cpulseIn\u201d function is supposed to figure out how often a voltage source is turning on\/off.&nbsp; If the pin goes from low to high before the timeout period is over (which I\u2019ve 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\u2019s no pulse and the pin is low, that means the LED is off it and the pool is in pool mode.<\/p>\n<p>Because we know the current state of the pool, we can also make our spa\/pool button a little smarter.&nbsp; If I tell it to turn the pool on, but the pool is already on it shouldn\u2019t press the button to change pool modes, and the same goes for pressing spa while the spa is on.<\/p>\n<p>The last feature I wanted to have was a temperature sensor.&nbsp; 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\u2019m just going to piggyback off the built in temperature sensor to calculate my own temperature.&nbsp; 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.&nbsp; 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.&nbsp; 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\u2019re using a 5 volt source and a 3.3v analog pin.<\/p>\n<p>Now we need to install it in the pool controller.&nbsp; I\u2019m 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.&nbsp;&nbsp; I\u2019ve also hooked up this little breakout board to hook up the optoisolators and make it easier to manage.&nbsp; 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.&nbsp; I made this before I had google wifi and before the Wemos D1 mini pro with external wifi antennae connection had been released.&nbsp; In order to add an external antennae I scraped away the base of the antennae trace and soldered on a jumper wire.&nbsp; 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.&nbsp; If I was making another one of these I\u2019d probably just use a D1 mini pro and avoid this extra headache, but it\u2019s nice to know this is an option if need be.<\/p>\n<p>Now that our device is hooked up we can add it to home assistant.&nbsp; I\u2019ve got MQTT sensors for pool status, and temperature, and MQTT switches for pool mode, the pool light, the spa light, and pool cleaner.&nbsp; I\u2019ll add these to my configuration.yaml file using the correct MQTT topics and restart home assistant.&nbsp; Once they\u2019re added my pool is now fully integrated into my smart home, for under $20.&nbsp; Here are some of my favorite node-red automations for the pool.&nbsp; 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.&nbsp; And this one sends a message of \u201cpool cleaner malfunctioning\u201d to my phone if the temperature of the pool measured at the pump is greater than 95 degrees and spa mode is not active.&nbsp; 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.<\/p>\n<p>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\u2019ve got a question about a dumb device you\u2019d love to add to home assistant post it down in the comments and I\u2019ll see if I can give you a good place to start.&nbsp; If you enjoyed this video please consider subscribing, and as always, thanks for watching the hookup.<\/p>\n<h3>Links<\/h3>\n<p>Project Specific Parts:<br \/>\nNodeMCU: <a href=\"https:\/\/amzn.to\/2HmqcyH\">https:\/\/amzn.to\/2HmqcyH<\/a><br \/>\nor<br \/>\nWemos D1 Mini PRO: <a href=\"https:\/\/amzn.to\/2Jibme7\">https:\/\/amzn.to\/2Jibme7<\/a><br \/>\nOptoisolators: <a href=\"https:\/\/amzn.to\/2sJ8Iab\">https:\/\/amzn.to\/2sJ8Iab<\/a><br \/>\nResistors: <a href=\"https:\/\/amzn.to\/2J67k8c\">https:\/\/amzn.to\/2J67k8c<\/a><br \/>\nBuck Converters: <a href=\"https:\/\/amzn.to\/2xNXGGy\">https:\/\/amzn.to\/2xNXGGy<\/a><\/p>\n<p>Essentials:<br \/>\nPrototype Boards: <a href=\"https:\/\/amzn.to\/2Jt862T\">https:\/\/amzn.to\/2Jt862T<\/a><br \/>\nHeader Pins: <a href=\"https:\/\/amzn.to\/2M1iayF\">https:\/\/amzn.to\/2M1iayF<\/a><br \/>\nHook Up Wire: <a href=\"https:\/\/amzn.to\/2JsDtuF\">https:\/\/amzn.to\/2JsDtuF<\/a><\/p>\n<p>Tools:<br \/>\nSoldering Iron: <a href=\"https:\/\/amzn.to\/2JuTQa6\">https:\/\/amzn.to\/2JuTQa6<\/a><br \/>\nWire Cutters: <a href=\"https:\/\/amzn.to\/2Ls4Imr\">https:\/\/amzn.to\/2Ls4Imr<\/a><\/p>\n<p>Schematic JPG: <a href=\"https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/schematic.JPG\">https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/schematic.JPG<\/a><br \/>\nSchematic FZZ: <a href=\"https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/switches.fzz\">https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/switches.fzz<\/a><\/p>\n<p>Arduino Code: <a href=\"https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/PoolMCU_CONFIGURE.ino\">https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/PoolMCU_CONFIGURE.ino<\/a><\/p>\n<p>Home Assistant YAML: <a href=\"https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/HA_pool.yaml\">https:\/\/github.com\/thehookup\/PoolMCU\/blob\/master\/HA_pool.yaml<\/a><\/p>\n<p>Music By: www.BenSound.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PoolMCU \u2013 tripping switches with octocouplers Today on the hookup we\u2019re 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\u2019s basically the brain of my pool.&nbsp; You can buy all kinds of addons for these things to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2609,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-362","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","category-tutorials"],"acf":[],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/comments?post=362"}],"version-history":[{"count":3,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":2364,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/362\/revisions\/2364"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media\/2609"}],"wp:attachment":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media?parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/categories?post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/tags?post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}