Thermostat with PID controller

great project. I started reading about this. I started using it :smiley: letā€™s see how it behaves :smiley:

I planed to use this PID Thermostat. Do you think it will include hass soon ?

@fabian.n Nice work. easy to install and setup.

Will it be possible to make a more detailed step by step guide on how to use autotune? I am unable to find the logger.info and also not sure how to make autotune run for the first time and how to disable it when values are secured.

Thanks again.

I tried to use it. I have floor heating and it just doesnā€™t work for me because I get some division by zero error. I tried fixing it but I donā€™t know the math behind itā€¦ I need to read more about formula and how I can apply itā€¦

@larsbach You have to enable the logging for info in home assistant. Right now default is warning and the pid logging is info

At https://github.com/home-assistant/home-assistant/pull/27833 a new thermostat is proposed. Maybe we can also bring the PWM/PID functions in this new thermostat?

Is there somebody who can give me a little bit more context on how this works? Does it work well with underfloor heating? Can somebody give a review on how it compares to the original generic_thermostat?

Thanks in advance,
Ronald

Iā€™m working on making this easier to use for everyone. Basically the normal Thermostat uses a very simple ā€œif colder then 20Ā°C, heatā€ A PID controller uses 3 different methodes Potential, Integral and Differential. Basically if set up correctly it predicts the Temperatur change over time and controls the heating accordingly. This eliminats the overshoot that happens if you heat until it e.g. reaches 22Ā°C. Therefor it can safe you a lot of energy. Especially floor heating has a very large overshoot because of the mass.
However, PID controller are not ā€œplug and playā€, set up wrong they donā€™t work.
Small note, floor heating can explode if you set the temperatur too high.

1 Like

I really like the idea but in my head it misses support for other states. Outdoor temperature, illuminance, weather, sun azimuth and angle are all factors that have a great role in my house.

I already think for a long time, my thermostat should use deep reinforcement learning but I donā€™t have a clue on how to start :slight_smile:.

Exactly this it what takes me so long to programm. Because I want to include all that in a new version instead of fixing the old one. My expirence in building automation has shown me itā€™s acutally very easy to do. However, Iā€™m not a big programmer so I have a hard time including this in the UI to make it accessable for others.
If someone else wants to work with me that has that expirence, I gladly do so.

Then we should perhaps team up!

Iā€™ve got experience in the Lovelace frontend and know my way around some custom components.

I was missing that info as well so Iā€™ll share my progress hereā€¦

Iā€™ve been using it now for the last two weeks with floor heating and it keeps my temperature quite stable within limits.

My situation:
The house is a recently build (2017-18) 140m2 house with district heating (stadsverwarming) so I donā€™t have to control the heating system itself, I just have to open and close the main valve.

My config:

  • I have to say that I modified the climate.py to fix some typos and to match with the ā€˜generic-thermostatā€™
  • modified PID controller my wishes :wink: (added moving average D part (velocity) and changed some on the limits for the I part) ā€¦ so my settings should be used I think with my code only.
  • PWM and PID settings tuned to roughly mimic honeywell behaviour
  • Visiualised in Lovelace by ā€˜simple-thermostatā€™

modified climate and PID settings

  - platform: smart_thermostat
    name: woonkamer
    heater: switch.hoofdklep
    target_sensor: sensor.temp_wk
    min_temp: 15
    max_temp: 23
    ac_mode: False
    target_temp: 18
    
    keep_alive: #time before update of PID controller
      seconds: 60
    away_temp: 16
    kp : 50
    ki : 0.005 #0.01
    kd : 150000 #0
    
    #duration of cycle
    pwm : 600
    # autotune : ziegler-nichols
    difference : 100
    noiseband : 0.5

However some generic settings for the default PID and floor heating could be. I think I used something like this at the beginning (use on your own risk!)

  - platform: smart_thermostat
    name: woonkamer
    heater: switch.hoofdklep
    target_sensor: sensor.temp_wk
    min_temp: 15
    max_temp: 23
    ac_mode: False
    target_temp: 18
    
    keep_alive: #time before update of PID controller
      seconds: 60
    away_temp: 16
    kp : 50
    ki : 0.01
    kd : 0
    
    #duration of cycle
    pwm : 600
    # autotune : ziegler-nichols
    difference : 100
    noiseband : 0.5

the critical note :slight_smile:
I still use it as a test. If I understand it correctly no or limited safety routines are included in the ā€˜generic thermostatā€™ for failing sensors etc. thus also not in this code! So for testing and not long periods away from home Iā€™m using it but Iā€™m not convinced I want to use it as standard. It has to be more robust. There is some development on a new code ā€™ virtual_thermostatā€™ which ,if I remember correctly, should be more robust, but Iā€™m a too bad programmer to check-validate it.

and as last a graph of the temperature of before and after.

  • yellow is the PWM signal
  • green main floor temp
  • HA controlled when yellow line is present.
  • before yellow line Honeywell chronotherm

1 Like

Wauw, I like your way of doing stuff - especially the before and after graphā€¦ this is a data scientist at work.

My situation is similar: itā€™s a house from 1840 which we completely renovated and isolated. We have large windows on the south side and these interfere a lot with the generic thermostat.

As for heating, I have a Itho Daalderop Central Heater (instead of your stadsverwarming) and for each room, I can control the valves of the underfloor heating. All is controlled by HomeAssistant.

  • If any room is requesting heating, the valves of that room open and central heating is turned on.
  • If no room is requesting heating, the central heating is turned off.

The valves itself are thermo-electric (e.g. candlewax valves: https://en.wikipedia.org/wiki/Wax_motor). The response times of the valves is about 2-3 minutes to open and 10 minutes to close.

So, my gut feeling says:

  • The PWM wonā€™t work as response time of the wax valves is too slow / I have fear the wax motors will die faster if I use PWM
  • The influence of the sun/weather is large due to the windows on the south side and should be taken into account

And to be honest: I donā€™t know anything about a PID thermostat :smirk:. I should put it on my todo-learning list soon but my gut feeling says it wonā€™t work due to the external influences. Or am I wrong?

Thanks for your input, Iā€™ll think of making it robust.
This shows me, I need to include safety, didnā€™t really think of that. Your graph doesnā€™t really look good. It should definitely be more stable. However it depends on your case and what happend.
If itā€™s ok for both of you. Iā€™ll make a flowchart on everything with an regular floor heating as an example. And upload it here to get some feedback if itā€™s what you would want and if thereā€™s anything missing?

1 Like

We have large windows on the south side and these interfere a lot with the generic thermostat.

PID will probably improve it a lot but a limited effects will still be there.

The influence of the sun/weather is large due to the windows on the south side and should be taken into account

Here the same. Most optimal would be weather dependant regulation in combination with room temperature but I expect it will be more difficult to set parameters. With weather controlled heating you need to know the relation between heat loss and required heating.

The PWM wonā€™t work as response time of the wax valves is too slow / I have fear the wax motors will die faster if I use PWM

The generic thermostat uses on-off. So it already a kind of PWM but less accurate: it opens and closes for certain periods depending the room temp limits. Do you log the frequency it is opening and closing right now?

When using slow actuators the code might needs an update instead of just longer PWM cycle time or other kp, ki, kd settingsā€¦ I thinkā€¦ (but better ask @fabian.n, he probably knows this a lot better as Iā€™m more of trail and error). You might have to add a time addition to the PWM to include the opening and closing time. As a short PWM heating moment will have a relative long open-close interval and at a long PWM heating moment the open-closing will have a relative limited influence. You might need a min cycle period as well.

1 Like

Thanks for your input

Your welcome. It would be great to have a good working thermostat with PID control.

Iā€™ll think of making it robust.
This shows me, I need to include safety, didnā€™t really think of that.

Yes safety and robustness is very very important (at least for me) for such an important house function. Did you already have a look on the virtual_themostat, might this one a better basis? It seems that a lot of the code is the same as the generic_thermostat. virtual thermostat

Your graph doesnā€™t really look good. It should definitely be more stable. However it depends on your case and what happend.

The temperture variations are not too bad for me. The part before the PWM signal is controlled by a honeywell chronotherm, which is it believe, a quite reasonable thermostat. The 2-3 extreme peaks are created by not normal conditions (more people or door long time open).
The heating has some trouble catching up with the changes due to the quick heating by the sun and on the other side the slow low temp heating by the floor. To solve this a ā€˜differenentā€™ or more complex controller is required with info of the weather, but you are working on that one I saw :wink:

But please let me know if you have any tips to improve the behaviour and to achieve a more stable heating! I will test it!

Just started using this superb PID Thermostat, its fascinating. I am using standard Gas Central Heating system, on-off boiler control relay. Have been playing with the PID Autotune, not sure its doing exactly what I thought it should be doing, so have switched it off and starting to play with PID values now. Its a fascinating and absorbing subject, will post results here when I get some, thanks for the great work, REALLY wish I could help with Python design stuff, but only a begginner, however, VERY happy to provide Testing and Feedbackā€¦ Keep coding! :slight_smile:

1 Like

Hi, then for use this custom-component we need a external PID controller?
for example i have a xiaomi sensor and as thermostat a nodemcu with relay for on or off the heating.
i need have a external PID controller ?? because i intalled the custom component a always says ā€œ[custom_components.smart_thermostat.climate] Obtained current control output. 0.0ā€

Thanks in advance

Hi!

I see that Fabianā€™s repository has been forked many times.
What is the most actively maintained fork ?

Hello,

A long time ago I programmed a PID controller in appdeamon and used it to heat the house. I even added the outside temperature as a disturbance and it worked quite well. Anyway I digress, before coming to HA I used Jeedom, and they had a ā€œsmartā€ thermostat that learned how the room was heated, how the outside temp influenced the internal temp ect. Jeedom would then compute a PWM signal to control the heating (on for x mins during y mins) https://jeedom.github.io/plugin-thermostat/fr_FR/ . Turns out this was an app for a Vera smart house controller. The algorithm has been ported to Domoticz in python and can be found here : https://github.com/999LV/SmartVirtualThermostat.
Looks like it is what you peeps are looking for?! Iā€™ll post the link as a request for integration into HA thermostat.

Cheers,

Matthew

1 Like