ScratMan / HASmartThermostat

Smart Thermostat with PID controller for HomeAssistant
338 stars 49 forks source link

Integral part of the PID controller accumulates gain for error during the period the thermostat was in OFF state #38

Closed jandado closed 2 years ago

jandado commented 2 years ago

Describe the bug I have three floor heating circuits regulated by the Smart Thermostat. I am forced to shut them down during peak hours. When the thermostat is turned back ON (usually after 1 hour) the temperature drop is accumulated into the integral part for the whole duration it was OFF. See attached recent chart of the pid_i attribute of one of the thermostats. The flat lines are during the OFF periods, the immediate jumps are right after it is turned back on. I have highlighted the parts I am referring to.

To Reproduce Steps to reproduce the behavior:

  1. turn thermostat OFF,
  2. wait for the temperature to drop by one or a couple of degrees over a "significant" period (from the controller perspective, i.e. an hour),
  3. turn back ON - the next pid_i update will jump by the overall accumulated error, including the off period.

Expected behavior The integral part of the thermostat should not account for the time it has spent in the OFF state and keep the value unchanged until there is an update (temperature change / sampling period). It was obviously not missing the target temperature furing OFF period, because it could not act to achieve it.

*Screenshots pid_i *

ScratMan commented 2 years ago

Hi, it didn't integrate, the PID is not called nor refreshed while thermostat is off. But when you switch it back on, the last sample might be several hours or days old, so dt will become huge, and then the PID will multiply it by the new temperature error. I'll need to fix that.

jandado commented 2 years ago

Hi, it didn't integrate, the PID is not called nor refreshed while thermostat is off. But when you switch it back on, the last sample might be several hours or days old, so dt will become huge, and then the PID will multiply it by the new temperature error. I'll need to fix that.

Hi @ScratMan - yes, that is what I was trying to say :) It causes wild over-shoots (even with no-overshoot autotuned parameters) and oscillations that take long time to settle. Thank you!

ScratMan commented 2 years ago

Hello @jandado , please try this beta release https://github.com/ScratMan/HASmartThermostat/releases/tag/2021.12.2-beta1

jandado commented 2 years ago

I have just updated, @ScratMan - I will let you know how it goes.

jandado commented 2 years ago

Hello @ScratMan. It behaves much better now - see attached screenshot. There is one jump in the evening before the 2021.12.2-beta1, the black circle is cause by me calling smart_thermostat.clear_integral to have a fresh start. All the way on the right is todays behavior after one hour in off state. I made sure the temperature dropped by reasonably significant margin. The integral picks up where it should as it was turned back on.

Thank you! pid_i_2021 12 2-beta1

ScratMan commented 2 years ago

Fix merged in v2021.12.2