Thermostat with PID controller

Last 2 days, I am getting again even bigger overshoot, with heating even when temperature is already reached
image

Hi, your pid_i is still larger than pid_p and pid_d, so it will give positive output and heat. You should increase kp so that pid_p reaches at least 75%, and increase kd by the same amount.

Means increase Kp from current 77 by how much (%)? And same percentual increase on Kd (currently 110000)?

Try with Kp: 100, and double the Kd, as the pid_d looks very low. You should also use the sampling_period to a few minutes to filter the very fast spikes on the temperature sensor.

OK, I will try with:

  kp : 100
  ki : 0.0032
  kd : 220000
  sampling_period: 00:10:00

When looking at the P, I and D curves with set point steps, the integral should be quite stable, P should have the biggest amplitude, and D should progressively cancel the P when P is decreasing.

My curves:
Please note I’m using an alpha version taking outdoor temperature as an additional input, to compute E = Ke * (set_point - outdoor_temp), and output = P + I + D + E
In the end the integral is reduced and seems more stable as the thermal losses of the building are compensated by E.

1 Like

It surprises me that that E component of yours isn’t standard stuff. It seems so obvious.

What do you mean by not standard ?

I am back, with last 2 days. I don’t know what am I doing wrong, or should I just count as the fact that it will be like that. I still get overshoot of 0,5 degree. Before, that overshoot was even larger, so what I adjusted as recommended above resulted in not heating when over set point, but overshoot is still there.
Ignore those shifts in set temp, that was just me trying things.

image

@nilux definitely not a standard. I used Danfoss heating control before, that did not know about outside temperature at all. But my heat pump knows, and adjusts leaving water temperature based on outside temperature.

1 Like

I’m using also a PID thermostat but a different one ( multizone) in combination with low temperature floor heating and can confirm it is tricky in achieving a constant temperature. At my place some sunlight or heat from making dinner can already give a 0.5 degree change.

Could you give it a try with a constant setpoint for a few days. You’re rise and drop might be amplified by the setpoint changes between 21.5 and 22.

Apparently PID usually includes P, I, and D. That’s what I mean by standard.

@axax i set it now for 22 constantly, will see. I do agree that bit of sun can easily participate in overshoot, and as I said, I am mostly concerned about heating when temp is over the set temp, and maybe not have to heat constantly for 4 hours, rather than few shorter cycles.

I think there is an issue with the derivative part, it always returns to 0 between steps as the temperature is really slow to change. The gains seems to be quite OK when looking at the amplitudes, maybe Kp is a little bit high, keeping Kd as is and reducing Kp by 10% steps may help on the overshoot but I’m afraid the integral may then become dominant and force the heating with negative error.
I think that the main issue is that you generate a very small step in the morning while the temperature is already close to the set-point.
Maybe the solution would be to return to lower Kp and Kd gain and use the new outdoor temperature compensation available in the v2021.12.5-beta versions, to have a kind of higher speed compensation that may help with small set point steps, and smaller Kp and Kd will then help for fine regulation around set points. It also embeds a system to automatically increase the PWM period when on time is lower than the minimum cycle duration, to avoid overheating ; maybe it can help you too.

Willing to give it a try. Would it be to move to beta only (for starters, i would keep kp kd ki as they are now)? Or is there some additional parameter to configure?

Install the beta, yes, stop HA, specify the outdoor_sensor entity in the configuration file with a temperature sensor, and restart HA.
Then fix the Ke gain (you can do it live in HA using the set_pid_gain service) : Ke = 10 / (22 - outside temperature during these days).
Finally, clear the integral using the clear_integral service.
The PID will then start using outdoor temperature.

OK, here is my configuration now:

  outdoor_sensor: sensor.espaltherma_outside
  min_cycle_duration: 00:20:00
  kp : 100
  ki : 0.0032
  kd : 220000
  ke: 0.588
  pwm : 02:00:00
  sampling_period: 00:10:00

Cleared the integral. This is current state:

control_output: 6.7
Kp: 77
Ki: 0.0032
Kd: 110000
Ke: 0.588
pid_mode: auto
pid_p: -15.4
pid_i: 0
pid_d: -0.0
pid_e: 0
pid_dt: 12.511824131011963

I also did return to previous 0,5degree less during nights

I see you’re still adjusting the gains using the configuration file: the gains in the state of the device are different from gains in the file.
Please note the gains in configuration file are only taken into account when:

  • Starting the thermostat for the very first time
  • In case of HA database crash or deletion

In all other cases, the gains are restored from the database, and should be adjusted using the set_pid_gain service

I did change all of them now using service too. I like to keep my yaml in line.
I also noticed that I had Ki value as 0.0032 however only 0.003 is acceptable.

While using outdoor temperature compensation you could decrease the kp and kd gains.
You should first keep the set point steady, without night/day steps, and adjust the gains to see how it behaves.

When doing set point steps, the overshoot will depend on the gains, but also on the amplitude of the step. The bigger the step, the higher the overshoot. Example :

On the smaller step, when the temperature starts to rise, the D is still too small to stop the heating due to large kp gain, and when D start to increase and cut the P, the temperature is already high Vs the step level. When the heater is switched off with set point decrease, the temperature is still increasing and overshoots by 0.5°C the requested temperature step.