ScratMan / HASmartThermostat

Smart Thermostat with PID controller for HomeAssistant
336 stars 48 forks source link

Integral spike after thermostat being disabled for a while #185

Closed jasperweiss closed 7 months ago

jasperweiss commented 7 months ago

I noticed my temperature overshooting the setpoint significantly sometimes. I made a graph using Apex charts to visualise the PID values and noticed the integral value shoots up once the thermostat is enabled after being disabled for a while. My issue seems similar to #38 but that should have been fixed (I'm running 2023.10.0)

See the this graph screenshot 2023-11-20 215004 Note that the setpoint (not shown) is 19.5. The thermostat is disabled rather than lowering the setpoint when I'm not present (is that the intended way to use it or should I lower the setpoint instead?) Notice that just before 17:00 the thermostat is enabled and the integral (red line) shoots up. The temperature difference is quite substantial at this point but the time delta should essentially be zero since the thermostat has only just been enabled. The pid_dt value is reset upon enabling the thermostat right? I'd expect the integral to only consider time deltas during which the PID is enabled so I'm not sure why it's skyrocketing like that.

Expected behavior Integral should start accumulating incrementally from the moment the thermostat is enabled and PID output is not 0, rather than considering the time during which it was off (not sure if that's what's happening?).

This is the config

hvac_modes:
  - heat
  - "off"
min_temp: 10
max_temp: 25
current_temperature: 19.9
temperature: 19.5
control_output: 13.8
kp: 20
ki: 0.01
kd: 0
ke: 0.2
pid_mode: auto
pid_i: 18.3
pid_p: -7
pid_d: -0.0
pid_e: 2.6
pid_dt: 0.2234346866607666
jasperweiss commented 7 months ago

Seems like there's 2 temperature measurements after turning on. The temperature difference is still big enough to create a huge spike on the integral even for a low time delta. I lowered the pid_i with factor 10 and it doesn't to spike anymore. Since the integral value is saved and usually doesn't need to change much unless conditions have changed significantly, it's perfectly fine for it to take a little longer to settle. pid_e already accounts for some of the variations in outside temperature.