Smart heating control algorithm - new, open-source

For heating/cooling related questions in Domoticz

Moderator: leecollings

Post Reply
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Smart heating control algorithm - new, open-source

Post by jefft »

Hi All,

If you're looking for smart control of your heating system, you might find this useful - either to use, or to take ideas from.

https://github.com/jefft4/Heating-control-algorithm

This is my heating control algorithm, which has been working well in our home through the last 15 months. It handles many combinations of zones, valves, sensors and heat source types - for example, I have it set up with 7 heating zones and hot water, a mix of radiators, hydronic fan heaters, smart TRVs and dumb valves and a boiler with flow temperature control. You can configure the heat-up and cool-down rates of each zone and the heat source individually, along with outside temperature sensing and prediction options to help the algo to maintain the desired temperature.

The code is written in dzVents and the configuration and control are via domoticz user variables and standard device types; there's nothing external and no plug-ins.

Feel free to use it, adapt it, ask me any questions here. I hope it's useful to others! :D

Jeff
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
VinnieV8
Posts: 3
Joined: Monday 20 December 2021 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Smart heating control algorithm - new, open-source

Post by VinnieV8 »

Hi Jeff,

Thanks for posting this Smart Heating Control Algorithm and the deatailed guide.
Although your guide is quite extensive I'm missing some additional info about the global user variable file which I could not find in the guide or on your GitHub, do I need to create this file and fill it with the default user values or is it created on the first run of the DzVents agorithm for heating control?
When I need to create this file where should it be stored? When it needs to be created, do you have an example file?

Vincent
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

You create user variables on the domoticz 'Setup -> More Options' menu. The global control one is called 'Heating control global'.

Examples of a few from my system in the image... hope that helps :D
Screenshot 2021-12-20 154636.jpg
Screenshot 2021-12-20 154636.jpg (212.56 KiB) Viewed 3608 times
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
VinnieV8
Posts: 3
Joined: Monday 20 December 2021 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Smart heating control algorithm - new, open-source

Post by VinnieV8 »

Jeff,

Yes of course the user variables of Domoticz, didn't see the link here, Thanks, also the screen shot will help.

Vincent
Alain
Posts: 164
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Smart heating control algorithm - new, open-source

Post by Alain »

I've been looking for something like this to control a couple of heat pumps that I will be receiving in a while. I have a room thermostat (Thermosmart), but it doesn't show me the required water temperature. I need that to set the supply setpoint on the heat pumps through Modbus. I'm hoping to integrate this script as a sort of gateway between the Thermosmart and the heat pumps.
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
mariano
Posts: 2
Joined: Tuesday 03 May 2022 9:47
Target OS: Windows
Domoticz version:
Contact:

Re: Smart heating control algorithm - new, open-source

Post by mariano »

Jeff, this is indeed a very useful algorithm, thanks for sharing it. I will definitely use it for smart control of my heating system.
Milan
Posts: 8
Joined: Sunday 25 October 2020 15:36
Target OS: Linux
Domoticz version: 2023.1
Location: CZ
Contact:

Re: Smart heating control algorithm - new, open-source

Post by Milan »

Thanks for the great work Jeff. I would like to try it for 7 zones, but it is not clear to me exactly what devices are used. Can you please provide a screenshot of the device in Domoticz? Like variables.
Thanks a lot.
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

[Sorry for slow reply, I don't seem to be getting the notifications for this thread even though the box is checked!]

Did you work through the user guide? You need one "Heating zone" user variable string for each zone. Just create as many as you need :-) Those variables will look something like this (this is one of mine):

Code: Select all

"Heating zone lounge rear"	String	
{"sensor": 1730, "age": 15, "setpoint": 2157, "mvalve": "CH", "valve": "LR", "incRate": 0.7, "decRate": 0.4, "outSensor": "OD", "prefPHT": 30, "maxPHT": 120, "minDT": 20, "sw": 527}
Each zone needs to be associated with an indoor temperature sensor, an outdoor temperature sensor (sensors defined by "Heating sensor" user variables), one or two control valves (defined in a "Heating valve" user variable), and a setpoint device. Sensors and valves can be shared by several zones if that's how your heating system works.

The values within the user variable strings are all explained in the document; some are optional. There's an example near the end of the user guide for a heating system, which should help to show all the component parts linked together.

Hope that helps!
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
Milan
Posts: 8
Joined: Sunday 25 October 2020 15:36
Target OS: Linux
Domoticz version: 2023.1
Location: CZ
Contact:

Re: Smart heating control algorithm - new, open-source

Post by Milan »

Thanks jefft for your reply. I got the script working and I would like to ask a couple of things. My situation: 7 zones, each with a thermostat (setPoint) and termostatic valve on the radiator (mvalve). In Domoticz, I have a short script: when at least one mvalve is active, then boiler is turned on. I have a central gas boiler without water heating. I have a thermometer ("idxFlowTemp") on the outlet pipe. I set "idxReturnTemp" to "idxFlowTemp". What function does have flowSet"? It seems to me that the boiler goes to high temperatures and does not turn off when "heaterMaxTemp" is exceeded.
"incRate" and "decRate" are difficult to determine. I set them by guesswork. The bathroom heats up quickly incRate = 1.4, the living room more slowly incRate = 1.6.
In the main script, I turned off Boiler manual / service, Boiler master, Heating mode.
"CycleTime" I shortened to 12 minutes to check the temperature and conditions more often.
Thanks a lot.
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

Okay, let's work through those points...

Flow & return - for now the return temp isn't used anyway so what you do with it doesn't matter. Return is optional anyway; might be better to omit it in case it is used in the future.

To control the flow temperature, you need a boiler with OpenTherm or Bosch EMS and a suitable interface to domoticz. For example, my "flowSet" is a domoticz dummy setpoint device, which in turn sends the 'set flow temperature' command to the EMS interface attached to my boiler. Do you have such an interface?

Something I've discovered is that with Bosch EMS, the 'set flow temp' command has to be repeated every few minutes else the boiler reverts to the temperature set by its control panel. I use a little timed event to re-send that command. The boiler can sometimes exceed heaterMaxTemp for a while; that's not in our control, it's the behaviour of the boiler. We tell it what temperature we want, but sometimes it overshoots. If it continues to heat after the rooms are at their target temperatures, then the heat/cool rates and other parameters need tuning.

incRate and decRate are best calculated by reference to real data. Look at the temperature graph of your room from cold to hot and the temperature of the radiators; incRate is [rise in room temp] / [time] / [heater temp - room temp] and decRate is [drop in room temp] / [time] / [room temp - outdoor temp] (more details, units, etc are in the user guide). Yours appear to be the wrong way around; a room that heats more quickly will have a higher incRate. The warmUpRate of the boiler is also relevant; if that's set too low, the boiler will get hotter and stay on for longer. You can calculate that factor using your flow temperature sensor; it's temperature/time.

A 12-minute cycle time sounds fine with a gas boiler; I read somewhere that 6 minutes is the minimum to avoid damage, but I wouldn't go so low!

How often are your room temperature sensors reporting to domoticz? If your heating stays on too long, sometimes that can be because the sensors have not reported the changing temperature frequently enough so the predictions think that the room is cooler, and heating more slowly, than it really is. When I tested and researched for my system, I found that many zigbee and z-wave sensors by default only report for a >0.5C change or every 30 minutes! The sensors must report significantly more frequently than the cycle time - e.g. mine are 3 mins vs 15 mins cycle.
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
Milan
Posts: 8
Joined: Sunday 25 October 2020 15:36
Target OS: Linux
Domoticz version: 2023.1
Location: CZ
Contact:

Re: Smart heating control algorithm - new, open-source

Post by Milan »

Hi jefft,
I don't have OpenTherm or Bosh EMS, just a regular gas boiler where I added a ds18b20 thermometer to the output. "flowSet" I created as dummy thermostat, without it the script reports an error. I havn't such an interface. Can I skip it?
How often are your room temperature sensors reporting to domotics? I have sensors based on ESP2866 and ESP Easy and they send the temperature every minute. That should be ok.
I will try to adjust IncRate, DecRate as you write.
I deleted parametr "idxReturnTemp" but: heatingControl: no idxReturnTemp defined in user variable [Heating control global]! Unable to work without this.
One more question. "heaterMinOnTime":5. Let's assume that the need to turn on the boiler will be 10 minutes. "cycleTime" = 12 minutes. What will cause the boiler to shut down before the cycleTime event occurs?
Thanks
Milan
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

You need flowSet, but it's fine for it to be a dummy. In that case, your boiler will always run at the temperature set by the boiler controls; find out what that is and set your min and max boiler temperatures both to that value.

Every minute for the sensors is great :-) Same as mine, ESPEasy!

Sounds like I need to change the check on idxReturnTemp; that should be optional... oops! ;-)

The boiler will be on for however long the algorithm decides is needed in each cycle, but never less than heaterMinOnTime; that's to protect the boiler from damage. The decision on how long is needed, is based on the temperature rise needed, the incRate and decRate, warmUpRate, etc. You can change the 'lognote' function at the top of the code to make it log all the information if you want to see how it's thinking. Sometimes, that can be very helpful in tuning the parameters, as you will see if it over-estimates or under-estimates how the temperature will change with time.
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Smart heating control algorithm - new, open-source

Post by Derik »

Thnaks
For this script..
Looking forward to use this..
Only i use a Heatpump? Also possible?

Perhaps a small how to?
Like to hear

Thanks
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

Hi Derik,

I've not tried it with a heatpump as I don't have one, but conceptually it should work fine. You'll need to check what it's possible to control - e.g. flow temperature - and set the heat source parameters appropriately. If you can't measure flow/return temperatures, you can dummy those sensors. Zones
and their valves and temperature sensors should work the same for any type of heat.

Good luck!
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
mjray
Posts: 18
Joined: Wednesday 05 October 2022 2:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Smart heating control algorithm - new, open-source

Post by mjray »

Would it be possible to adapt this to cope with heating cost varying over time? I could input reasonable estimates for the next 24 hours. Any tips, pointers or suggestions?

Otherwise, I can manipulate the setpoint but that seems less good than using it to influence the flow temperature directly. The ideal decision would be: if "fuel" is far more expensive in the next period, better to use more now to preheat to near the cap value and use less then to stay above the collar value.
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

@mjray. I think that's a whole other application, rather like manipulating electricity use in line with solar generation and grid prices. You could certainly link something like that with the heating control. One approach might be to play with the user variables that control the min & max flow temperatures, or to replace those with setpoint devices that you can tweak more easily in code. If you wanted to pre-heat, you would also need to manipulate the setpoints and/or the pre-heat periods. If you created something that worked out your targets & flow temp based on fuel costs, you could perhaps copy the 'how much heat' logic from my algo to control the valves to get the best result within those boundaries.

I'm a bit sceptical as to how well pre-heating can work. I can see potential in it if you look an hour or two ahead and heat to just above target; any more than that and you'll probably have to over-heat then cool down more than is comfortable. If you could pre-heat some sort of heat store to drawn down later, that would be really cool (warm...!)

Have fun, let us know how you get on!
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
mjray
Posts: 18
Joined: Wednesday 05 October 2022 2:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: Smart heating control algorithm - new, open-source

Post by mjray »

jefft wrote: Thursday 17 November 2022 15:00 @mjray. I think that's a whole other application, rather like manipulating electricity use in line with solar generation and grid prices.
Yes, that's what I'm doing. ;) The heater is an air-source heat pump, so as well as local production and grid prices, there is also the challenge that the energy of the air varies with its temperature, but we have weather forecasts that predict that fairly well for the near future.
I'm a bit sceptical as to how well pre-heating can work. I can see potential in it if you look an hour or two ahead and heat to just above target; any more than that and you'll probably have to over-heat then cool down more than is comfortable. If you could pre-heat some sort of heat store to drawn down later, that would be really cool (warm...!)
Part of my current dumb approach is to move the target up by about a degree a few hours before the electricity price trebles (every day at 0730), then drop it back. Usually, that and the solar gain of a morning (we have clear sky to the east) is enough that the heating does not activate again until after dark, or at least the afternoon in December/January.

I read of people using their hot water tanks as heat stores and then transferring some of that heat back to the heating loop, but my system isn't plumbed for that. There are also specialist heat stores, which are not your granny's storage heaters, but I know even less about them.
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Smart heating control algorithm - new, open-source

Post by zygios »

Hi,
Trying to use code, but getting error:
2022-12-11 08:10:00.647 Status: dzVents: Info: ------ Start internal script: Floor_heat_alg:, trigger: "every 5 minutes"
2022-12-11 08:10:00.650 Status: dzVents: Info: #### Heating control
2022-12-11 08:10:00.657 Status: dzVents: Info: Heating params: cycle time 15, water min/max 26/36, min on time 5, warm-up rate 4
2022-12-11 08:10:00.667 Status: dzVents: Info: Found a zone definition: Heating zone Kosto // {"sensor":103, "age":15,"setpoint":189,"valve": "Kosto","mvalve": "ST","incRate": 1.0,"decRate": 0.3,"outSensor": "OD","prefPHT": 30,"maxPHT": 120,"minDT": 25,"hyst": 0.3,"sw":275}
2022-12-11 08:10:00.668 Status: dzVents: Info: #### Heating control: first pass processing for zone Kosto
2022-12-11 08:10:00.668 Status: dzVents: Info: sensorIdx=103 setpointIdx=189 valve=Kosto outSensorIdx=OD sw=275
2022-12-11 08:10:00.670 Status: dzVents: Info: getSetpoints: called for device idx189
2022-12-11 08:10:00.672 Status: dzVents: Info: bitToday=64, bitTomorrow=1, bitYesterday=32
2022-12-11 08:10:00.672 Status: dzVents: Info: Setpoints:API call URL: <curl 'http://192.168.1.xx:xxx/json.htm?idx=189&type=setpointtimers'>
2022-12-11 08:10:00.716 Status: Incoming connection from: 192.168.1.xx
2022-12-11 08:10:00.724 Status: dzVents: Info: ------ Finished Floor_heat_alg
2022-12-11 08:10:00.724 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler Floor_heat_alg
2022-12-11 08:10:00.724 Error: dzVents: Error: (3.1.8) ...icz/scripts/dzVents/generated_scripts/Floor_heat_alg.lua:208: attempt to index a nil value (local 'json2')

Can't understand issue reason.
jefft
Posts: 75
Joined: Monday 23 January 2017 23:30
Target OS: Linux
Domoticz version: 2023.1
Location: UK
Contact:

Re: Smart heating control algorithm - new, open-source

Post by jefft »

It's failing to find the JSON parser module. If you look into the code where 'json2' is first assigned, you'll see what it's looking for, "/home/domoticz/domoticz/scripts/lua/JSON.lua". If that's not your path, just correct the code. If that is your path, check that the lua file exists, permissions are good, etc.

[Sorry it took so long to answer; I'm still not getting email notifications on this thread even though the 'notify me' is ticked!]
Domoticz, Z-Stick Gen.5, zzh Zigbee, rxftrx433XL on Ubuntu 22.04, HP 290 G1.
Node Red, MQTT, 80+ Z-wave, ESP8266 & Shelly, handful of Zigbee bulbs. EMS-ESP gateway for Bosch boiler. Controlicz, until it dies :-(
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest