Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/heating power valve pos #1581

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
weight in the target temperature, higher temperatures higher impact t…
…han lower temperatures
wtom committed Jan 24, 2025
commit e10aff1675fbf132d5fb4489991e96bd0cbc95b4
37 changes: 33 additions & 4 deletions custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
@@ -967,6 +967,11 @@ async def startup(self):
break

async def calculate_heating_power(self):
if not hasattr(self, 'min_target_temp'):
self.min_target_temp = self.bt_target_temp or 18.0
if not hasattr(self, 'max_target_temp'):
self.max_target_temp = self.bt_target_temp or 21.0

if (
self.heating_start_temp is not None
and self.heating_end_temp is not None
@@ -979,29 +984,52 @@ async def calculate_heating_power(self):
1,
)
if _time_diff_minutes > 1:
temp_range = max(self.max_target_temp - self.min_target_temp, 0.1)
weight_factor = max(
0.5,
min(
1.5,
0.5 + (self.bt_target_temp - self.min_target_temp) / temp_range,
),
)

_degrees_time = round(_temp_diff / _time_diff_minutes, 4)
self.heating_power = round(
(self.heating_power * 0.9 + _degrees_time * 0.1), 4
(self.heating_power * (1 - 0.1 * weight_factor) +
_degrees_time * 0.1 * weight_factor), 4
)

if len(self.last_heating_power_stats) >= 10:
self.last_heating_power_stats = self.last_heating_power_stats[
len(self.last_heating_power_stats) - 9 :
len(self.last_heating_power_stats) - 9:
]
self.last_heating_power_stats.append(
{
"temp_diff": round(_temp_diff, 1),
"time": _time_diff_minutes,
"degrees_time": round(_degrees_time, 4),
"weight_factor": weight_factor,
"heating_power": round(self.heating_power, 4),
}
)

_LOGGER.debug(
f"better_thermostat {self.device_name}: calculate_heating_power / temp_diff: {round(_temp_diff, 1)} - time: {_time_diff_minutes} - degrees_time: {round(_degrees_time, 4)} - heating_power: {round(self.heating_power, 4)} - heating_power_stats: {self.last_heating_power_stats}"
f"better_thermostat {self.device_name}: calculate_heating_power / "
f"temp_diff: {round(_temp_diff, 1)} - time: {_time_diff_minutes} - "
f"degrees_time: {
round(_degrees_time, 4)} - weight_factor: {weight_factor} - "
f"heating_power: {round(self.heating_power, 4)} - "
f"heating_power_stats: {self.last_heating_power_stats}"
)

# reset for the next heating start
self.heating_start_temp = None
self.heating_end_temp = None

if self.heating_end_temp:
self.min_target_temp = min(self.min_target_temp, self.bt_target_temp)
self.max_target_temp = max(self.max_target_temp, self.bt_target_temp)

# heating starts
if (
self.attr_hvac_action == HVACAction.HEATING
@@ -1251,7 +1279,8 @@ async def async_set_temperature(self, **kwargs) -> None:

if _new_setpoint is None and _new_setpointlow is None:
_LOGGER.debug(
f"better_thermostat {self.device_name}: received a new setpoint from HA, but temperature attribute was not set, ignoring"
f"better_thermostat {
self.device_name}: received a new setpoint from HA, but temperature attribute was not set, ignoring"
)
return