Closed bamnoru closed 2 years ago
Hi, please give a try to release v2021.11.2-beta2
Hi @ScratMan ,
With this version (beta2), PID is not calculated on every keep_alive period, good, But, PID is still calculated on every temperature change, and only in this case.
My parameters
climate:
- platform: smart_thermostat
name: En Bas
unique_id: en_bas
heater: input_boolean.chauffage_sol
target_sensor: sensor.sonde_salon_temperature
min_temp: 15
max_temp: 25
ac_mode: false
target_temp: 21
eco_temp: 20
comfort_temp: 21
keep_alive: 60
sampling_period: 300
pwm: 900
min_cycle_duration: 0
min_off_cycle_duration: 0
kp : 250
ki : 0.5
kd : 50000
Logs
2021-12-07 18:08:50 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638896930.6943707 (before 1638896399.6975956): 21.1 (before 21.2) 2021-12-07 18:08:50 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 13.55 (error = -0.10, dt = 531.00, p=-25.00, i=31.01, d=7.53) 2021-12-07 18:08:50 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 234 sec 2021-12-07 18:09:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 178 sec 2021-12-07 18:10:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 118 sec 2021-12-07 18:11:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 58 sec 2021-12-07 18:12:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning on input_boolean.chauffage_sol 2021-12-07 18:12:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning on input_boolean.chauffage_sol 2021-12-07 18:13:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 61 sec 2021-12-07 18:14:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 1 sec 2021-12-07 18:15:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-07 18:15:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol 2021-12-07 18:16:46 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 718 sec 2021-12-07 18:17:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 658 sec 2021-12-07 18:18:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 598 sec 2021-12-07 18:19:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 538 sec 2021-12-07 18:20:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 478 sec 2021-12-07 18:21:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 418 sec 2021-12-07 18:22:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 358 sec 2021-12-07 18:23:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 298 sec 2021-12-07 18:24:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 238 sec 2021-12-07 18:25:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 178 sec 2021-12-07 18:26:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 118 sec 2021-12-07 18:27:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 58 sec 2021-12-07 18:28:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning on input_boolean.chauffage_sol 2021-12-07 18:28:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning on input_boolean.chauffage_sol 2021-12-07 18:29:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 61 sec 2021-12-07 18:30:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 1 sec 2021-12-07 18:31:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-07 18:31:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol 2021-12-07 18:32:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 718 sec 2021-12-07 18:33:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 658 sec 2021-12-07 18:34:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 598 sec 2021-12-07 18:35:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 538 sec 2021-12-07 18:36:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 478 sec 2021-12-07 18:37:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 418 sec 2021-12-07 18:38:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 358 sec 2021-12-07 18:39:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 298 sec 2021-12-07 18:40:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 238 sec 2021-12-07 18:41:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 178 sec 2021-12-07 18:42:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 118 sec 2021-12-07 18:43:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 58 sec 2021-12-07 18:44:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning on input_boolean.chauffage_sol 2021-12-07 18:44:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning on input_boolean.chauffage_sol 2021-12-07 18:45:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 61 sec 2021-12-07 18:46:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 1 sec 2021-12-07 18:47:11 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638899231.7284083 (before 1638896930.6943707): 21.2 (before 21.1) 2021-12-07 18:47:11 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = -0.20, dt = 2301.04, p=-50.00, i=0.00, d=-1.74)
PID is still calculated on every temperature change, and only in this case.
This is normal, the PID is calculated as soon as a new temperature value is available, except if the sampling_period is set and not elapsed since last temperature received. It seems your temperature sensor didn't send updates for 40 minutes, that's quite long.
Hi, So, sampling_period is used only to slow down temperature refresh, not to increase calculation. If the temperature doesn't change for a long period (and is above the consign), PID should be calculated to increase the I value.
Maybe you should restore the previous version with
if calc_pid or self._sampling_period != 0:
and check why the calculation is done on every keep_alive period, even if the sampling_period is not reach.
Thanks for your job !
The keep alive is there to check the health and refresh the state of the full system, and yes the sampling period can only limit the sampling rate, not increase it. Why integral doesn't integrate between samples ? because we don't know how the temperature changed. We need two samples to integrate to perform the error and dt calculation, we can't integrate or derive without receiving a new sample.
That's why we need temperature samples to be as regular and smooth as possible. Sampling rate of 30 seconds with constant +/- 0.1°C changes will disturb the derivative component, so we use the sampling_period to limit the sampling to 1 sample every few minutes.
For integral, we can't guess the samples that doesn't exist ; that's why I recommend to use thermal sensors with a sampling rate from 5 to 15 minutes, and that reports the temperature even if it didn't change.
For example, on my system I'm using a Popp Mold detector which is Z-Wave battery powered thermal and humidity sensor on which we can configure an automatic sampling and reporting and the minimum temperature change to report. I set it to send a report every 15 minutes (the minimum), even if the temperature didn't change, and the minimum temperature change is set to 0.1°C (the minimum too). It gives me really nice curves that are working really nice with the PID, even with the fast transient that can occur in my bathroom with heating boost or when taking a shower :
Hi, I use zigbee sensors, and, refresh is sent by the sensor only on change (and, I can't configure refresh rate). I've also some 433Mhz sensors (Oregon and cheap chinese sensors), refresh is sent by the sensor frequently, but HA doesn't trigger changes if the value doesn't not changed. With the previous version, PID is calculated too frequently (on my system), and with this beta, really too slowly. I'm trying to manage a floor heating, with a high inertia.
That's one of the biggest issues: sensors that doesn't wake up and refresh regularly...
I tried to make something in a new release, please try with v2021.12.2-beta4 with adding force_pid_refresh: 00:10:00
for example to your YAML. It will force refreshing the PID values at regular time interval. You may end up with some samples from the sensor falling in between two PID refresh, making the derivative part wind-up, maybe you should set the sampling_period
to 5 minutes too in order to limit this phenomenon.
Hi, I gave it a try to
sampling_period: seconds: 180
with the aim to slow down sensor update rate (regular 32 seconds) but keep an eye open on the log (debug level) show an unsuccessful result, update rate between PID calculation is still 32 seconds.
But does the output change ? or is thereany change in p, i and D ? Any sensor update will force calling the PID, and this will be logged, but PID should reject the sample if delay is shorter than sampling period, and the output should remain unchanged.
Hi Adrien, it happens, please take a look at these consecutives logs..
2021-12-08 08:37:14 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638949034.8819177 (before 1638949002.245477): 20.95 (before 20.96)
2021-12-08 08:37:14 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 36.15 (error = 0.04, dt = 32.57, p=3.28, i=32.87, d=-0.00)
2021-12-08 08:37:14 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until switch.tz3000_zmy1waw6_ts011f_a1523afe_on_off turns on: 2167 sec
2021-12-08 08:37:47 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638949067.6161706 (before 1638949034.8819177): 20.95 (before 20.95)
2021-12-08 08:37:47 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 36.15 (error = 0.04, dt = 32.57, p=3.28, i=32.87, d=-0.00)
2021-12-08 08:37:47 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until switch.tz3000_zmy1waw6_ts011f_a1523afe_on_off turns on: 2135 sec
no changes in co / error / ... but still logged PID co calculations
OK, so it works as expected, call to the PID is logged, but no update in the PID outputs. I agree I should log separately when PID accepts or rejects to compute the outputs.
I do some modifications locally:
You can see in the log that new calculations are done before the sampling_period. And, there some log lines even if no new value are done (and, it's confusing) I suspect an error in pid_controller, near line #103
if self.sampling_period != 0 and self._last_input_time is not None and \
time() - self._last_input_time < self.sampling_period:
return self.output # If last sample is too young, keep last output value
First log
2021-12-07 23:49:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = -0.10, dt = 240.01, p=-25.00, i=0.00, d=-0.00)
New calculation
2021-12-07 23:49:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-07 23:49:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol 2021-12-07 23:50:03 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1638917403.8995237 (before 1638916754.9035714): 21.0 (before 21.1)
No refresh
2021-12-07 23:50:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 66.66 (error = 0.00, dt = 60.00, p=0.00, i=0.00, d=66.66) New early calculation, Need to turn on (wait 240s)
2021-12-07 23:50:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 240 sec 2021-12-07 23:51:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 66.66 (error = 0.00, dt = 60.00, p=0.00, i=0.00, d=66.66)
This log is probably not a new calculation
2021-12-07 23:51:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 180 sec 2021-12-07 23:52:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 66.66 (error = 0.00, dt = 60.00, p=0.00, i=0.00, d=66.66)
This log is probably not a new calculation
2021-12-07 23:52:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 120 sec 2021-12-07 23:53:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 66.66 (error = 0.00, dt = 60.00, p=0.00, i=0.00, d=66.66)
This log is probably not a new calculation
2021-12-07 23:53:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 60 sec 2021-12-07 23:54:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = 0.00, dt = 240.01, p=0.00, i=0.00, d=-0.00)
New calculation As my sampling_period is smaller than pwm, the heater was not turn on... I will do some tests with a sampling_period equals to pwm to avoid this issue
2021-12-07 23:54:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-07 23:54:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol
Second Log
2021-12-08 00:13:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = 0.00, dt = 120.00, p=0.00, i=0.00, d=-0.00) 2021-12-08 00:13:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-08 00:13:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol 2021-12-08 00:14:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 47.22 (error = 0.10, dt = 180.00, p=25.00, i=0.00, d=22.22)
New calculation Wait 415s before turning on
2021-12-08 00:14:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 415 sec 2021-12-08 00:15:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 47.22 (error = 0.10, dt = 180.00, p=25.00, i=0.00, d=22.22)
This log is probably not a new calculation
2021-12-08 00:15:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 355 sec 2021-12-08 00:16:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 29.20 (error = 0.10, dt = 120.00, p=25.00, i=4.20, d=-0.00)
New calculation from previous 00:14:17, dt = 120 secondes Change delay to turn on
2021-12-08 00:16:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 457 sec 2021-12-08 00:17:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 29.20 (error = 0.10, dt = 120.00, p=25.00, i=4.20, d=-0.00)
This log is probably not a new calculation
2021-12-08 00:17:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 397 sec 2021-12-08 00:18:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 29.20 (error = 0.10, dt = 120.00, p=25.00, i=4.20, d=-0.00)
This log is probably not a new calculation
2021-12-08 00:18:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 337 sec 2021-12-08 00:19:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 35.50 (error = 0.10, dt = 180.00, p=25.00, i=10.50, d=-0.00)
New calculation from previous 00:16:17, dt = 180 secondes Change delay to turn on
2021-12-08 00:19:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 220 sec 2021-12-08 00:20:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 35.50 (error = 0.10, dt = 180.00, p=25.00, i=10.50, d=-0.00)
This log is probably not a new calculation
2021-12-08 00:20:17 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 160 sec 2021-12-08 00:21:17 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 39.70 (error = 0.10, dt = 120.00, p=25.00, i=14.70, d=-0.00)
New calculation from previous 00:19:17, dt = 120 secondes
I've found the bug in pid_controller, line #103 :
Replace
if self.sampling_period != 0 and self._last_input_time is not None and \
time() - self._last_input_time < self.sampling_period:
return self.output # If last sample is too young, keep last output value
By
if self.sampling_period != 0 and self._last_input_time is not None and \
time() - self._input_time < self.sampling_period:
return self.output # If last sample is too young, keep last output value
And revert your change in climate.py to :
if calc_pid or self._sampling_period != 0:
Hi @bamnoru, @ScratMan, after your suggested modifications, I got a consistence log:
2021-12-09 01:06:00 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Received new temperature sensor input at timestamp 1639008360.8170195 (before 1639008328.1838965): 20.71 (before 20.71)
2021-12-09 01:06:00 DEBUG (MainThread) [custom_components.smart_thermostat.climate] Obtained current control output. 0.00 (error = -0.71, dt = 195.77, p=-58.22, i=26.47, d=0.82)
2021-12-09 01:06:00 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.tz3000_zmy1waw6_ts011f_a1523afe_on_off
2021-12-09 01:06:00 INFO (MainThread) [custom_components.smart_thermostat.climate] Reject request turning off switch.tz3000_zmy1waw6_ts011f_a1523afe_on_off: Cycle is too short
Sampling period in the log is now dt=195 in front of a "sampling_period: 180" in yaml stable and ripetitive, and the good news is that "d" part is preserved within the period.
Hi @Stefano0042 Maybe, if you want to have a dt value closer to your sampling_period, you should adjust your parameters : sampling_period should be a multiple of keep_alive.
Hi @bamnoru yes, but in fact is a multiple of the sensor interval itself 32.5sec (32.5 x 6) so 195 will be a good sampling_period: :) :).
Please try v2021.12.2-beta8
I removed the force_pid_refresh
parameter as suggest by @bamnoru here. It could lead to PID computation issue, and the results could be the same with useage of keep_alive
timer combined with sampling_period
now that the PID correctly rejects samples when they are too close each others.
@ScratMan Perfect ! Works fine for me.
Thanks for your help on debugging this.
Describe the bug PID calculation is performed based on sampling_period, but also on keep_alive period. Maybe it's the normal behavior, but, from my point of view, not.
Parameters sampling_period: 300 keep_alice: 60
LOG
PID calculation base on sampling period (strange, dt = 240, but difference from previous calculation time should be 300) Control_output is now set to 33,70
New calculation of control_output, set now to 17,04 Time to turn on is recalculated
Other log, output changes every minutes :