Skip to content

Commit

Permalink
Change algo to take slop into account
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Oct 31, 2024
1 parent 38c4b06 commit 461db8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ def calculate_action(

self._last_calculation_date = now

temp_at_dt = current_temp + slope_min * self._dt

# Check to turn-off
# When we hit the threshold, that mean we can turn off
if hvac_mode == HVACMode.HEAT:
if self._accumulated_error <= -self._error_threshold and slope_min >= 0:
if (
self._accumulated_error <= -self._error_threshold
and temp_at_dt >= target_temp
):
_LOGGER.info(
"%s - We need to stop, there is no need for heating for a long time.",
self,
Expand All @@ -158,7 +163,10 @@ def calculate_action(
return AUTO_START_STOP_ACTION_NOTHING

if hvac_mode == HVACMode.COOL:
if self._accumulated_error >= self._error_threshold and slope_min <= 0:
if (
self._accumulated_error >= self._error_threshold
and temp_at_dt <= target_temp
):
_LOGGER.info(
"%s - We need to stop, there is no need for cooling for a long time.",
self,
Expand All @@ -173,7 +181,7 @@ def calculate_action(

# check to turn on
if hvac_mode == HVACMode.OFF and saved_hvac_mode == HVACMode.HEAT:
if current_temp + slope_min * self._dt <= target_temp:
if temp_at_dt <= target_temp:
_LOGGER.info(
"%s - We need to start, because it will be time to heat",
self,
Expand All @@ -187,7 +195,7 @@ def calculate_action(
return AUTO_START_STOP_ACTION_NOTHING

if hvac_mode == HVACMode.OFF and saved_hvac_mode == HVACMode.COOL:
if current_temp + slope_min * self._dt >= target_temp:
if temp_at_dt >= target_temp:
_LOGGER.info(
"%s - We need to start, because it will be time to cool",
self,
Expand Down
1 change: 0 additions & 1 deletion custom_components/versatile_thermostat/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from homeassistant.components.switch import SwitchEntity

from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ async def async_control_heating(self, force=False, _=None) -> bool:
def set_auto_start_stop_enable(self, is_enabled: bool):
"""Enable/Disable the auto-start/stop feature"""
self._is_auto_start_stop_enabled = is_enabled
self.update_custom_attributes()

@property
def auto_regulation_mode(self) -> str | None:
Expand Down

0 comments on commit 461db8d

Please sign in to comment.