In the recent times we see that the global warming is a big problem that is already effecting our world. For an individual person it is sometimes hard to see how to help the environment. On of the things each individual can do is reducing the energy consumption in the household. The biggest energy consumption at the household level is heating during the colder months of the year. Beside the environmental impact of reducing energy consumption there are also benefits for the users directly as the energy bills are lower.
One of the devices to help with this problem is smart radiator thermostat. There are many commercial solutions but they mostly use proprietary protocols and are as such hard to integrate in the smart home infrastructure, beside this the commercial solutions are quite expensive and have high entry level.
I was looking for a viable DIY smart radiator thermostat solution for a long time as we were using old manual electronic thermostats that are quite a hustle to set up and on top of that loose the settings when the battery runs out. Because of this I decided to create this project to develop a smart radiator thermostat.
SpecificationsThe "smart" in the smart radiator thermostat for me means that it is connected and can be integrated to the rest of the smart home infrastructure. Because of this reason I, decided to create WiFi connectable radiator thermostat. I chose MQTT as the communication protocol as it enables much flexibility for connection to the different smart home platforms such as Home Assistant.
For the controller I decided to use the CY8CPROTO-062-4343W development kit. The kit enables WiFi connection and has a NTC thermistor already onboard for the air temperature measurements. To focus more on the FW side, I decided to disassemble an old "non smart" electronic thermostat and reuse its hardware for this project.
As Home Assistant provides specifications for the automatic discovery of MQTT devices and the protocol for communication over MQTT topics I decided to implement those. In this case the radiator thermostat is an HVAC climate device for which the specifications can be found here.
PrerequisitesIn this section I will give a short description of the smart home setup used and provide short instructions on how to setup the environment.
As previously stated I used Home Assistant as the smart home platform. I installed a Home Assistant instance using docker on the Raspberry Pi 4B. Besides the Home Assistant the Raspberry also runs an Eclipse Mosquitto docker container as the MQTT broker.
Here are some basic instructions on how to setup the environment (this is just for reference for someone just starting):
- Install Raspberry Pi OS (desktop 64-bit) using Raspberry Pi Imager on a SD card.
- Put the SD card in the Pi and connect Ethernet cable, HDMI cable, keyboard and mouse. Then plug in the power supply and boot into the Raspberry desktop.
- Open the terminal and update the software:
sudo apt update && sudo apt upgrade
- Install docker with the terminal using the apt repository by the official instructions.
- Under home directory setup the directory structure for persistent storage with
mkdir
and create the files withtouch
andnano
. Configuration files for MQTTmosquitto.conf
anddocker-compose.yaml
are at the end.
mkdir apps
cd apps
mkdir homeassistant
mkdir homeassistant/config
mkdir mqtt5
mkdir mqtt5/config
mkdir mqtt5/data
mkdir mqtt5/log
touch mqtt5/log/mosquitto.log
nano mqtt5/config/mosquitto.conf
nano docker-compose.yaml
- Start the containers with:
sudo docker-compose up
- Do the initial Home Assistant setup by opening a browser on the RPi and going to http:\\127.0.0.1:8123
- In the Home Assistant add the MQTT integration under
settings-> Devices & services->ADD INTEGRATIONS
, search for MQTT and add the integration. For broker add mqtt5 (as this is the name of MQTT container) and leave the rest default 1883 for the port and empty user and password. - In the terminal, check the eth0 IP address which will be required later for the radiator thermostat to know where to connect to MQTT broker. The terminal command is:
ip a
By this point everything should be setup.
Preparing the HWIn this project I reused and old manually configurable electronic thermostat for the motor and motor control which enables valve opening and closing. The thermostat reused is from eQ-3 company but probably other brands could be reused by the same principal or one can develop its own HW (which I am planning to in the near future).
In principal a DC motor is used with gearing to drive a linear shaft which pushes on the radiator valve. Depending on how much the shaft is extended the valve opens and closes. When the shaft is fully extended the valve is closed and vice versa when the shaft is fully retracted the valve is opened.
To drive a DC motor a H-bridge circuit is used. Where 4 transistors in pairs of two can connect DC motor leads between supply and ground in both polarities, which enables to drive the motor in both directions. Additionally, voltage divider is used to enable voltage measurements which indicate when the motor stalls, which means the motor reached one of the end positions of the shaft (fully retracted or fully extended).
A schematic of the H-bridge and its connections are presented below and a picture of the circuit used. On the circuit it can be seen that I desoldered the original microprocessor.
The 4 controlling pins for the transistors are connected to P8.0, P9.2, P9.1 and P9.4. The signal for stall detection was connected to P10.5 as the pin enables ADC measurements. (The mic signals connected on the board is fortunately high impedance and does not impact the measurements so no additional modifications were needed.) Additionally, GND must be connected to the development board.
To power the motor I used AA batteries in the disassembled thermostat enclosure.
Program descriptionThe FW developed for this project is based on the Infineon MQTT example project. The program first creates the new developed thermostat task for thermostat operations and the MQTT task which connects to WiFi end establishes connection to the MQTT broker.
The thermostat task initializes temperature measurements and motor control signals. After that it fully retracts and extends the shaft with the motor to calibrate the shaft range. The movement is timed until stall is detected by a voltage drop.
After WiFi and MQTT connection is established a MQTT message about the thermostat configurations and capabilities is published to the MQTT broker under the "homeassistant" topic on which the Home Assistant is subscribed on to discover new devices. With this message the the Home Assistant initializes new device with its capabilities. The smart radiator thermostat then subscribes to tow topics on which it listens to messages from Home Assistant for operation mode ("heat", "off") and the target temperature. When receiving messages on this two topics the thermostat responds on two topics about the operation mode state and the target temperature state. Besides this the thermostat publishes measured temperature and action state (if heating or not) on two additional topics.
Building FWThe project code is accessible at the GitHub repository. Clone the project to your workspace and import the project in Modus Toolbox. In Modus Toolbox select New Application
in Quick Panel
. Chose CY8CPROTO-062-4343W BSP, click Browse for Applications
and select the folder location with the cloned repository. Rename the project, tick the box and click create
.
Configure the WiFi credentials SSID and password of your router in the configs/wifi_config.h
and change the IP address in the configs/mqtt_client_config.h
with the IP of your MQTT broker and the user setting. If flowing the instructions in Prerequisites section input the address from the lest step. Also check the #defineMQTT_CONFIG_TOPIC
which should hold the topic under which your Home Assistant is discovering new devices. By default it is "homeassistant".
Next, build the project and connect the CY8CPROTO-062-4343W development board to your PC with USB cable on the PROG/DEBUG port. Also plug in the batteries if you also used a disassembled thermostat enclosure. Then flash the board.
Program operation and testingAfter the program is flashed the thermostat will start connecting to the WiFi and calibrating the shaft for opening and closing the valve. If everything is working correctly a new card will appear in the Home Assistant where you can test the setting of the target temperature and turning the heating on and off. You should see the current measured temperature and the action state of heating.
For debugging you can establish a serial connection (example PuTTY) with the board where logs will be shown.
Future developmentThis project focused on the FW development side of the smart radiator thermostat where I explored how to connect it trough WiFi and MQTT to Home Assistant. Future work will be to integrate the thermostat in an enclosure. Here a custom PCB will be developed with a custom 3D printed enclosure and the gearing for the linear shaft. Additionally the FW can expended the thermostat modes of operation.
Comments