ScratMan / HASmartThermostat

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

heating duration exceeds min_cycle_duration #57

Closed bamnoru closed 2 years ago

bamnoru commented 2 years ago

Hi,

Be careful with float values. My parameters:

The heater is on more than time_on value.

In this example, time_on is too low, and, heaters will switch on for min_cycle_duration.

2021-12-22 07:57:42 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning on input_boolean.chauffage_sol 2021-12-22 07:57:42 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning on input_boolean.chauffage_sol

Turning on at 7:57

2021-12-22 07:58:12 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 60 sec 2021-12-22 07:58:42 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 30 sec 2021-12-22 07:59:12 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns off: 0 sec

Should turn off (90 seconds after turning on), and, log says "0 sec", but, in fact, the heater will be switch off on next keep_alive cycle Total heating duration is 120 seconds

2021-12-22 07:59:42 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off input_boolean.chauffage_sol 2021-12-22 07:59:42 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off input_boolean.chauffage_sol

To have a better result, I'll change min_cycle_duration to 89 instead of 90. but, I think this issue is due to float, time_on and time_off should be cast into integer (in seconds)

ScratMan commented 2 years ago

Hello, that's not due to usage of float, but to asynchronous operation. PID is computed whenever a new temperature value is received from the thermal sensor, and then the heater is switched on or off and the time t0 is recorded ; this may occur 1 seconds after the last keep alive tick. But if the PID output doesn't change afterward, only the keep alive timer can trigger a check of the PWM and switch off or on the heater. So if the on time was 10 seconds and the heater switched 1s after the last keep alive tick, the real on time is 59s.

bamnoru commented 2 years ago

When the time_on duration is reached, heater should switch off, and not wait on next keep_alive cycle.

Maybe, to have more accuracy, change line #961 :

if time_on < time_passed or self._force_off: by

if time_on <= time_passed or self._force_off:

As I said, I've changed my parameters, and, now, it's fine for me, but, when reading the logs, it's confusing to see "time until turns off 0 sec", and request sent later.

ScratMan commented 2 years ago

Fixed in v2021.12.5