Skip to content

Commit

Permalink
add tempsensor for water temp
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Nov 30, 2023
1 parent 1874a73 commit c678cf9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions custom_components/peaqhvac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TRENDSENSOR_INDOORS = "Temperature trend indoors"
TRENDSENSOR_OUTDOORS = "Temperature trend outdoors"
TRENDSENSOR_DM = "Degree Minutes trend"
TRENDSENSOR_WATERTEMP = "Water temperature trend"

AVERAGESENSOR_INDOORS = "Average temperature indoors"
AVERAGESENSOR_OUTDOORS = "Average temperature outdoors"
Expand Down
13 changes: 10 additions & 3 deletions custom_components/peaqhvac/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.core import HomeAssistant

from .const import AVERAGESENSORS, DEMANDSENSORS, DOMAIN, NEXT_WATER_START, LATEST_WATER_BOOST, \
TRENDSENSOR_DM, TRENDSENSOR_OUTDOORS, TRENDSENSOR_INDOORS
TRENDSENSOR_DM, TRENDSENSOR_OUTDOORS, TRENDSENSOR_INDOORS, TRENDSENSOR_WATERTEMP
from .sensors.min_maxsensor import AverageSensor
from .sensors.money_data_sensor import PeaqMoneyDataSensor
from .sensors.offsetsensor import OffsetSensor
Expand All @@ -30,8 +30,6 @@ async def async_setup_entry(
async_add_entities(peaqsensors, update_before_add=True)




async def _gather_sensors(hub, config, hass) -> list:
TRENDSENSORS = [
{
Expand All @@ -54,6 +52,15 @@ async def _gather_sensors(hub, config, hass) -> list:
"extra_attributes": {
"time_at_zero": (hub.sensors.dm_trend.predicted_time_at_value, 0)
}
},
{
"name": TRENDSENSOR_WATERTEMP,
"sensor": hub.hvac.water_heater.temp_trend,
"icon": "mdi:thermometer-water",
"unit": "°C/h",
"extra_attributes": {
"time_at_40": (hub.hvac.water_heater.temp_trend.predicted_time_at_value, 40)
}
}
]

Expand Down
3 changes: 0 additions & 3 deletions custom_components/peaqhvac/sensors/peaqsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def __init__(self, hub, entry_id, name: str, icon: str = "mdi:thermometer"):
self._state = ""

if self._sensorname == WATERDEMAND:
self._watertemp_trend = 0
self._current_water_temperature = 0
self._heat_water = False
self._water_is_heating = False
Expand All @@ -29,7 +28,6 @@ def extra_state_attributes(self) -> dict:
attr_dict = {}

if self._sensorname == WATERDEMAND:
attr_dict["watertemp_trend °/h"] = self._watertemp_trend
attr_dict["current_temperature"] = self._current_water_temperature
attr_dict["heat_water"] = self._heat_water
attr_dict["water_is_heating"] = self._water_is_heating
Expand All @@ -44,7 +42,6 @@ async def async_update(self) -> None:
self._state = self._hub.hvac.house_heater.demand.value
elif self._sensorname == WATERDEMAND:
self._state = self._hub.hvac.water_heater.demand.value
self._watertemp_trend = self._hub.hvac.water_heater.temperature_trend
self._current_water_temperature = self._hub.hvac.hvac_watertemp
self._heat_water = self._hub.hvac.water_heater.model.water_boost.value
self._water_is_heating = self._hub.hvac.water_heater.water_heating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __init__(self, hvac, hub):
self._current_temp = None
self._wait_timer = WaitTimer(timeout=WAITTIMER_TIMEOUT, init_now=False)
self._wait_timer_peak = WaitTimer(timeout=WAITTIMER_TIMEOUT, init_now=False)
self._temp_trend = Gradient(
max_age=3600, max_samples=10, precision=1, ignore=0, outlier=20
self.temp_trend = Gradient(
max_age=3600, max_samples=50, precision=1, ignore=0, outlier=20
)
self.model = WaterBoosterModel(self._hub.state_machine)
self.booster = NextWaterBoost()
Expand All @@ -50,7 +50,7 @@ def is_initialized(self) -> bool:
@property
def temperature_trend(self) -> float:
"""returns the current temp_trend in C/hour"""
return self._temp_trend.trend
return self.temp_trend.trend

@property
def latest_boost_call(self) -> str:
Expand All @@ -73,7 +73,7 @@ def current_temperature(self) -> float:
@current_temperature.setter
def current_temperature(self, val):
try:
self._temp_trend.add_reading(val=float(val), t=time.time())
self.temp_trend.add_reading(val=float(val), t=time.time())
if self._current_temp != float(val):
self._current_temp = float(val)
old_demand = self.demand.value
Expand Down Expand Up @@ -122,7 +122,7 @@ def _get_next_start(self, target_temp: int) -> tuple[datetime, int|None]:
min_price=self._hub.sensors.peaqev_facade.min_price,
preset=preset,
temp=self.current_temperature,
temp_trend=self._temp_trend.gradient_raw,
temp_trend=self.temp_trend.gradient_raw,
target_temp=target_temp,
non_hours=self._hub.options.heating_options.non_hours_water_boost,
high_demand_hours=self._hub.options.heating_options.demand_hours_water_boost,
Expand Down

0 comments on commit c678cf9

Please sign in to comment.