Design of smart radiator valve for home based on Raspberry Pi
Source: InternetPublisher:红水杯 Keywords: Embedded Raspberry Pi Updated: 2024/08/23
This project uses cheap heat actuated valves (around £10 on ebay) and separate electronics based on the ESP8266 to provide WiFi controllable radiator valves. Home Assistant (on a Raspberry Pi) can then be used to control the valves and, if required, the boiler as well.
A DHT22 temperature sensor can be added so that the electronics can also feed the temperature back to Home Assistant. A board with multiple relays can be used to control multiple radiators. You can have the valve and board run on 24V using a 13A plug PSU (recommended), or the valve and board run on 240V.
All you need to complete this project is a 3D printer and a humble stepper motor. It's a humble project, but it works and it's ticking away in my apartment, quite successfully.
Supplies
Valve: There are several valves on ebay, some are 24V, most are 240V. I recommend choosing 240VC normally open ones.
Electronic product selection:
24V system with ESP01 board, 24v to 5v buck converter and smoothing components
Single board ESP12, 24V or 240V, you can add a DHT22 temperature and humidity sensor if you wish.
(1 is more interesting, maybe more fun, and smaller. 2 is more convenient.)
transformer
Step 1: 24V Valve Controller Based on ESP-01
This is easier to solder and understand than the single board approach, but it's fun and physically very compact.
This solution is 24V only. The parts are:
24V 1A 13A plug transformer
ESP-01
ESP-01 Relay Card
24V to 5V Step-Down Converter
100n and 10n polyester capacitors, 10microFarad electrolytic capacitors, the smallest ferrite beads, a small circuit board - if you include extra smoothing, see below
Small box - I used 72x48x24mm
24V Thermally Actuated Valve
The ESP8266 is an amazing little microcontroller with Wifi that only costs a few pounds. Sometimes it can be a little sensitive to noise on the PSU. All those Chinese PSUs and converters are very overpriced for the price and can be noisy. So I added smoothing between a step-down converter and a 5V ESP-01 relay board.
The buck converter I used had a variable output voltage and I needed to carefully set it in a miniature potentiometer with a watchmaker's Phillips screwdriver and check the voltage with a multimeter.
You can see that I've over-miniaturized, and the vero-board portion is unmanageably small. In fact, I'm not even sure it needs to be - the ESP-01 will probably work just fine with just the buck converter and no smoothing capacitors or ferrite beads.
See how I soldered to the back of the board here and there - you need a fine, clean soldering iron tip and a little finesse.
Adding a DHT22 sensor might not be easy, I haven't tried it yet.
Step 2: ESP-12f Relay Board - 24V
This is a much simpler and neater solution than the ESP-01 method above. The ESP-12f is superior - 4Mb of RAM over 1Mb, and there are more GPIOs available. If you want the electronics box to have a temperature/humidity sensor, you can easily add a DHT22, which Home Assistant can use to control turning the radiator on and off. The box doesn't have to be right next to the valve (you can choose the length of wire between the box and the valve), so the temperature sensor can be located very usefully, away from the distorting effects of the radiator.
If you add a DHT22, it has 4 pins, but only 3 are used (see lots of info on the web.) It needs a pull-up resistor, I used a 6.8K, between "sense" and Vcc - see how I soldered the wires to the sensor (not inside the box). This provides a sensor that can be disconnected from the main board if needed, which makes it easier to build and disassemble if you wish. It's very clear which I/O pin number you're plugging into so you can configure it (see.)
These boards take any DC voltage from 12v to 80v. We use 24V for the valves, so it's very neat: one power supply for the board and the valves. It's also very safe: all supply voltages are inside the 13A plug PSU, safely insulated in an officially manufactured part.
Step 3: ESP-12f Relay Board - 240V
If you are really careful and are absolutely sure you understand, you can use 240V valves and boards.
In fact, from what I've heard, 240V valves are more readily available (although you shouldn't have a problem finding 24V.)
A board very similar to the one in the previous step can have a little 240V switch mode power supply mounted on it and it's almost no longer needed. I think I paid £8 instead of £6. Amazing!
However - I really don't like mains voltage. You risk shock and fire - why take that risk?
That said, it's pretty easy. In my case, I had the DHT22 option (note that I used thermoplastic to protect the dht22 wires - I made a mistake, this photo was taken before re-melting and remodeling.) I would say that despite having 240V inside, adding the DHT22 is a further unnecessary risk, so again - I think we should stick with 24V for this project, as it's cheap, neat, simple and safe.
The boards are a bit large. There is a 10x6x2.5cm box on ebay for cheap.
Step 4: Boiler Control
Only a corgi registered engineer should work on the boiler. My Vaillant has a two wire interface for a switch that turns the heat on, the clock takes the two wires and closes the switch between them at the 'on' time. I recommend you run the project like this - just keep using your clock but set up your wifi controlled valve on Home Assistant to coincide with the time. However the controller works the same for the boiler as switching the 24V power to the heat actuated valve.
I don't have remote controls on all my radiators, so the boiler always has some radiator to heat. I'm not a heating engineer or plumber, but I believe that if all radiators are closed, the boiler's pump will be affected, and I think I'm right when I say that heating engineers always install a radiator without a thermostatic valve. Anyway, even if you have my valve design on all radiators, you can still make sure at least one is open via the automation configuration in Home Assistant.
Step 5: Install the radiator valve
It should be a matter of unscrewing the old thermostatic valve and screwing the electric valve in. You may need to press very hard when doing this.
Interestingly, the travel on the valve seems to be very small, maybe 5 or 6mm for all I know, but all the ones I've tried seem to work fine. As shown in the picture, I forget which manufacturer it is, it may have slightly less threads: it won't work on one of my radiators, but the others do.
Step 6: Arduino Sketch - Loading and Configuration
I made a generic sketch that can be used with either or both of the relay and the temperature/humidity sensor. It uses LittleFS to upload a configuration file which configures what hardware is present and what the GPIO pins are (they vary between the ESP-01 and different boards.)
You can even compile in a dummy temperature or relay class, since I moved the hardware details into separate classes. The ESP-01 is only 1Mb, and we want LittleFS and Arduino to upload "over the air" so we don't have to unplug the ESP-01 or connect USB serial to the card's TX/RX (more than once.)
Sketch and included files attached, as well as some configuration files.
On Arduino, you'll need the ESP8266 board library (there's lots of information on this online.)
You'll also need LittleFS, PubSubClient, ArduinoJson (See the #includes at the top of the sketch.) Add these using the library manager.
I think you get all the others by default.
Please note that I have deleted my name and password:
char mqtt_user[34] = “xx”;
char mqtt_pwd[34] = “xxxxx”;
You can put yours, but you can also add them to the config file, as you like.
If you want to configure temperature or relays:
//#include "DummyTemp.h"
#include "Temp.h"
//#include "DummyRelay.h"
#include "Relay.h"
Just changed to use the dummy version as commented. Actually, you probably don't need this. I think it might help on the ESP-01 to save a little memory and keep OTA working, but I think the compiled code is small enough anyway.
Note that the config file is the card ID - you can only see it the first time you run the sketch, so you can only create the file after running it once. You can then upload it using LittleFS under "Tools" in Arduino.
Uploading code is different for ESP-01 and ESP-12f boards. Make sure you select the correct memory and file system size on the tools menu. For the ESP-01 it's 1Mb, for the ESP-12f it's 4Mb (Arduino may autodetect, no guarantees.) Choose the smallest file system size you see, the largest that will let OTA work (it will only work on the ESP-01!)
ESP-01 - You unplug and plug the USB/ESP-01 serial adapter and then the PC serial board into the Arduino environment.
ESP-12f card - You'll need a regular USB to serial adapter, see the photo, and connect the TX, RX, and Gnd to the board using the 3-way ribbon connector (see the picture of one of the board connectors, but they are slightly different.) Note that you have to reverse the TX and RX between the board and the plug so that the board's TX goes to the plug's RX and vice versa (otherwise you'll be transmitting to the transmitter, if you know what I mean).
Make sure you understand the difference between Program and Run modes in both cases. The ESP8266 reuses the I/O lines for uploads, and you must connect IO0 to ground to set this mode. The ESP-01 USB adapter has a small switch, but for the ESP-12 you need to bridge GND and IO0 using the small jumper that came with the board (see photo - the jumper was not installed when taken.)
This project uses the very nifty WiFiManager. The first time you run the sketch, the Wifi goes into access point mode. Connect to the board using your laptop or smartphone - I think it says "AutoConnectAP" but I forget. This should be obvious. You then select your wifi name, enter your password and save. The board then connects to your wifi.
Run the card for the first time with the serial monitor plugged in (see pic.) Sorry, I have an undiagnosed bug so when you run the uploaded code, without the config file, it crashes quickly, *but* you will see the card name displayed in the serial monitor on the Arduino (or putty or whatever). You can then create a config file and upload it to Tools/LittleFS. I noticed that some ESP-01 cards would cause the Arduino to show an error at the end of loading, but they would still get to 100% and load. Very annoying, but I couldn't fix it. The config files must be in a subdirectory called data! Example configs (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
}
The configuration is JSON. These controllers use MQTT to communicate with the Home Assistant controller (you can also use the mosquitto tools mosquitto_sub and mosquitto_pub to monitor messages and send your own messages.)
You are most likely using mDNS (aka "Bonjour", avahi, etc) on your LAN. If so, your mqtt server will have a "local" domain. I think the sketch may not work with the .local domain - but I'm not sure (mDNA code may need to be added - I'm just not sure.)
If you set the detector type you are configuring a temperature/humidity detector. Use a dht22. You can use a dht11, they are cheaper - but don't bother.
You can have 0 or more relays, that's why the JSON array. Normally you'd only have one GPIO for the relay, but I have a useful board with 2 relays for controlling my bedroom and a radiator outside the hall. Then you have two GPIOs (and 2 sets of mqtt stuff, see below.) You really need to find out which GPIOs are which from the card documentation. Some relay cards require you to add jumpers between the relay pins and the GPIO pins (my dual relay was the one I had trouble with.)
MQTT is completely out of scope here, but I'll add details and suggestions if asked.
A key concept is topic. Messages are sent on "topics". The boards have topics for information about temperature (if used) and relay status. When the board boots up it reads its card ID, suffixes one or both of "-dh22" and/or "-relay" to show what hardware you have, then adds the suffix to the "mqtt_topic_suffix" you configured - you set this to identify the valve controller among others.
Once the card is running, you can test mqtt by uploading the config file via LittleFS. Install the mosquitto utility for your platform - I think Windows will have it 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 send a command on the command channel to turn on the relay, and it answers with the new status on the info topic, then I ask with the STATUS command, and I also added a RESET command to reboot the card if you want it to. If you install a dht22 and wait 10 minutes you will get the 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-
Note that you can monitor temperature and humidity based on a known thermometer and set corrections into the config file. The dht22s can be off by 2 or 3 degrees sometimes! The dht22 is also very noisy. I wish the commercial ones were the same (like the Tuya zigbee thermometer, which is great value for the money), but they would have smoothing code. I did this by using the Hampel library to throw out the outliers so that my thermometer is almost as smooth as the Tuyas. If you run the board with the serial monitor you will see debug code showing when outliers are being discarded. You can tweak the outlier parameters, number of samples, and sampling frequency, but I hope you find what I was working towards.
When the card is configured and working you can detach the serial port, or unplug the esp01 and plug the relay (or temperature) module in. You should see it sending information on mqtt when it runs!
Download virtual temperature.h
Download virtual relay.h
esp0EF487.txt download
esp7FD57A.txt download
esp29A28C.txt download
esp2548B5.txt download
Temperature.h download
Relay.h download
relay-temp-hampel-littlefs-oo.ino
Step 7: Home Assistant on Pi + MQTT
Installation, setup and configuration of Home Assistant is mostly out of scope. There are lots of tutorials documented. The default installation comes with a Raspberry Pi specifically for Home Assistant, which is officially "supported". You can install it on an existing Pi.
You'll also need the MQTT broker plugin. You can install MQTT separately, but although I had some trouble installing it, I think the broker is probably best.
Configuring sensors and switches is also a little tricky, but see my screenshot showing both. My sensors don't go into zones. It doesn't seem to be as simple for home assistant to configure mqtt sensors in yaml, I haven't tried it as it's not that cumbersome. It just means your automation can't say "turn on the downstairs radiator", but instead has to have a list of switches.
You'll see I made two automations: turning on the radiators before I get up, and turning them off if/when it gets hot. You'll see me keeping my apartment cool. The body of the radiator valves is in a state of reverse flow, which makes them very noisy when switched - that's why you'll see the valves fully open or fully closed before operating the boiler (but remember - this is an experiment in controlling a boiler - you should use your clock.) I hope you don't have to go to this trouble.
- Analysis of the circuit principle of ZX5-630 welding machine
- Input and output polarity reversal circuit composed of MAX660
- Analysis of the circuit of DL-01 low-frequency electrotherapy instrument
- How to Control Large Linear Actuators with Arduino
- Water tower water control circuit
- Fiber Optic Data Receiver Circuit
- CF1 (CF2) DC power supply circuit
- Mining winding hoist anti-loosening rope protection circuit
- Water level automatic controller circuit
- DC motor pulse width speed regulation circuit using integrated circuit
- The most detailed explanation of ATX power supply, please find out!
- Do you know about FlexChannel for multi-bus system debugging?
- A dedicated computer system, embedded design and development analysis
- Embedded-based robot system circuit module design
- How does an optocoupler work? Introduction to the working principle and function of optocoupler
- 8050 transistor pin diagram and functions
- What is the circuit diagram of a TV power supply and how to repair it?
- Analyze common refrigerator control circuit diagrams and easily understand the working principle of refrigerators
- Hemisphere induction cooker circuit diagram, what you want is here
- Circuit design of mobile phone anti-theft alarm system using C8051F330 - alarm circuit diagram | alarm circuit diagram