Thermostat with PID controller

Hi Adrien. Nice to see the progress. Moments when a large external distortion , such as heat of a bath or open window are tricky.

How long does it take before the temperature stabilises tot the setpoint back again?

I think what happens is: The room temp above setpoint will result in lowering of the integral part which defines the average opening time. As soon as the temp starts to drop the integral is already too low and needs to build up again.

For thermostats there is sometimes a routine to check for an open window to avoid that the thermostat runs off and tries to compensate the rapid heat loss.

In your case I imagine it could be two options:

  • you need precisely the opposite of a window routine. Keep the thermostat as is while bathing, especially the integral.
  • different PID settings, but not sure which settings work best
    – a slower reacting PID. Lower ki but temp will rise even more during bathing but with less drop.
    – or more aggressive, higher KP and kd?

See here an example to expose variables from the controller in HA. Use the functions name and a dict as return .
https://github.com/vindaalex/multizone-thermostat/blob/066f721642e719817bb3edfe427d9f0d27f42859/custom_components/multizone_thermostat/climate.py#L789

Thanks for the example. Works really nice.

1 Like

First release of my first custom component. Thanks @fabian.n for the base integration and @axax and @pidtuner for the support.

Hi adrien.b,

thanks for taking this project over.
I switched to your repository.

Thanks a lot,
pacemaker

Hello !

I installed and I test on a room. But if you leave the option autotune the thermostat remains on idle


Hello @Canaletto, did you make a step on the target temperature to start the autotuner ?

When using the autotune, the PID is disabled, and the ambient temperature need to be outside of the noise band around the set point. If your noise band is 0.5°C, the set point needs to be set to at least +0.3°C over the ambient temperature measured by the sensor to trigger the autotuner.
Then the autotuner should start enabling and disabling the heater to measure the oscillation of the temperature around the new set point, both in time constant and amplitude, and then compute and report the new PID gains in log.

1 Like

Not easy to set up


An idea would be to give some examples of configuration according to rooms and convectors type ? (or am I saying something wrong?)

I took the basic settings (example) and I put a standard thermostat (with a fake switch) in parallel to observe

image

@Canaletto who’s who ? There is no legend on which one is the PID or the generic thermostat.
The best is to look at the history chart of the Smart Thermostat entity in the entity card.

In the history tab you’ll find the chart with the set point, the temperature measurement and the state of the heater (orange bars below the temperature).

You may also create template sensors to monitor the PID attributes below :

{{ state_attr('climate.salle_de_bain', 'control_output') | float }}
{{ state_attr('climate.salle_de_bain', 'pid_p') | float }}
{{ state_attr('climate.salle_de_bain', 'pid_i') | float }}
{{ state_attr('climate.salle_de_bain', 'pid_d') | float }}

With this you can see what are the outputs of the PID Vs time, it greatly helped me to adjust the gains.

2 Likes

it is obvious that the PID is the one that says on/off. This is also visible on the history of the thermostat. But here I did it on the sx of both thermostats, the PID and the normal one with the same settings.

PS : as tu créé un sujet sur un fil en Français ? (HACF ou LU)

OK, but it looks like for both thermostats, the temperature never reach the set point.
On the PID the PWM is increasing slowly, surely due to integral part that is cumulative.
You need to look at the control_output and pid_* attributes to see the values, if error is big, the output should be 100% with large pid_p value, and when the temperature curve is steep the pid_d should be largely negative to override the pid_p. The integral should only compensate residual error.

Taking into account the outside temperature, even the wind or the temperature felt in case of wind would be interesting? (I think of poorly insulated houses).

Just want to say thank you !

Works well in my case, I just need to adjust a bit the integral part but I will not using it to control plastic injection, just to heat my towel, it’s 100% better than the shitty hysteresis control of the generic_thermostat :wink:

1 Like

It could bring an additional level of anticipation, by changing the gains depending on the weather, for example. But this would be really complex to manage.

I have a Netatmo thermostat to control my boiler, it uses a PID too, and probably the external temperature grabbed from internet. But to get the best efficiency, I configured my boiler (a model with condensation system) to regulate the water output temperature based on external temperature (with a sensor plugged directly on the dedicated input of the boiler, water temperature increases when external temperature decreases). I just had to adjust a bit the gain an offset of the boiler control rule to match my house insulation.

Coupled to the PID of the Netatmo, the temperature of the living room on the first floor is perfectly regulated (±0.1°C max) except on sunny days when heat is coming from the sunlights through the large windows.

But it already exists on this system. How to build it and add it to the smart thermostat ? It would require an additional loop with its own PID to modulate the thermostat PID output
 For sure it would be a hard work, for probably low benefits.

I would rather consider this Smart Thermostat as a (low cost) room temperature regulation for people already having home automation equipment to improve systems with poor regulation performance. As example, I’m using this thermostat to regulate my bathroom temperature.
My towel dryer was already equipped with a Qubino flush pilot wire dimmer, and I have a Zwave temperature sensor in the room. The towel dryer thermostat being basic with the pilot wire :

  • Level 5: Comfort mode. Regulates the temperature based on the potentiometer (inaccurate there is no temperature indication).
  • Level 4: Comfort temperature -1°C.
  • Level 3: Comfort temperature -2°C.
  • Level 2: Eco mode. Regulates at Comfort temperature -4°C.
  • Level 1: Frost protect. Regulates at 7°C.
  • Level 0: Off.

But 1 step of the towel dryer thermostat does not change the set point by 1°C. So the comfort temperature was either too hot or too cold (I’m also suspecting my daughter damaged the potentiometer by playing with it).

With the PID thermostat the pilot wire is switched from frost protection to comfort (with the towel dryer thermostat being on the max setting) and the regulation is much better.

To have an even better regulation, for example for the central heater system of a house, I would definitely prefer buying a dedicated solution like Netatmo or Tado°, it’s not so expensive compared to sensor’s and relays (160€ for the Netatmo without special offers, Vs 100€ for my Zwave sensor+dimmer) and it’s really efficient.

@benlbrm I would say increase a little bit the Kp and Ki.

I understand. I have 8 convectors of good quality but without pilot wire. So sensors and switches


For the outside temperature it was just an intérogation in front of the reading of this thread or they seem to say that it is important:

@Canaletto did you have a look on this component ? GitHub - vindaalex/multizone-thermostat

It has PID Thermostat, weather compensation.

Multizone thermostat uses either PID (called proportional mode) or external temperature (called linear mode). Not both at the same time.

Hi Adrien, you can set both control modes in any combination (weather compensation + PID or PD or PI etc). I use it for my main valve control.

OK thanks, i I thought it was an “or” selection.
I will have a look at it, but isn’t the external temperature part disturbing the integral part of the PID ? They both tend to compensate residual error, isn’t it ?