Web Enabled Pool Control - Raspberry Pi





Introduction: Web Enabled Pool Control - Raspberry Pi

Last year I had a pool built. It was exciting when the pool builder showed me that the pool industry had moved into the technology age and now offered application control over the internet. Being a computer junkie I jumped for joy. Then the quote... $10,000 for pool automation. Let me say that again... $10,000 for pool automation. Of course that was out of the budget... but not a lost desire.

I thought, let me purchase the components and I'll do the work. Researched and looking into the major builders hardware and it alone would have cost me near $5,000. Without install.

So I made it my mission to create my custom solution.

This is a brief overview of my project. To say I'm proud is an understatement! This project has taken months in planning and learning the software side and the labor to build has been at least 60 hours with an overall hardware cost around $1,000.

It will continue to mature. Better interface. More functionality. But for now it is live.

A word of caution, many of these components use 120V and 240V AC and they are dangerous if you don't have the training. That said... here we go.

Step 1: Drafting the Hardware

Step one, plan the project. Identify inputs (what you will monitor - i.e. water temp) and outputs (pumps, valves, LEDs, etc). Create a Pin-Out drawing for reference. (A lesson learned here was the pin-outs changed to enable cleaning wiring in a later phase). Measure the components. Draft them out to determine the size of the box needed.

A quick drawing is worth its weight in gold (use thin paper :-))

Parts List (links are examples):

1) Raspberry Pi: https://www.amazon.com/CanaKit-Raspberry-Complete-...

2) Raspberry Pi Relay Board: https://www.amazon.com/Elegoo-Channel-Optocoupler-...

3) 24V AC Transformer: https://www.amazon.com/Furnace-Control-Transformer...

4) 24V AC Relay: https://www.amazon.com/White-Rodgers-90-340-Replac...

5) Power Strip (note on this: I wanted to use the USB part of this strip to save my power supply, but it caused the Pi to reboot. Assuming it is under powered): https://www.amazon.com/gp/product/B015MF60O2/ref=o...

6) Project Box: https://www.amazon.com/gp/product/B005T57DF6/ref=o...

7) Terminals for easier connections: https://www.amazon.com/gp/product/B00G9IEMJM/ref=o...

8) Valve Actuator (non-name brand - works great. Can set it at any degree of rotation with cam settings: https://www.amazon.com/gp/product/B002ZPJVV2/ref=o...

9) LevelSmart water level (this cost was not in the original writeup - but is working very well!): https://konalabs.com/levelsmart/

10) Pool Components: Installed by pool contractors. All Pentair name brand except valves - they are Jandy, and the waterfalls, they are Brillian Wonders. For details on each component click on the picture and zoom in. The model is on the component.

11) Waterfall controllers - do not purchase the ones in this photo. You need the Brilliant Wonders Smart Sync. Found it for about $139 at American Best Pool Supply...http://www.americanbestpoolsupply.com/smart-sync-l... This allows the colors to sync with the LED colors from Pentair

12) If you need to integrate to the SPA heater I can help with this brand & model. Others would require additional investigation. I plan on improving this design when I get back to working the details of this project.

Step 2: Setting Up the Raspberry Pi

Setting up the webpage was new and a bit cumbersome, but this page followed step-by-step, will lay the ground work no matter how sizable your project.


Don't miss the small line about making it "mobile enabled". It makes the phone operation look more professional.

Right now, I'm going to stay high level, but will come back later to add more detail. As a general rule, enter the name of each step below followed by raspberry pi into google and with some time you will find what you need. The one that took more time to figure out was 2c, so I've added a link to "patch" webiopi to a newer version.

Sub steps:

2a: Setup Static IP

2b: Setup Remote Desktop

2c: Setup Webiopi - there is a patch required - details here: https://www.raspberrypi.org/forums/viewtopic.php?f...

2d: Setup Apache Server - ensure it loads at startup.

2e: Setup WinSCP to transfer files to the Pi from your PC

2f: Setup No-IP DNS (or other free service) - Point web request to your webpage

2g: Setup port forwarding on your router

After you have this working and you can pull up a working page on your web-browser, your creative work is still to go. Referencing the pin-out you created in step two, set your HTML and Python script names to match the pins. Then, with some planning and trial and error, setup your macros to do the work for you.

Step 3: Wiring the Raspberry Pi Relays

Installing Relay boards. Refer to your relay pinouts in step 1. Label the relays... it helps assembly greatly when you have dozens and dozens of wires in a box.

As a design criteria, I chose to have the relay boards switch 24V AC. The small relays (blue boxes in the pictures) do say they are rated for 120V and 240V, however running "main pump current" through relays this small would likely lead to excessive heat and early failure. I used the low level relays to apply 24V to large relays to switch 120V/240V.

Another important consideration. You should design your system to have everything "off" when the power is not applied to the Pi. What this means is should the Pi reboot, purposefully or power outage, you want the relays to disconnect power to all components during boot. Otherwise, you will have random components turning on when the Pi is down... Maybe not a big deal in some cases, but not desirable in any case. In designing with this in mind, all of the HTML and Python code "seems" backwards. High settings = "off", and Low settings = "On".

Watch the video attached and you can see the relays turn on and off (the red light below each blue relay) when I press the button on my smartphone.

Step 4: Designing and Building the System

As I mentioned in the introduction, working with 120V and 240V is no joke. Don't do it unless you take time to educate yourself!

Determine System Voltages: In this case, the pool industry sets that precedence for our project. It is a mix of output voltages.

1) 120v/240v - Pumps, Chlorinator, Heater, Pool Lighting Transformers

2) 24vAC - Pool valve drive motors, Pool Heater Interface Voltage, Pool LEDs

3) 12vDC - Pool waterfall LEDs.

I had a question for a wiring schematic which I wanted to reply too. Although it is possible to put one together the time investment is just too great. The best wording descriptions I can add are as follows:

1) Each component comes with their own wiring diagram. Each component has an input and an output. The inputs and outputs will be one of the 3 voltages above. Each component requires a particular input to create the correct output.

a. Raspberry Pi - 120v AC- power supply

b. Raspberry Pi - 5v DC- fed from Raspberry Pi

c. 24v Transformer - 120v AC to 240v AC input (refer to schematic provided with the transformer for wire color) - 24v AC Output

d. Control Relays - 24v AC Input to relay connectors - any output voltage to the relay connectors

e. Pool Pump (240v AC) - Chlorinator (240v AC) - Heater (240v or 120v AC) - LED Transformer (120v AC) - Waterfall Transformer (120v AC) - SPA Blower (240v or 120v AC - based on model). Switched with the control relays in step D.

In construction I used plexiglass from Lowes. Lots of sawing, drilling, measuring... you get the jest. I had to make two boxes. One for my pump room. One for my greenhouse where all of the lighting and the spa blower is located. I chose a cabinet with door to prevent prying hands from contacting high voltage.

Take your time and remember one lesson, before turning on the main power ALWAYS ohm between the source and ground to ensure there is NO DIRECT SHORT. Miss this step and you may have unexpected fireworks and burned components.

Step 5: Working With Macros

Referencing the top link in Step 2, creating macros with Python and calling them with HTML does multiple clicks with one button. This creates a set of instructions that will set each pin to the desired state. See the attached "pool setup" macro that is in the "python script" file.

Step 6: Wrapping Up... Watch the Videos

This is a fully functional replacement for some very high end consumer products. It was admittedly a massive undertaking, but in the end, fun and rewarding.

By the way - as you may notice in the videos, the time to pull up the webpage is very slow. The cause has been identified as a defective wireless router. It has been replaced and my controls are fast and have been up for over 2 weeks straight without a single minute of downtime!

When I show it to people, it blows them away! I hope it does you as well.

Good luck with your pool controls!



    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    31 Discussions

    This is very impressive. Hopefully you're still around to answer questions! Have you made any recent updates? I am looking to undertake a similar project (using a particle proton) and I have the same heater. Could you elaborate on how you control the Pentair heater? Also, I see you used a separate 24v transformer for each actuator, etc. The Hayward controller I currently have seems to employ only one 24v transformer. What led you to that decision? Finally, if you have some clear pics of the innards, I would be very interested to see how you wired everything up.

    Thank you!

    12 replies

    1st photo is cabinet 1 total. Picture 2 is the high voltage motor drives. The distribution block (black with screws) on the top left (and a closeup in pic 3) is where the 240v comes in. You can see I jumper that across to other circuits. Look close and you see small 24v wires to the relay coil (orange on the left relay) which switches the red and black of the 240v back to the pool pump. Each of the 24v wires is switched from the pi to the blue relays, to the high voltage relays. You can see the commons and neutrals are all wire nutted together - I switch the hot leg to all outputs through the relays. In the middle of pic 2 are the two 24v transformers (120v to 24v) that I mention earlier. One power all of this box. The other a 2nd box - pics to come.


    Thank you! This is great and very helpful. Appreciate the detailed descriptions as well. I am getting close to having a working prototype for much of my functionality and want to test it out before actually switching the pool equipment over from my current controller, but these pics definitely help my confidence with the high voltage stuff.

    One thing I would LOVE to do is hack the "off" switch on the valve actuators. If I could run them for a set amount of time and then freeze them in a both open position, that would allow me the opportunity to do some great things with my pool.

    Since you seem to be pretty astute with this stuff, do you think that is even possible? I would think so, but I haven't messed around with it yet. I have a few semi-working spares that I may mess around with, but wanted to get your thoughts as well.

    Thanks again! I'll be sure to share what I have when it's a bit more ready for prime time.

    Yes it is certainly possible. First thought though I'm not 100% sure it would work - just like you said - use two relays to apply the 24v ac to each actuator wire. When you turn both off the motor will have no drive voltage and stop. The issue that would need to be tested is if you applied 24v to both lines by leaving both relays on - what will the motor do? It may drive all the way open and all the way closed again and again... not sure. It would be an easy test - put 24v to both wires and see what happens. Probably not enough voltage to really hurt anything for a short time. Either way, you would need an interface that turns one relay off when the other is turned on to make it work...

    After looking at the innards of an actuator, it seems like you could use two relays and when both were off, it would stop at that point? Maybe I'm missing something.

    The 2nd box is a bit simpler to see what is going on. The 1st pic is where all of the relay wires are attached to the wires running under the ground. Pic 2 is where the wires come into the greenhouse and are connected to the relay box. The 3rd pic are all of the outgoing wires. 3 LEDs, 2 waterfall LEDs, a 120v wire for general lighting, 120v for the spa blower. The 4th pic is of the components. 7 relays - labeled - the silver and white boxes are the waterfall LED controllers and the cream box is the transformer for the pool LEDs. The middle device is my wireless pool fill device. All of the components are attached to plexiglass and the wires are running behind the glass. Hope all of this helps. Let me know when you complete your program - would love to copy some of it. Good luck!


    These are a little harder to see. Pic 1 is a detail pic of the relays. The bottom are pinouts that connect to the pi. The top are normally open or closed relays. The relay marked WFV is a clear example of wiring a valve motor (last pic). You can see the middle leg is dark blue. It is tied to 24v. When the relay is off it connects the 24v to the white wires drives the valve open. When energized it connects the 24v to the red wire, driving it closed. Pic 2 (barely) shows the pi in the background - a ribbon cable for easy disconnect from the pi running to the relay wires. Pic 3 is a 120v power strip fed from one leg of the 240v feed wire that powers the pi and the screen. Pic 4 is a pic of the pi from above. You see an extension cable from the memory card slot so I can change the memory card easy (worth the cost!!!). And finally pic 5 is a wifi antenna because the signal was too weak inside the cabinet.


    1st Pic - Main Power - Orange wire is 240v. The white and yellow wires are outputs. The 2 white wires are 240v back to the pool and spa pump. The yellow is 120v to a small solar heater pump.


    The question about the two 24v transformers, this may be over engineered but the reason there is two was I have have 11 relays and 6 automated valve motors and half of them are closer to the pool - about 40 feet from the main controller - so I use one transformer for the main room - 4 relays, 6 valves (admitted they don't energize all at the same time...), and the second transformer runs 7 relays 40 ft away that could all be energized at the same time through small thermostat wire - so I was concerned that there would be a voltage drop. So... I figured better safe than sorry... If you post your email address I'll send a lot of pics.

    Thank you!

    I'm managing the temperature measurement already, so I wan to be able to control that via my DIY controller. Walking to the heater would be a bit difficult for me given location. I'll work more on that as I get closer.

    Currently, I'm looking to integrate mine with SmartThings, but I may look into OpenHAB as well and see if that's more feasible (I already have ST hub and have some of the integrations implemented).

    Is there a semi-private way I can send you my email address lol, as I would love to see detailed photos?

    I would love to see what you do with SmartThings when you are complete. Before we go though the email exchange process I'll try to post them here...

    Give me a couple of days.

    Thank you... yes, still around. I went through two options with the heater. My first was to use the 24v inputs detailed on page 31 of the user manual. You move Jumper 3 and hook up 24v inputs for the pool and spa separately (The diagram calls the input "Spa Line" & "Pool Line"). This had the benefit of being able to select 2 temps with two relays but it had a drawback of the panel becomes inactive so if you want to change the temp you have to move the jumper position - set the temps - move the jumper back - cycle the power. This year I converted over to the more conventional setup. I installed a 24v relay in line with the "Firemans Switch" - which took me a while to figure out - but very simple after you know where to wire. On the same page, bottom right of the wiring diagram you see a text box that starts with "Replace Jumper with" - it is a yellow jumper. You wire the relay here. When you energize the relay it energizes the power board so you can change the temp - but you only have an on and off so if you want to change the temp to have to walk to the heater. My plan install a temp sensor and upgrade my software to measure the temp and turn the heater on and off. More to come on that... I am strongly considering Openhab - if you develop something and are willing to share that would be great!

    One other REALLY important point I forgot to add - Using the first option puts 24v directly to the control board which is low voltage. I had a board failure and I was concerned that it may have contributed. The second option deals with the 120v (or 240v) input.

    first off, this is amazing, you have done a fantastic job. Ive been researching pool automation and youre right, the equipment cost alone is well over 2500 bucks and it seems with every feature you want you have to sacrifice 2 other features. its like they nickel and dime you to get everything.


    are you able to set a schedule for the pump? my pump runs 8 hours a day during the winter and as much as 12 hours a day during the summer.

    the chlorinator, runs essentially as long as the pool pump is running but only generates chlorine based on the levels it senses. were you able to automate that as well and how are you sensing the levels?

    the valve positions, i assume there is some way to tell it what degree to turn the valves? i only have 2 valves on my pool. one for return and one for supply. they are 3 position valves so i can control more return in spa or more return in pool, or a mix, and same for the supply. this is how my waterfall feature works.

    heaters, i assume youre sensing water temperature and the heater being preset, youre just using the relays to turn it on or off to reach desired temperature. what about if youre using both solar and say a gas heater. solar valve i imagine would turn on and off on to actuate temperature and if you wanted a quick boost you could turn on the gas.

    i want the hot key functions to take over the schedule. so typical schedule mixes the spa and pool for x hours per day, but i come home from work and want to sit in the spa for a bit, so i hit a "hot key" to switch the valves around so only the spa is circulating, measure temperature, then kick heater on to bring water to desired temp.

    i feel like the hardware and wiring part is simple, its the coding that i have no idea about. aside from making a few macros in excel and some basic C++ i am no programmer. but i can do HTML, just no idea about web apps. also setting up router, web server, ip addresses, etc, very easy.

    at any rate im glad i found this, i think i now have a project i can play with (as if i needed more projects) Good job!

    2 replies

    Thank you... you are definitely asking the next set of questions. Unfortunately I don't have them all solved yet.

    Right now my pump is on a mechanical timer. I have looked into the timer function built into Linux on the Pi, but I have not tried to get it working (just as you say I have TOO many projects).

    Initially I designed my system to work my chlorinator with its own button, but thought better of it. I have it wired to the main pool pump. As soon as the pump comes on the chlorinator turns on. I don't think mine senses the level - mine has a % on button that I keep on 80%.

    I have 3 valves now as well. All 3 are 3 way valves. I am in the process of installing 3 more for better controls between the spa, fountains, pool, and now my solar heaters that I just got finished last weekend. The valve motors have a cam where you can set two different stop positions - CW and CCW. Unfortunately, using just one relay, you can only stop on one of those two positions.

    On the heater - I am not sensing the temp yet - I use 24v inputs on the heater and the heater measures the temp and turns on and off. The problem with that is I can't adjust the temp from my phone. I have purchased the sensor and the fitting to pipe it in is on the way as well (if it works). I see on-line tutorials ((http://webiopi.trouch.com/Tutorial_Devices.html) on how to setup the monitoring of the temp, but not how to turn it on and off with the temp - so I have some work to do there.

    My new solar system also does not sense the temp... I installed it with its own dedicated pump and set it up so the valve opens when the pump turns on to move the warm water to the pool. My plan is to put it on a timer as well. If I turn the system on, I want it to circulate into the pool every 30 min when the sun is up. I'll be working that in the coming weeks.

    Bottom line, is like you I well versed in visual basic - so the coding logic is not difficult - the coding syntax is painful. You can see I have enough python and html to get it working, but not enough to get the timers integrated - yet... I did have a gentleman (https://www.instructables.com/id/Hottub-Pool-Contr... share is controller program files, that are much more sophisticated than mine, which I plan to utilize.

    But I am also exploring other options that are just "prettier" - such as OpenHab - as one person suggested. (http://www.makeuseof.com/tag/getting-started-openh...

    I'm more that willing to send you my files - in exchange for you sharing if you are able to integrate the timer and temp controls.

    Might I suggest http://home-assistant.io over Openhab I looked at both projects and went with Home Assistant much better and the development is awesome every 2 weeks something new is out! Can you access the PIs gpio pins direct from the browser i.e. http://home-assistant.io ? If so Integrating it into Home Assistant would be a snap! and all your programing of the on off times would be super easy via the direct Home Assistant Automations or AppDaemon. I like your project built something similar but more crude with an Arduino and Xbee but it runs 1 pump with 4 speeds, 3 auxiliary pumps, valves for solar, spill over, water falls, heaters and valves to isolate spa and pool (filter pool while spa is running on a single system), pump chlorinator, and Air temp, pool temp, spa temp, solar temp, and other things.

    Nice Project!

    what display did you use?

    Pretty cool. You could have used a arduino and Smartthings to simplify your life. No only that but then you could have used schedules & home automation to turn things on/off based on if your home or not.