Thermostat with PID controller

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…

@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.

1 Like

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 ?

Combining both for a room thermostat is indeed tricky and could result in instability. I think it might however be useful is some specific cases. I wonder if it could be beneficial to combine both for a room with slow lagging heating systems, like low temp wood covered floor heatings? Weather mode directly compensates for a large part the heat loss and PID controller fine-tunes the last part of the temperature error. I haven’t done any testing myself, maybe that some papers can be found about it.

I don’t use this combination for the room thermostats either, only for the main valve (heat supply to the total system) and only by weather mode + proportional, no integral or derative.

That’s exactly what I was suspecting. I own two Netatmo thermostats, in On/Off mode, as the Netatmo can’t modulate the power of my boiler (it’s not an OpenTherm system) ; and I kept the external temperature sensor used with the original Expert Control modulating thermostat from Chaffoteaux. It allowed me to configure the boiler to adjust the water output temperature for the two heating circuits according to the external temperature (adjustable gain + offset linear compensation). That’s very efficient, but the boiler controls the water temperature (the “available heating power”) while the PID controls the PWM (doing the modulation).
I’m afraid if the external temperature compensates the PID output, it may lead to unpredictable results with the anti-windup of the integral part. Implementations I found using external temperature are only based on proportional regulation of the error, with no derivative nor integration.

In the mean time, I updated my code and built a beta version to put back the min_cycle_duration option and try to improve the autotuner (as it didn’t work at all).

You could have look into the multizone thermostat version of (I think about) march 2021. I scraped all mods from forks relating autotune. It also includes the option to start autotune via preset mode and saved results directly in the PID controller.

I just removed this option as I doubted the effectiveness of this tuning, especially for slow varying systems with relatively large external effects (outdoor temp, cooking, sun radiation etc)


Maybe it’s a stupid question, but do you have a simple query (sql or influx) to extract data that can be easily import in pidtuner ?

You can use something like that :

SELECT mean("current_temperature") AS "mean_current_temperature", mean("control_output") AS "mean_control_output", mean("temperature") AS "mean_temperature" FROM "home_assistant"."autogen"."state" WHERE time > :dashboardTime: AND time < :upperDashboardTime: AND "entity_id"='salle_de_bain' GROUP BY time(:interval:) FILL(null)

I generated a new beta release with services to set the PID gains, set the preset modes temperatures and clear the integral component of the PID.
These changes will ease the tuning of the PID, allowing to adjust the gains without requiring a restart.

It also adds a unique_id parameter to be able to customize the entity through UI.