Hot Tub / Pool Controller Web Interface

3,986

27

88

Posted

Introduction: Hot Tub / Pool Controller Web Interface

The ulimate webbased hottub / pool controller.

Step 1: Step 1: Intro

About 2 years ago i bought myself a raspberry pi and just playing around with it.. After a while i decided to make something useful instead of playing around with it.. So i decided to make a hottub controller with it. I'am running the controller over a year now and decided to share it with you :)

For all the functions see:

So in this tutorial we will see how to make a hottob / pool controller.

The controller is written in PHP with GPIO control

The following packages should be installed.
- Apache 2
- PHP5
- MySQL Database
- PhpMyAdmin
- GPIO Control

In case you don't want to install everything. You can download and install my Image / OS.
You can download my raspbian image HERE
--> Automatic Control does not work in the ready to use image. Please download files in the link below. Working on a new ready to use image.


Version 1.1 is available -> installed on raspbian jessie lite and updated a few bugs.
Download the image 1.1 HERE

Needed Hardware:
- Raspberry PI
- SD card ( 8 GB )
- 5V 4 Channel Relay Module ( or 8 channel is you wish )
- DS18B20 Temperature Sensors - Waterproof.
- Jumper Wires.

Step 2: STEP 2: Hardware Setup

Connect the DS18B20 sensors
Red Wire --> To 3.3v
Black Wire--> GND
Grew Wire (Data) --> GPIO pin 4
Also see Attachment

Contact the relai block as follow:
5v to 5v
GND to GND

See Attachment PDF for the right pin no. (or board overview, blue circles)

Pin 1 (relay) to WiringPi Pin 8
Pin 2 (relay) to WiringPi Pin 9
Pin 3 (relay) to WiringPi Pin 2
Pin 4 (relay) to WiringPi Pin 3

Be Aware ! The relay can switch a maximum of 10A

Step 3: Steps 3: Installing OS

First we will install a new fresh image of raspian.

I installed RASPBIAN JESSIE LITE, because we don't need all other stuff like desktop environment. But all other Raspian versions should be fine as well.

Flash your selected image with Win32DiskManager to the SD Card

Step 4: STEP 4: Install Packages

Download the program "putty" and "advanced port scanner" (both free software).

Scan with "advanced port scanner" and find your raspberry pi IP adress.

Go to Putty insert the IP of the raspberry and login with user "Pi" and password "raspberry".

First we need to expend filesysteem
Type:

sudo raspi-config 


Select expend file system en finish installation. The raspberry will restart now.

Wait a minute and connect again with putty to the raspberry and login.

Second we will update the PI
Type:

  sudo apt-get update 


Then:

 sudo apt-get upgrade 

Type "Y" to update (and upgrade the pi as necessary)

Install Apache2 with the following command:

sudo apt-get install apache2 


Install PHP5

sudo apt-get install php5 libapache2-mod-php5 -y 


Install MySQL

 sudo apt-get install mysql-server 

During installing mysql-server will ask for a password. This is to connect to the mysql server.. choose a password anything you like.. But don't forget this password. Write it down somewhere!! ( i choose "raspberry" )


Install PhpMyAdmin

sudo apt-get install phpmyadmin


Configure Apache to work with PhpMyAdmin

sudo nano /etc/apache2/apache2.conf 


Add the following line at the end of apache2.conf:
Include /etc/phpmyadmin/apache.conf
Control + X to save, type "Y" to overwrite.
Also See: http://raspipress.com/2012/09/tutorial-install-ph...


Install GPIO

sudo apt-get install git-core 
git clone git://git.drogon.net/wiringPi

cd wiringPi

./build

To get the DS18B20 sensors working use the follow commands:

Type:

 sudo nano /boot/config.txt


Add the following line

dtoverlay=w1-gpio

Control + X to save, type "Y" to overwrite.

sudo nano /etc/modules 

Add these 2 lines at the and:
w1-gpio
w1-therm

Control + X to save, type "Y" to overwrite.

run the gpio command to check the installation:

gpio -v 

gpio readall


----------
Yeah finally all packages installed :)

Step 5: Step 5: Setting Up Scripts...

Before we can upload the files to the raspberry we need to change a few settings

Add the pi user to the group
type: sudo gpasswd -a pi www-data
Change the group for the directory and allow the pi user to update the directory
type: sudo chown www-data:www-data /var/www
type: sudo chmod 775 /var/www

I've you have downloaded debian jessie you need to change the root directory of apache.
type: sudo nano /etc/apache2/sites-available/000-default.conf
Change /var/www/html to /var/www CTRL + X to save "Y" to overwrite.

To have access to control GPIO pins with a webpage.

Type: sudo visudo
Add this line to the end of the file:
www-data ALL=(ALL) NOPASSWD: ALL

Press CTRL + X to save and exit.

Download all the files from here


Download the program Filezilla Client (or other FTP program )
Connect to you're raspberry pi with following details:
SFTP://IpOfYourPi ( port 22 )
User: pi
Password: raspberry

Upload the files to /var/www ( - Just type /var/www in the right screen. )

In case you have another mysql password then "raspberry" you need to change to php configuration of the controller:
Edit the config.php file.
Change mysql_pass to the right password you have set during mysql-server installation.

Next step is to import the SQL file in the database.

Go to http://IP-Raspberry/phpmyadmin
Login with root and you're password (raspberry default)
Add a database with the name "controller"

Click on controller in the left area of the page and then click Import.
Select controller.sql from all controller files and upload by pressing start.

Setting up Cronjobs
type: crontab -e
Add this text to the end of the file.

* * * * * wget -q -O - "http://127.0.0.1/cron_jobs/cron_min.php?auth=Gdw34zXrFHYDe" 1,11,21,31,41,51 * * * * wget -q -O - "http://127.0.0.1/cron_jobs/cron_10minutes.php?auth=Gdw34zXrFHYDe"

CTRL + X to save. Done !

Step 6: Step 6: Controller Page

Go to: http://raspberryIP

Welcome to the login screen :)..

Login with username: admin password: 123456

There is also a tablet page. special writtin for my tablet :).
See http://raspberryIP/tablet

4 People Made This Project!

Recommendations

  • Science of Cooking

    Science of Cooking
  • Pocket-Sized Contest

    Pocket-Sized Contest
  • Spotless Contest

    Spotless Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

5 Questions

On the install PHP5 step I am getting a message that says the package is not available but is referred to by another package. What might that be

A few more points of interest....

1. In the explanation above it states that mysql will prompt you to set a password during install. That's not true anymore. After the install of mysql is done, use this command "sudo mysql_secure_installation" Now just agree to all the questions and set your password to "raspberry" or whatever.

2. You wont have permission to create the directories in FileZilla if you type "type: sudo chmod 775 /var/www" Instead use "sudo chmod -R 777 /var/www"

Php5 is no longer compatible with Raspian... use Php 7 instead

"apt-get install php7.0 libapache2-mod-php7.0"

What version of Raspbian did you use? The tutorial is based on Raspbian Wheezy / Jessie.

I am using NOOBs

I am trying to run off the image you have to download now(ver 1.1). It is asking for a domoticz login. What should that be? I tried to use admin and Pi as the logins but when I try to type in the password nothing can be writen.

I'm having the same problem

Username: admin
Password: 123456

Please let me know if this works.

That did not work. I can input the username but the password doesn't display when I try to type that in.

If my pump requires more power than 10A, how does one go about acquiring a higher amperage output ? currently heater is 4kw, requires 17a

39 Comments

@rickiewickie

Ok, got your code all working with MQTT! After considerable head scratching, this is what I did:

Configured a GPIO "listener" to fire off the appropriate MQTT topic whenever one of the pins receives changed. The end result is I didn't even have to alter your code at all to get the pump/heater/lights etc working!

The only thing I had to change in your code was the location of the sensor output files. Since I disabled the 1-wire stuff and i'm pulling temp info via mqtt into a different logging file.

QUESTION:

I'm noticing odd behavior. My pump switch seems to be kicking ON automatically even when I've pressed OFF in manual control main screen. Any idea why it would be doing this? I can view the WiringPi readall, and see that it's getting changed.. Also another clue that it is coming from the Pi is the frequency.. Always less than a minute, but sometimes 50sec, sometimes 10 seconds after I turn it off. Is there a loop in the cron or code somewhere that I need to look at?

Thanks again!

@cory
The "odd behavior" has most likely something to do with the settings, like automatic pump control/frost protection.
To test this, set "Cleaning Mode" to "On" , this disables all the automatic functionality. So when the when this behavior is is gone then you need to know it is something in the settings (Tab: Configuration Sub: Controller)

The interval of switching has something to do with the cronjob that will run every minute and check all the settings / time schedules etc.

Hope this answer is sufficient enough :)

Hey I've got another question. I'd like to see what I can do with the $set_temp_dev function. I can't seem to find it anywhere?

Oh.. and here's what I did to your nice clean work :)

login.jpgmain.jpg

Rickiewickie,

I emailed you directly from the About page with some bugs and suggestions I've found. I *think* I've fixed up the automatic control portion so that it behaves better. If you didn't get the email, let me know here and we'll figure out how to chat about it.. If you'd like :)

thanks, i'll check it out.. though I messed with ALOT on this pi. It's pretty messy right now. I wouldn't be surprised if it was my fault.

If you want the changes I made for a later date, let me know and I can go over it with you. You could also integrate it into your other home automation or for additional MQTT listening devices for single interface control when using your tub. You can add as many MQTT topics as you have unused pins.

further info: 'Time Schedule' has been removed. Automatic control is 'Off'.

I also stopped the MQTT forwarder script, the behavior still is the same. The website automatically turns on the pump on what seems like a 1min loop.

Fixed it.. something on this Pi was flipping pin 9. Switched it to something else and it's holding where I set the controller.

Hi Rick,

I just used this tutorial and setup to build my own controller instead of buying a new circuit board from the manufacturer. Thanks for the great setup and image file.

I am having some problems while using the automatic heater control. For some reason, after my temperature gets within the requirement, the heater shuts off (as it should) but the pump remains on. Can you think of anything that would cause this?

Well I might have spoken too soon. I logged into the php myadmin page and switched the pump controller setting to on. Seems to be working now.

Hi Adam,
Go to hear that you got it working!
Enjoy the controller :)