Raspberry-Pi Home Heating Controller

67,202

187

96

Introduction: Raspberry-Pi Home Heating Controller

Have you ever wanted to remotely control your home heating and hot water from anywhere, but did not want to pay over £200 for a commercial system ?

Using off-the-shelf hardware and shareware code, you can build your own DIY controller for less than £50.

** Warning this project involves working with mains voltage - please seek help if you are unsure **

All code for this project is available here : https://github.com/JeffreyPowell/pi-config

Step 1: System Design

The system consists of a controller unit ( pi-heating-hub ) which sits next to your central heating and water boiler, and one or more temperature sensors ( pi-heating-sensor-01 , 02 , ... ) which are positioned around your home.

The pi-heating-hub consists of a raspberry pi zero connected to some relays - you will need to refer to your heating system manual to see if it is possible to splice in to your central heating and/or hot water circuits. I was able you connect to both circuits, but you may only be able to connect to the central heating circuit, in which case you will only need one relay connected to the pi zero.

The pi-heating-sensor consists of a pi zero connected to some 1-wire temperature sensors. You can connect as many pi-heating-sensor as required, one for each room you want to monitor ( lounge, bedroom1, conservatory, ... ) and each pi zero can have as many 1-wire temperature sensors connected as you require ( you could have a pi zero in your lounge with three 1-wire temperature sensors measuring : air temperature, one measuring the temperature of the radiator and one hanging out of the window measuring the outside temperature ).

The pi-heating-hub and pi-heating-sensors communicate via your home wifi.

Step 2: What You Will Need

The pi-heating-hub :

  • Raspberry Pi Zero + SD card
  • Power supply
  • USB wifi dongle + micro usb adaptor
  • 1 or 2 channel relay module ( 250 Vac - 10 A )
  • 10 pin GPIO connector ( 2 x 5 pin )

For each pi-heating-sensor :

  • Raspberry Pi Zero + SD card
  • Power supply
  • USB wifi dongle + micro usb adaptor
  • a 4.7kΩ resistor
  • 1 or more 1-Wire Digital Thermometers ( DS18B20 )
  • 10 pin GPIO connector ( 2 x 5 pin )

Step 3: Base Setup of Each Pi Zero

Common Hardware configuration :

First solder the GPIO connectors to the GPIO port pins 1 to 10 on all pi zeros you are going to use.

the pi-heating-hub only uses pins 1, 6, 8 and/or 10, and the pi-heating-sensor only uses pins 1, 6 and 7, the other pins are used just to add physical strength.

Common Software configuration :

We need to configure all the pi zero systems with some common settings, install some handy packages and configure static IPs and hostnames.

First install a clean copy of Raspian Jessie onto the SD card and connect power to the Pi.
( you will need a USB hub to connect a keyboard, mouse and wifi dongle to your Pi zero for the following steps ) Once booted, connect to your Wifi network and open a terminal window.
check for updates,

> sudo apt-get update

Next, from the desktop open the config app [ Pi Menu > Preferences > Raspberry Pi Configuration ]

  • on the System tab, expand the filesystem, change the default pi account password, boot to cli, no auto login
  • on the Interfaces tab, just enable SSH and 1-wire
  • on the Performance tab, reduce GPU memory to 16 - since we will only be using the cli.
  • and on the Localisation tab, set all options to the correct location.

Click Ok to save, but do not reboot yet.

Next we need to give each pi zero a static IP address and new hostname.

Check your network hub DHCP settings. I was able to reserve the following static IP addresses :

  • 192.168.0.100 : pi-heating-hub ( Pi with relays, connected to water heater and/or heating pump )
  • 192.168.0.101 : pi-heating-remote-01 ( Pi with 1-wire thermometers in lounge )
  • 192.168.0.102 : pi-heating-remote-02 ( Pi with 1-wire thermometers in bedroom1 )
  • 192.168.0.103 : pi-heating-remote-03 ( Pi with 1-wire thermometers in conservatory )

To simplify the set-up process I've written a script to do this for us, run this script on each pi zero to configure the static IPs, you should leave the gateway and DNS settings as default.

> curl "https://raw.githubusercontent.com/JeffreyPowell/pi-config/master/base-install.sh" > base-install.sh && sudo bash base-install.sh

Once this is complete you should shutdown,

> sudo shutdown -h now

and disconnect your keyboard, mouse and monitor before powering on again, and you should now be able to connect over SSH using the new static IP and new password.

> ssh pi@192.168.0.101

Step 4: Build and Configure the Controller Hub

Hardware :

Connect the relay to the pi zero using the following pins :

Pin 2 - GPIO 5.0V
Pin 6 - GPIO GND
Pin 8 - GPIO 14 ( connected to hot water pump relay - if available )
Pin 10 - GPIO 15 ( connected to Heating relay )

Wire the 2 channel relay as shown in the diagram. ( if you just have a 1 channel relay you only need to wire pin 10 )

Now you'll need to refer to your heating system manual / wiring diagram.

My system currently uses a 15min / 24hr electro mechanical clock and a remote wired thermostat.

The heating is controlled by the timer and thermostat, the hot water boiler constantly on and water temperature is controlled via the boiler water thermostat.

Warning, mains voltage !

I was able to splice the heating relay into the circuit inline with the timer and thermostat.

Now when you turn your old thermostat to maximum, and set your clock to constant on, the heating relay will control your heating pump.

and spliced the hot water relay inline with the boiler water thermostat.

( as a fail back option you could set the heater relay to constant on, and use your old timer and thermostat again )

Software :

After the basic install we need to install the packages and software that will switch the relays and control your heating ( apache, php and mysql )

Connect to the pi over SSH

> ssh pi@192.168.0.100

and execute this script to install everything

> curl "https://raw.githubusercontent.com/JeffreyPowell/pi-config/master/pi-heating-hub-install.sh" > pi-heating-hub-install.sh && sudo bash pi-heating-hub-install.sh

As part of the MySQL instal process it will ask for a root password, make a note of this for the next step.

Now we need to configure the database :

> curl "https://raw.githubusercontent.com/JeffreyPowell/pi-config/master/pi-heating-hub-mysql-setup.sh" > pi-heating-hub-mysql-setup.sh && sudo bash pi-heating-hub-mysql-setup.sh

once everything is installed, you can browse to :

http://192.168.0.100:8080/status.php

and you should see the status page displayed. - we have not set up any sensors yet, so there will be no data.

Step 5: Build and Configure a Temperature Sensor

For each pi zero sensor you want to use, follow the following step

Hardware :

We only need to connect to pins 1, 6 and 7, the other pins are used just to add physical strength.

Pin 1 - GPIO 3.3V ( 1-wire power )
Pin 6 - GPIO GND ( 1-wire ground )
Pin 7 - GPIO 4 ( 1-wire data )

Connect the 1-Wire Digital Thermometer as shown in the diagram. You could connect directly to the pins, or use a small prototype board to connect several 1-Wire Digital Thermometers to the same Pi zero. ( I have two connected to my pi-heating-sensor-01 and three connected to pi-heating-sensor-02 )

Software :

Connect to each pi-heating-sensor in turn,

> ssh pi@192.168.0.101

We can now start to install the packages and software that will read the 1-wire thermometer data and make it available the the heating controller hub.

again there is a script to do this :

> curl "https://raw.githubusercontent.com/JeffreyPowell/pi-config/master/pi-heating-remote-install.sh" > pi-heating-remote-install.sh && sudo bash pi-heating-remote-install.sh

once everything is installed, reboot :

> sudo shutdown -r now

now we need to edit the config file ~/pi-heating-remote/configs/sensors

but first we need the discover the serial numbers of the connected 1-wire thermometers

> ll /sys/bus/w1/devices/

Will show that I have two 1-wire thermometers connected, 28-0000056e625e and 28-0000056ead51.

drwxr-xr-x 2 root root 0 Jan 25 15:23 .

drwxr-xr-x 4 root root 0 Jan 24 16:17 ..

lrwxrwxrwx 1 root root 0 Jan 24 16:43 28-0000056e625e -> ../../../devices/w1_bus_master1/28-0000056e625e

lrwxrwxrwx 1 root root 0 Jan 24 16:43 28-0000056ead51 -> ../../../devices/w1_bus_master1/28-0000056ead51

lrwxrwxrwx 1 root root 0 Jan 25 15:23 w1_bus_master1 -> ../../../devices/w1_bus_master1

Now edit the config file and insert these serial numbers.

> vi home/pi/pi-heating-remote/configs/sensors

Delete the default settings and insert the serial number and a name for each 1-wire thermometer.

remove all this :

28-000005cf873e = External

28-000005d0065c = Conservatory

28-000005d01a5a = Conservatory Rad

and add your data, e.g. :

28-0000056e625e = Lounge

28-0000056ead51 = Garden

save and close the config file.

That's it :) everything should now be installed and configured, but lets test it to make sure.

First we can run some tests via our SSH session and verify how many 1-wire thermometers are connected :

> curl localhost:8080/count.php && echo

2

then we can display the names and values of each thermometer :

> curl localhost:8080/name.php?id=1 && echo

Lounge

> curl localhost:8080/value.php?id=1 && echo

2.5

> curl localhost:8080/name.php?id=2 && echo

Garden

> curl localhost:8080/value.php?id=2 && echo

21.5

as you can see by the temperatures returned, I need to swap the physical location of the sensors !

We can also test from our desktop via a browser using the following URLs with your static IP :

http://192.168.0.101:8080/count.php

http://192.168.0.101:8080/name.php?id=1

http://192.168.0.101:8080/value.php?id=1

http://192.168.0.101:8080/name.php?id=2

http://192.168.0.101:8080/value.php?id=2

Repeat the above instructions for all additional sensors, pi-heating-remote-02, pi-heating-remote-03 etc.

Step 6: Configure Input Sensors and Output Devices

Now we have the hub and sensors setup we can start to connect then.

First we will configure the input sensors. ( thermometers )

Browse to the hub status page :

<p>http://192.168.0.100:8080/status.php</p>

Click on 'Input Sensors' button then click on the 'Scan for new sensors' button.

the app will scan your local network for any thermometer sensors you have set up.

The hub updates sensor data and switches the relays every minute.

Click 'Done' to go back to the main status page.

Next we will configure the output devices. ( relays )

Click on 'Output devices' then click on the 'Add new' button, then click 'Edit' next to the new device.

Update the name to 'Heating' and enter the pin number of the heating relay ( in our case 10 ), the relays I used are active when the GPIO pin is low, so I entered zero in the Pin Active H/L field. ( if your relays are active high, enter 1 )

Click 'Save' then 'Done', then 'Done' again to get back to the status page. ( repeat the last few steps if you have a second relay for the water boiler on pin 8 )

Now we need to create a schedule to switch the heating relay(s) on and off.

Step 7: Create a Heating Schedule

A schedule can be triggered at a specific time, a day of the week, a mode, a timer, when a device is connected to the local network or a combination of these triggers.

A mode is a simple flag that can be either on or off, e.g. 'Working from Home', 'Weekend Away' etc.

A timer is similar to a mode but once activated will automatically deactivate after a specific time, e.g. 'Heating Boost'

A connected device can be anything on the local network identified by its MAC address, 'Jeff's iPhone' etc.

  • To create a Mode, from the status page, click on 'Modes' > 'Add new' > 'Edit' , rename it 'Weekend Away', click 'Save' > 'Done' and 'Done' again to take you back to the status page. The 'Weekend Away' mode button is now displayed on the right of the status page.
  • To create a timer, from the status page, click 'Timers' > 'Add new' > 'Edit', rename it 'Heating boost' and change the duration to '60', click 'Save' > 'Done' and 'Done' again to take you back to the status page. The 'Heating Boost' timer button is now displayed on the right of the status page.

You can click the mode button on and off, and the timer button will count down every minute.

Ok, now we can configure some schedules.

  • From the status page click 'Schedules' > 'Add new' > 'Edit', rename the schedule, set the time and day of week for the schedule to run, select which output device you want to trigger 'Heating' and/or 'Water Boiler', then select the temperature required, ie. when the lounge is below 21 degrees. All these setting need to be TRUE for the schedule to trigger, all other options are set to 'be ignored'. click 'Save' > 'Done' > 'Done'

That's it, your heating is now controlled by your raspberry pi.

Step 8: External Access From the Internet

If you want to control your heating from anywhere you will need to configure your router to forward port 8080 network traffic to the heating controller hub ( 192.168.0.100 )

and for security, add some basic password protected access.

> curl "https://raw.githubusercontent.com/JeffreyPowell/pi-config/master/pi-heating-hub-secure.sh" > pi-heating-hub-secure.sh && sudo bash pi-heating-hub-secure.sh

enter a password when prompted.

The next time you browse to the app you will need to enter username 'admin' and the password you entered.

Sensors Contest 2017

Participated in the
Sensors Contest 2017

2 People Made This Project!

Recommendations

  • Arduino Contest

    Arduino Contest
  • Barbecue Speed Challenge

    Barbecue Speed Challenge
  • Home Decor Challenge

    Home Decor Challenge

96 Comments

0
RomanW9
RomanW9

6 days ago

Not sure if anyone is still paying attention to this project, (the comments are old) but i have tried to solve the No Available Senors problem. Have tried all of the suggestions here and have reloaded the Hub many times. The remotes all respond as they are supposed to but I can't get the hub to see the sensors.
Can anyone help with where I should look now?
Trying to use this to control my swimming pool heater.

Thanks

0
JffryPwll
JffryPwll

Reply 6 days ago

Hi Roman, how many remote sensors do you have, and what are their IP addresses ?

0
RomanW9
RomanW9

Reply 4 days ago

One remote sensor with IP 192.168.1.31 and the Hub is 192.168.1.30. I have changed the $subnet_cidr line in the sensors-list.php file to 192.168.1.0/24 and tried adding a $subnet_scan = "192.168.1.31 / n"; line as well.

Thanks

0
JffryPwll
JffryPwll

Reply 3 days ago

can you run this command, and post results here
nmap -sP 192.168.0.0/25 | grep report

0
RomanW9
RomanW9

Reply 3 days ago

Thanks for your help. I was able to get it working. I must have had the syntax wrong for the $subnet_scan = "192.168.1.31/n" line. I played around with it and finally the sensors appeared on the hub display. The temperature updates are working now.

I do have one other question. Is it possible to use a 10K thermistor instead of the DS18B20 1 wire device? I want to measure swimming pool temperature and the thermistors have a much easier mount to the water pipes.

0
JffryPwll
JffryPwll

Reply 3 days ago

if you can read the value of the thermistor with a raspberry pi it will work,
you just need to supply your own code to read the sensor value and edit these files on the heating-remote :
/home/pi/pi-heating-remote/configs/sensors
/var/www/pi-heating-remote/name.php
/var/www/pi-heating-remote/value.php

0
RomanW9
RomanW9

Reply 2 days ago

Thank-you for pointing me in the right direction.

0
RomanW9
RomanW9

Reply 3 days ago

192.168.0.0 produced no output since my subnet is 192.168.1.0 . The ouput for that is:
pi@HydroPi:~ $ nmap -sP 192.168.1.0/25 | grep report
Nmap scan report for 192.168.1.1
Nmap scan report for 192.168.1.2
Nmap scan report for 192.168.1.3
Nmap scan report for 192.168.1.4
Nmap scan report for 192.168.1.5
Nmap scan report for 192.168.1.6
Nmap scan report for 192.168.1.10
Nmap scan report for 192.168.1.15
Nmap scan report for 192.168.1.17
Nmap scan report for 192.168.1.22
Nmap scan report for 192.168.1.24
Nmap scan report for 192.168.1.25
Nmap scan report for 192.168.1.26
Nmap scan report for 192.168.1.27
Nmap scan report for 192.168.1.28
Nmap scan report for 192.168.1.30
Nmap scan report for 192.168.1.31
Nmap scan report for 192.168.1.100
Nmap scan report for 192.168.1.101
Nmap scan report for 192.168.1.102
Nmap scan report for 192.168.1.103
Nmap scan report for 192.168.1.105
Nmap scan report for 192.168.1.106
Nmap scan report for 192.168.1.107
Nmap scan report for 192.168.1.108
Nmap scan report for 192.168.1.109
Nmap scan report for 192.168.1.110
Nmap scan report for 192.168.1.111
Nmap scan report for 192.168.1.114
Nmap scan report for 192.168.1.115
Nmap scan report for 192.168.1.116
Nmap scan report for 192.168.1.120
Nmap scan report for 192.168.1.121
Nmap scan report for 192.168.1.124
Nmap scan report for 192.168.1.125


0
SteveC339
SteveC339

Question 4 weeks ago

Hi
Does any body know if this will work with the pi-zero/W with onboard WiFi and if so do I need to alter the sketches.
Thanks Steve

0
RomanW9
RomanW9

Answer 6 days ago

Hi Steve, have you received any responses? I'm pretty sure it would work with the pi-zero/W. However, you will need to load the older Jesse version of Raspian I think.

0
SteveC339
SteveC339

Reply 4 days ago

Thanks for that, I will try when I get chance. No other responses as of yet.
Thanks again Steve

0
dziabong
dziabong

Question 7 months ago on Introduction

Hello. I wonder if it is possible to connect few temperature sensors to one raspberry pi?

0
dodgy12
dodgy12

Answer 6 months ago

You sure can. They communicate serially so can add quite a few. I am using three at the moment conencted to one Pi Zero

Dodgy12

0
Hartley_man
Hartley_man

Reply 5 months ago

Not true, there is a limit to the number of sensors you can add. I have four on our system and if I try to add anymore then they all becomes unstable and some of them simply stop communicating.
If you need more then four sensors, then I suggest you add another raspi-remote..... I installed a ‘raspi-remote within a touchscreen’ in our lounge to provide the temperature of that room and to monitor and control the system.

0
rubidium9
rubidium9

Reply 4 months ago

Hartley_man

Where did you source your "DS18B20" sensors from?

Do you realise that unless you purchased directly from Maxim previously Dallas Semiconductors or an authorised distributor, it is very likely a poor counterfeit, clone, fake device?

Your sensor problem is likely due to using one of the many different variant copies that fail to meet the genuine DS18B20 specification!

See https://github.com/cpetrich/counterfeit_DS18B20/b...

Please confirm if you are using genuine or fake devices?

Finally many thanks to Jeffrey Powell for an excellent project.

0
jonsag
jonsag

Reply 5 months ago

Hartley_man, I think you have some problem with power supply, or possibly use to many 4.7k resistors. I've had many sensors connected with no problem. Perhaps you've added a resistor to each sensor? There should only be one for all sensors. Some sensor units have the resistor built in, so you need to disable them, only having one for the whole bus.

0
Hartley_man
Hartley_man

Reply 5 months ago

Jonsag, I agree the DS18B20 can read 10, 20 or more without any issues but I have found that the Heating Hub / Remote can only read 4 or 5 before it becomes unreliable. I have built 2 systems and both had the same issue.
How many sensors do you have attached to your system, what cable type did you use to connect them all back to the pi.

0
jonsag
jonsag

Reply 5 months ago

Actually I have not had that many connnected to this setup, but I have experimented on other projects with perhaps 10 or so. That project was written in python. Perhaps you are right that this particular implementation has some problem with the timing when reading the dallas sensors.

0
ÁgostonD
ÁgostonD

3 years ago

Best raspberry heating controller I ever see. Is there any chance that you will improve it with more functions? For example local sensor on the hub device?

I have an uneccesary old RPi 1 with a DHT11 sensor, and trying to build a simple controller without remote sensors.

0
dodgy12
dodgy12

Reply 5 months ago

Hi, I did not use the "remote" pi sensor, you can run it all on just one Pi hub and a few temperature sensors.