Remote Control Radiator Valves and Raspberry Pi Home Assistant Heating Control

by Crabbers in Circuits > Microcontrollers

3656 Views, 11 Favorites, 0 Comments

Remote Control Radiator Valves and Raspberry Pi Home Assistant Heating Control

20220215_191742.jpg
20220216_092533.jpg

You can now get nifty sets of battery powered smart radiator valves, with hubs and smartphone apps, for £250-ish. I'm sure they're very good, but how about doing some of your own, more cheaply, and having a bit of fun (and probably some swearing too) with esp8266s, a soldering iron and Home Assistant and its smartphone apps?

This project uses cheap thermally actuated valves (£10-ish on ebay) and separate ESP8266-based electronics to give a WiFi-controllable radiator valve. "Home Assistant" (on Raspberry Pi) can then be used to control the valves, and the boiler too if desired.

It's possible to add DHT22 temperature detectors so that the electronics can also feed temperature back to Home Assistant. Boards with more than one relay can be used to control more than one radiator. You can get valves and boards to run on 24V with a 13A plug PSU (recommended,) or valves and boards that run on 240V (caution!!)

The amazing "Smart Radiator Valve With Home Assistant" Instructable creates a 100% home-made remote control radiator valve that's a thing of beauty, but it's quite complicated and needs a 3D printer and an obscure stepper motor. This is a humbler project, but it works and it's ticking away in my flat, fairly successfully.

Supplies

20220216_093400.jpg
20220216_093554.jpg
20220216_093544.jpg
20220216_094334.jpg
buck-converter.jpg
20220216_094930.jpg
20220216_094521.jpg
20220215_143131.jpg
close-up-20220124_162425.jpg
low-voltage-esp12-relay-card.jpg
close-up-nc-240v-valve.jpg
2ndhand-valve.jpg
20220227_103405.jpg

Valves: There are several types of valve on ebay, some 24V, most 240V, some normally open, some normally closed. I'd very strongly recommend sticking to 24V, although I've done a couple of 240v. NO or NC isn't critical, because you set up your Home Assistant automations to control them appropriately. Probably when the boiler's on, most radiators are on, so they spend more time open - Normally Open might be best. The best type I've found is the last pictured, pear-shaped with a grill on the top, and the little window to show the valve position. The very common type pictured first, which is all over ebay and you buy straight from China - it's ok, but I've found I've had to adjust the mounting, rather than screw it right down, whereas the white, pear-shaped one has been excellent (only problem: I don't know who makes them - I just saw them being sold off on ebay, seemingly from surplus stock.)

Electronics choices:

  1. 24V system with ESP01 board, 24v to 5v buck converter and smoothing components
  2. Single board ESP12, 24V or 240V, and you can add a DHT22 temperature/humidity sensor if you like.

(1 is more fiddling & perhaps more fun, and a little smaller. 2 is more straightforward.)

Transformer: if you do 24v, a cheap 13A plug PSU is easy to find on ebay. Lowest amps you find, probably 1A, unless you see 500mA. I metered a valve & it was about 3.5w when cold, 2.5w when warmed up. That's 250mA plus electronics - not much.

ESP-01 Based 24V Valve Controller

20220216_100126.jpg
20220216_094352.jpg
20220215_135626.jpg
20220215_135634.jpg
buck-converter.jpg
20220216_093554.jpg

This is more soldering and understanding than the single board approach, but it's interesting, and physically quite compact.

This solution is 24V only. Parts are:

  1. 24V 1A 13A plug transformer
  2. ESP-01
  3. ESP-01 relay card
  4. 24V to 5V buck converter
  5. 100n and 10n polyester capacitors,10microFarad electrolytic capacitor, smallest ferrite bead, small bit of circuit board - that's if you include extra smoothing, see below
  6. small box - I used 72x48x24mm
  7. 24V thermally actuated valve

The ESP8266 is an amazing little microcontroller, complete with Wifi, for a couple of quid. It's a little sensitive to noise on the PSU sometimes. All these Chinese PSUs and converters are very much made to the price, and can be noisy. Therefore I added smoothing between the buck converter and the 5V ESP-01 relay board.

The buck converter I used has a variable output voltage, and I needed to set it carefully with a watchmaker's Philips screwdriver in the tiny potentiometer, and a multimeter to check voltage.

You can see that I've overdone the miniaturisation, and that the vero-board part is unmanageably small. In fact I'm far from sure it's even needed - probably the ESP-01 would work fine with just the buck converter and no smoothing capacitors or ferrite bead.

See how I've soldered to the backs of boards here and there - you need a fine, clean soldering iron tip and a little skill.

It might not be easy to add a DHT22 sensor, and I haven't tried.

ESP-12f Relay Board - 24V

close-up-20220124_162425.jpg
low-voltage-esp12-relay-card.jpg
20220216_094930.jpg
20220215_144241.jpg
2ndhand-valve.jpg
20220216_093554.jpg

This is a simpler and neater solution than the ESP-01 method above. The ESP-12f is superior - 4Mb of memory over 1Mb, and more GPIOs are available. It is easy to add a DHT22 if you want the electronics box to have a temperature/humidity sensor, which Home Assistant can use to control turning radiators on and off. The box need not necessarily be right next to the valve (you choose the length of wire between box and valve,) so that the temperature sensor can be pretty usefully located, away from the distorting effect of the radiator.

If you add the DHT22 it has 4 pins, but only 3 are used (see copious info on the web.) It needs a pull-up resistor, I used 6.8K, between "sense" and Vcc - see how I soldered that with the wires, onto the sensor (rather than inside the box.) This gives a sensor that can be disconnected from the main board if necessary, which is much easier to build, and dismantle if you want to. Be quite clear which I/O pin number you've plugged into, so that you can configure it (see on.)

These boards are fantastic. They take any DC voltage from something like 12v to 80v. We are using 24V for the valve, so it's very neat: one power source for board and valve. It's also very safe: all the mains voltage is inside the 13A plug PSU, safely insulated in an official, manufactured part.

ESP-12f Relay Board - 240V

20220215_143131.jpg
20220216_093400.jpg
20220127_123658.jpg
20220216_132747.jpg

If you are really careful and very sure you understand, you can use a 240V valve and board.

In fact 240V valves are easier to obtain, as far as I can see (although you shouldn't have trouble finding 24V.)

A very similar board to the one in the last step can be had with a little 240V switch mode power supply on it, for hardly any more. I think I paid £8 instead of about £6. Amazing!

Yet - I really dislike mains voltage. You risk shock and fire - why take the risk?

That said, it's easy. On mine I have the DHT22 option (notice I've used hot plastic to protect the dht22 wires - I got this slightly wrong and this photo is from before a re-melt and reform of it.) I would say though that given there's 240V inside, adding a DHT22 is a further needless risk, so again - I think we should stick to 24V for this project, because it's cheap, neat, easy and safe.

These boards are a bit bigger. There's a 10x6x2.5cm box on ebay that's quite cheap.

Boiler Control

Only a Corgi registered Engineer can work on a boiler. My Vaillant has a two wire interface for the switch that turns on heating, and the time clock takes the two wires and closes a switch across them when it's "ON" time. I recommend you run the project like this - simply continue to use your timeclock, but set up your wifi controlled valves on Home Assistant to coincide with the times. The controller would however work equally for the boiler as for switching on 24V to a thermally actuated valve.

I don't have remote control on all my radiators, so the boiler always has some radiators to heat. I am not a heating engineer or plumber but I believe it's the case that if all radiators are shut off, the boiler's pump would suffer, and I think I'm right in saying that heating engineers always fit one radiator without a thermostatic valve. Anyway even if you had my valve design on all radiators, you could still ensure that at least one is on via your automation configs in Home Assistant.

Mounting Radiator Valves

20220216_092533.jpg
20220215_192114_01.jpg

It should be a matter of unscrewing your old thermostatic valve, and screwing on the electric one. You will probably need to press quite hard as you do so.

It's interesting - the travel of the valve seems very slight, maybe 5 or 6 mm as far as I can see, yet all the valves I've tried do seem to have worked well. The one pictured, I forget its make, might have slightly less thread: it wouldn't go on one of my radiators, whereas the others did.

Arduino Sketch - Load and Configure

20220216_093505.jpg
usb-serial-esp01.jpg
20220216_115248.jpg
20220216_115242.jpg
20220216_115235.jpg
20220216_115310.jpg
arduino-serial.jpg

I have produced a general purpose sketch that can work with either or both of relay(s) and a temperature/humidity sensor. It uses LittleFS to upload a configuration file that configures what hardware is present, and what the GPIO pin(s) are (they differ between ESP-01 and the different boards.)

You can even compile in dummy temperature or relay classes because I moved hardware specifics to separate classes. The ESP-01 has just 1Mb, and we want both LittleFS and Arduino "Over the Air" uploads, so that we don't have to unplug the ESP-01 or connect USB Serial to TX/RX for the cards (more than once at any rate.)

Sketch and included files attached, and a few config files.

On Arduino you'll need the ESP8266 board library (lots of info on the web.)

You also need LittleFS, PubSubClient, ArduinoJson (see the #includes at the top of the sketch.) Add these using library manager.

I think you get all the others by default.

Note that I've x'd out my name and password:

char mqtt_user[34] = "xx";
char mqtt_pwd[34] = "xxxxx";

You can put yours but you can also add those to the config file, just as you like.

If you want to configure out either Temperature or Relay:

//#include "DummyTemp.h"
#include "Temp.h"
//#include "DummyRelay.h"
#include "Relay.h"

Just change to using the Dummy version via commenting. In reality you probably won't need this. I thought it might help for the ESP-01, to save a little memory and keep OTA working, but I think the compiled code is just small enough anyway.

Notice the config file is the card Id - you only see this when you first run the sketch, so you can only create the file after running it once. Then you can upload with LittleFS under "Tools" on Arduino.

Uploading code is different for the ESP-01 and ESP-12f boards. Make sure you select the right memory and file system size on the tool menus. For ESP-01 it's 1Mb, for ESP-12f it's 4Mb (Arduino might auto-detect, no guarantees.) Select the smallest size File System you see, leaving the max for OTA to work (and it will just work on ESP-01!)

ESP-01 - you unplug, and plug into the USB/ESP-01 serial adapter, and into your Arduino environment's PC's serial board.

ESP-12f cards - you need to get a plain USB to serial adapter, see photos, and use a 3 way ribbon connector to get TX, RX and Gnd to the board (see the picture of one of the boards connectors, but they differ slightly.) Note that you have to reverse TX and RX between board and plug, so that the board's TX goes to the plug's RX and vice versa (otherwise you're transmitting to a transmitter, if you see what I mean.)

Be sure you understand in both cases the difference between program and run modes. ESP8266 re-uses I/O lines for uploading, and you have to ground IO0 to set this mode. The ESP-01 USB adapter has a little switch for this, but for the ESP-12 you'll need to use the little jumper that comes with the board to bridge GND and IO0 (see the photo - no jumper installed when taken.)

This project uses the very nifty WiFiManager. The first time you run the sketch, the Wifi goes into Access Point mode. Use a laptop or smartphone to connect to the board - I think it shows as "AutoConnectAP" but I forget. It should be obvious. You can then choose your wifi name, enter the password and save. The board then connects to your wifi.

Run the card first time with the serial monitor plugged in (see photo.) I'm sorry to say I have an undiagnosed bug so that at this point when you run the uploaded code, without a config file, it quickly crashes, *BUT* you'll see in the serial monitor on Arduino (or putty or whatever) the card name displayed. You can then create a config file and upload it on Tools/LittleFS. I've noticed that some of the ESP-01 cards cause Arduino to display errors at the end of loading, but nevertheless they got to 100% and loaded. Annoying, but I couldn't solve it. Config files must be in a sub-directory called data! Example config (several attached) -

{
"mqtt_server":"ha.abe", 
"mqtt_port":1883, 
"mqtt_topic_suffix":"-240v",
"dht_gpio":4,
"temp_correction":-1.8,
"humidity_correction":-4,
"detector_type":"dht22",
"led_gpio":16,
"relay_gpio":[5],
"relay_active_state":1,
"led_active_state":0
}


Config is in JSON. These controllers use MQTT to communicate with the Home Assistant Controller (you can also monitor messages and send your own using mosquitto tools mosquitto_sub and mosquitto_pub.)

You might well be using mDNS on your LAN (aka "Bonjour", avahi, etc.) If so your mqtt server will have a "local" domain. I think that the sketch as it is might not work with .local domain - but I'm not sure (possibly mDNA code would need adding - I'm just not sure.)

If you set detector_type you're configuring a temperature/humidity detector. Use a dht22. You can use a dht11, they're cheaper - but don't bother.

You can have 0 or more relays, that's why the JSON array. Normally you'll just have one GPIO for the relay, but I have one useful board with 2 relays, that controls my bedroom and the hall outside's radiators. Then you have two GPIOs (and 2 sets of mqtt things, see below.) You do need to work out which GPIO(s) from card documentation. Some relay cards need you to add jumpers between a relay pin and a GPIO pin (my dual relay one is the one I encountered that on.)

MQTT is fairly out of scope here but I'll add details and advice if asked.

A key concept is topic. Messages are sent on a "topic". These boards have an information topic for temperature (if used,) and relay state(s). When the board starts it reads its card Id, suffixes either or both of "-dh22" and/or "-relay" to show what hardware you have, and then suffixes your configured "mqtt_topic_suffix" - you set this to identify the valve controller amongst others.

When you've got the card running, with config file uploaded over LittleFS, you can test mqtt. Install mosquitto utilities for your platform - I think windows will have it all too; I use linux. Here's some output from my latest relay card:

mosquitto_sub -v -h ha.abe -u XX -P YYYY -t '#' | ts | grep 0F74
Feb 15 18:43:45 esp0F74D3-dht22-relay-240v-NO OFF
Feb 15 18:45:04 esp0F74D3-dht22-relay-240v-NO OFF
Feb 15 18:46:19 esp0F74D3-dht22-relay-240v-NO OFF
Feb 15 18:46:35 esp0F74D3-dht22-relay-240v-NO-cmd ON
Feb 15 18:46:37 esp0F74D3-dht22-relay-240v-NO ON
Feb 15 18:47:28 esp0F74D3-dht22-relay-240v-NO-cmd STATUS
Feb 15 18:47:29 esp0F74D3-dht22-relay-240v-NO ON
Feb 15 18:47:36 esp0F74D3-dht22-relay-240v-NO-cmd RESET
Feb 15 18:47:44 esp0F74D3-dht22-relay-240v-NO OFF

Notice how I sent commands on the command channel to turn on the relay, and was answered on the info topic with the new status, then I interrogated with a STATUS command, and I've also added a RESET command if you want the card to reboot. If you've a dht22 installed and you wait 10 mins you'll get temperature:

Feb 15 19:15:05 esp0F74D3-dht22-relay-240v-NO-temp {"humidity":"52.9","medianh":"53.0","temperature":"18.0","mediant":"18.0","hum-correct":0,"temp-correct":0}
Feb 15 19:27:38 esp0F74D3-dht22-relay-240v-NO-temp {"humidity":"52.3","medianh":"52.3","temperature":"18.2","mediant":"18.2","hum-correct":0,"temp-correct":0}

Notice that you can monitor the temperature and humidity against a known thermometer, and set corrections into the config file. dht22s can need 2 or 3 degrees sometimes! dht22 are also quite noisy. I expect commercial ones are too (like the Tuya zigbee thermometer, which is excellent value,) but they'll have smoothing code. I have done this by using a Hampel library for knocking out outliers, so that my thermometers are almost as smooth as Tuyas. If you run the board with a serial montior you'll see debug code showing when outliers are dropped. You can tune the outlier parameters, the number of samples and the sampling frequency, but I hope you find what I've worked towards suitable.

When the card is configured and working, you can detach serial, or unplug the esp01 and plug into the relay (or temperature) module. You should see it sending its info on mqtt when it's running!

Home Assistant on Pi + MQTT

ha 2022-02-16-12-39-30.jpg
ha 2022-02-16-12-37-39.jpg
HA 2022-02-16-12-39-22.jpg
HA 2022-02-16-12-39-08.jpg
HA 2022-02-16-12-38-55.jpg
HA 2022-02-16-12-38-36.jpg
HA 2022-02-16-12-38-32.jpg
HA 2022-02-16-12-38-05.jpg
ha 2022-02-16-12-37-53.jpg

Home Assistant installation, set-up and configuration are mostly out of scope. There's lots of documentation. The default installation has a raspberry pi devoted to Home Assistant, and that is what is officially "supported". You can install it on an existing pi, I have, and it works, but that's non-standard.

You also need the MQTT broker add-on. You can install MQTT separately, but although I had some troubles getting it going, I think probably broker's best.

I set mine up with a user and password, and getting it working was a little tricky. If you have any trouble I might be able to help. I didn't attempt more secure arrangements with keys, which mqtt can do.

Configuring sensors and switches is also a little tricky but see my screenshots showing both. I haven't got my sensors into zones. It appears that's not straightforward for home assistant with mqtt sensors configured in yaml, and as it isn't very troublesome I haven't tried. It just means your automations can't say "turn on downstairs radiators", but instead must have a list of switches.

You'll see I've done two automations: turning on radiators before I get up, and turning them off if/when it gets warm. You'll see I keep my flat cool. The bod who put my boiler in muddled flow and return, so radiator valves are on return and that makes them very noisy when switching over - that is why you'll see the valves are fully open or fully closed before operating the boiler (but remember - this was an experiment in controlling the boiler - you should use your time clock.) I'd hope I was alone in having this trouble.

Instructables seems to have rather shrunk my config screens - I'll help if you can't follow them.