ScratMan / HASmartThermostat

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

On/Off adjustment duration causes heater not switching on #56

Closed bamnoru closed 2 years ago

bamnoru commented 2 years ago

Hi @ScratMan

I'm testing your v2021.12.5-beta3 version. When the min_cycle_duration is greater than time_on duration, time_off duration is extended. set_control_value starts waiting for time_off duration before switching on heaters, but, heater never switch on.

image

I think there's a bug line #949:

                if self._active:
                    _LOGGER.info("Request turning off %s", self._heater_entity_id)
                    await self._async_heater_turn_off()
                    self._time_changed = time.time()

self._time_changed is set to current time on every keep_alive cycle, when the thermostat is "_active" (and, _active is set to true when the thermostat received the fisrt temperature sensor value.

I think you should turn off heaters only when the heaters are on, by testing self._is_device_active instead if self._active:

                if self._is_device_active:
                    _LOGGER.info("Request turning off %s", self._heater_entity_id)
                    await self._async_heater_turn_off()
                    self._time_changed = time.time() 

You can also see in logs that the request to turn off heaters is called on every keep_alive cycle

2021-12-21 08:45:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Reject request turning off switch.chauffage_entree: Cycle is too short 2021-12-21 08:45:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 742 sec 2021-12-21 08:45:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.chauffage_entree 2021-12-21 08:45:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.chauffage_entree 2021-12-21 08:46:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 712 sec 2021-12-21 08:46:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.chauffage_entree 2021-12-21 08:46:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Reject request turning off switch.chauffage_entree: Cycle is too short 2021-12-21 08:46:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 682 sec 2021-12-21 08:46:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.chauffage_entree 2021-12-21 08:46:39 INFO (MainThread) [custom_components.smart_thermostat.climate] Reject request turning off switch.chauffage_entree: Cycle is too short 2021-12-21 08:47:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Time until input_boolean.chauffage_sol turns on: 652 sec 2021-12-21 08:47:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Request turning off switch.chauffage_entree 2021-12-21 08:47:09 INFO (MainThread) [custom_components.smart_thermostat.climate] Turning off switch.chauffage_entree

Regards,

ScratMan commented 2 years ago

Thanks for testing. It's true that the switching off should take the state of the heater entity and not the state of the thermostat. But I don't understand how your issue can occur, as the self._control_output value should be positive, even during the keep_alive calls the test at line 946 should be true, so it should not go to line 949. 🤔

bamnoru commented 2 years ago

Hi,

When control_output is positive, with a small value, the time off is adjusted, and is greater than sampling_period. On next calculation, if control_output return to 0, the heating duration was not finished (and, the heater does'nt yet switch on), but, time_changed is set to now (and time_passed is also setted 0), and, the condition to switch on will never occured.

ScratMan commented 2 years ago

OK, understood. I pushed the fix.

ScratMan commented 2 years ago

v2021.12.5-beta4 release available, may you give it a try and feedback ?

bamnoru commented 2 years ago

Hi @ScratMan It's seems better.

You can see that time_off duration is adjusted when time_on duration is lower than min_cycle_duration: image

Need to wait more, until the control_output go back to 0.

bamnoru commented 2 years ago

Works fine. Thanks