Thermostat with PID controller

Thank you @fabian.n I will test this.

Before home assitant I used jeedom which have smartThermostat plugin. Jeedom thermostat (auto-tune) has better regulation compares of native climate components of home assistant.

I hope contribute with my test to improve your component.

In order to start, can you explain what default value of kp, ki, kd we can be set to start to use this ?

start with:

  • kp: 7.66141138481997
  • ki: 0.4086086071903984
  • kd: 35.91286586634361

if you use pwm make sure you set the min_cycle_duration to the minum on time of your heating hardware in order to not damage it!

pwm shoud be the time of your heater to reach 100% (time until the radiator feels very hot). if min_cycle_duration is larger then that take that time and multiply it by 3 for pwm.

Thank you I will test this

Hey @fabian.n
Iā€™ve got a runtime error. My log:

2021-02-10 12:59:43 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2021-02-10 12:59:43 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2021-02-10 12:59:47 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for smart_thermostat which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2021-02-10 12:59:51 WARNING (MainThread) [homeassistant.components.climate] ClimateDevice is deprecated, modify SmartThermostat to extend ClimateEntity
2021-02-10 12:59:53 WARNING (MainThread) [custom_components.smart_thermostat.climate] Autotune will run with the next Setpoint Value you set.changes, submited after doesn't have any effekt until it's finished
2021-02-10 12:59:54 WARNING (MainThread) [custom_components.smart_thermostat.climate] No previously saved temperature, setting to 19.0
2021-02-10 12:59:55 ERROR (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'unknown'
2021-02-10 13:00:31 ERROR (MainThread) [custom_components.smart_thermostat.climate] Unable to update from sensor: could not convert string to float: 'unknown'

What am I doing wrong? That sensor was ok in the generic_thermostat

Please clone the dev branch not the main and try it again.

1 Like

@fabian.n
Thank you, the dev branch is working. Atm, it works the same as a generic thermostat but maybe itā€™s only a configuration issue. Iā€™ll try to play with pid params a little bit. I will test it for a couple of days and come back with feedback. See you

I just started to test the dev branch in my test environment.
So far it is working.
What I like is that you can now set the temperature in 0,1 Ā°C steps.

What Iā€™m still missing is the autosave function of the current temperature.
If I restart HA, the set temperature will fall back to the default value.

Again, thanks for your work

The behavior of the dev branch is way different than the version bevor.

As you can see in the picture, the ON interval is too long which results in the temperature curve to swing up and down.
The big temperature increase (beginning/end) is caused by sunlight which comes through the windows.

The old version was pretty accurate when it comes to the stability of the temperature curve.
What did you change?

keep_alive:
  seconds: 180
min_cycle_duration:
  minutes: 5
away_temp: 16
kp : 5
ki : 3
kd : 2
pwm:
  minutes: 16

Hello All,

I have this kind of message since few week with my custom component Smarts thermostat:

Logger: homeassistant.loader
Source: loader.py:794
First occurred: 9:48:10 (1 occurrences)
Last logged: 9:48:10

No ā€˜versionā€™ key in the manifest file for custom integration ā€˜smart_thermostatā€™. As of Home Assistant 2021.6, this integration will no longer be loaded. Please report this to the maintainer of ā€˜smart_thermostatā€™

Can you help me?

Do you think we can find this kind of integration in HACS or other?

The smart_thermostat is no longer working with the latest release as announced

@fabian.n
Are you planning to update your project?
If not I would like to know (if possible) and start to look for alternatives
Winter is coming :wink:

It is pretty easy to fix that, just add:

ā€œversionā€: ā€œ1.0ā€,

to your manifest.json in the smart_thermostat folder.

Full manifest.json:

{
ā€œdomainā€: ā€œsmart_thermostatā€,
ā€œnameā€: ā€œSmart thermostatā€,
ā€œversionā€: ā€œ1.0ā€,
ā€œdocumentationā€: ā€œGitHub - aendle/custom_components: missing feature test reposetoryā€,
ā€œrequirementsā€: ,
ā€œdependenciesā€: [
ā€œsensorā€,
ā€œswitchā€
],
ā€œcodeownersā€:
}

@MudiStar
I too would like to control my floor heating with a PID thermostat.
Itā€™s water based and the valve needs about 3 minutes to open/close.

I thinkt the correct values are:

min_cycle_duration:
  minutes: 3
pwm:
  minutes: 15

Which version would you recommend? Dev or master?
Which PID values would you recommend to start with?

Thanks for your answer.

@fabian.n
Thanks for your work on this!

Hello, Iā€™m new in Home Assistant and Iā€™m try to learn the yaml language. I alredy do a servo control with a slider, and my goal is regulate the position of the servo with the PID control. I donā€™t now exactly if I can do that with this integration because I donā€™t know how to get the output value of the PID.
Iā€™m in the wrong way?

Thanks

It seems the development of this thermostat is stopped

I tried to use it to control a towel dryer in the bathroom using a pilot wire switching between comfort and OFF modes.
The control seems OK, but the autotune leaded to ZeroDivisionError exception, so it couldnā€™t adjust the PID parameters automatically.

I used the following configuration (I had to comment the initial_operation_mode parameter, it seems it doesnā€™t exist in the integration) :

- platform: smart_thermostat
  name: salle_de_bain
  heater: switch.seche_serviette
  target_sensor: sensor.popp_mold_salle_de_bain_temperature
  min_temp: 7
  max_temp: 30
  ac_mode: False
  target_temp: 24
  keep_alive:
  seconds: 5
  # initial_operation_mode: "off"
  kp : 5
  ki : 3
  kd : 2
  pwm : 1
  autotune : ziegler-nichols
  difference : 100
  noiseband : 0.5

Error message :

2021-10-01 20:37:32 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/smart_thermostat/climate.py", line 433, in _async_control_heating
await self.calc_output()
File "/config/custom_components/smart_thermostat/climate.py", line 476, in calc_output
params = self.pidAutotune.get_pid_parameters(self.autotune)
File "/config/custom_components/smart_thermostat/pid_controller/init.py", line 188, in get_pid_parameters
ki = kp / (self._Pu / divisors[1])
ZeroDivisionError: float division by zero

I ended up using the generic thermostat for the moment, Iā€™ll try to manually adjust the PID parameters using rule of thumb method as described here : https://www.eurotherm.com/temperature-control/pid-control-made-easy/ in order to measure and compensate the inertia.

Hi adrien.b,

the autotune never worked correctly and, to my knowledge, was created for brewing.
I see two options currently:

  1. You use the version in the master branch with the values @MudiStar suggested.
  2. You use the version in the dev branch with the values @fabian.n suggested.

As the heating period starts now, I will try both out and report my findings.

I used PID tuner https://pidtuner.com/ to provide my heater/temperature data vs time and compute some values. It gave me the following :

  kp : 4.672847736461644
  ki : 0.0008760855108256681
  kd : 5025.328799581739

Iā€™ll see how it works

1 Like

Hi Adrien,

Last winter Iā€™ve been creating an update based on this PID thermostat and another thermostat routine (which unfortunately was not released in HA) and expanded it as I needed a zoned heating system (but it still can be used as a single standalone thermostat). You could have a look zoned heating here including some additional explanation about the PID settings in the readme file. Iā€™ve been using it for the last year (and performs quite well to my needs at least).

Regarding the autotune I found it to be tricky, especially for slow varying systems and the large influence of the weather. However Iā€™ve still included the option but did not test it.

Iā€™m trying to control underfloor heating and every room has itā€™s own temperature sensor and wax actuator. All I have is controlling the actuator to set the temperature. The system is very slow and needs constant pulsing so the floors donā€™tā€™ get too cold or too hot. The concrete floors hold so much temperature that if Iā€™m not careful close to the set point then I overshoots by 2Ā°c or so and the temperature in the room is rising for hours after I have turned off the vax actuators.

Hi Stefan

Great question. I am planning a similar application myself (havenā€™t started yet) but I do have a control engineering education.

Based on your description it sounds like you have a large delay in your system (caused by the concrete heat reservoir between the heat source and the room temperature to be controlled) or possibly a second-order system.

Controlling systems of these types, especially those with delays, is tricky! If youā€™re not careful, the combined (closed-loop) system with your controller could be unstable, although it sounds like you have already made some good intuitive decisions.

Here are a few pointers which may help:

  1. The biggest practical problem with PI/PID control is the various different conventions for defining the two/three parameters. In the following notes, I am using the interacting formulation (as opposed to non-interactive or parallel conventions). They are all mathematically equivalent, itā€™s just that the parameter values are defined differently in each, so you need to be very careful which convention you are implementing.

  2. To control a simple system with a stable exponential dynamic (known as a first-order system), including those with a delay, you only need a PI controller (i.e. no derivative term).

  3. A simple but reliable heuristic for setting a PI controller for a first-order system with a delay is:

Kc = (1 / Kp) x (T1 / (T1 + theta) )
Ti = T1

where

Kc = PI controller gain
Ti = PI controller integration time constant (units of time)
Kp = process gain (of the heating process)
T1 = time constant of the process (units of time)
theta = delay of the process.

While this calculation is easy, what you need are good estimates of Kp, T1 and theta. These you can get by doing a step test of your system, provided you can run it in open loop (i.e. manual with no feedback controller). Itā€™s broadly known as system identification but a step test would suffice:

Step 1. Wait until your system reaches an equilibrium point with the heater off or at a constant setting
Step 2. Make a step change in the heater setting (higher or lower) and record the response of your system (i.e. the room temperature) until it reaches a new equilibrium, which could take a while in your case.

Kp = (T2 - T1) / (H2 - H1) where T1, T2 and H1, H2 are the initial and final temperatures, heater settings (e.g. a temp close to the region in which you want to control).
theta = you can probably estimate this as the time from when the heater setting changed to the first indication that the temperature clearly started to change.

T1 = (t_63% - t_step - theta) where t_step is the time when the step change to the input was made, and t_63% is the time when the room temperature reached 63% of itā€™s final equilibrium temperature (i.e. 0.63*T2).

  1. If this doesnā€™t work a more advanced solution to control your system would be possible if you have a temperature measurement for the concrete floor. It sounds like the dynamic between the heater and the floor temperature may be faster than the dynamic between the floor temperature and the room temperature, (I am speculating, but this could be why you are experiencing overshooting of the room temperature). If you can get this extra measurement then you could implement a cascade control system (two control loops running at different sampling rates) which should solve that problem. But this may not be necessary if the PI solution above gives you good enough performance.

Hope this helps! I would be happy to discuss further offline since I will probably be encountering the same problems myself. Feel free to message me directly.

Bill.

All my tentatives to make the smart thermostat work in my bathroom fails. I tried with different combinations of pid, but everytime it fails, heating while the temperature is already too high or not heating while the temperature is 1Ā°C below the setting. :triumph:

Could you include some more details, like:

  • PID settings
  • how do you read your temperature (irregular such as battery + zigBee or continuous regular by wired sensor)
  • temperature reading for tested period (half to whole day)
  • Control output signal for same period