Skip to content

Commit b235d9b

Browse files
committed
[TASK] fix avg outdoor temp sensor
1 parent 60b81db commit b235d9b

File tree

9 files changed

+78
-24
lines changed

9 files changed

+78
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.jekyll-cache/
2+
_site/

_config.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
remote_theme: just-the-docs/just-the-docs
2+
theme: just-the-docs
23

34

45
# Welcome to Jekyll!
@@ -20,10 +21,12 @@ title: Better Thermostat
2021
description: Documentation for Better Thermostat
2122
baseurl: "/" # the subpath of your site, e.g. /blog
2223
url: "https://bt.t-haber.de" # the base hostname & protocol for your site, e.g. http://example.com
23-
24+
logo: /assets/logo.png
2425
permalink: pretty
25-
exclude: ["node_modules/", "*.gemspec", "*.gem", "Gemfile", "Gemfile.lock", "package.json", "package-lock.json", "script/", "LICENSE.txt", "lib/", "bin/", "README.md", "Rakefile", "vendor"]
26-
26+
exclude: ["custom_components/", ".vscode", "node_modules/", "*.gemspec", "*.gem", "Gemfile", "Gemfile.lock", "package.json", "package-lock.json", "script/", "LICENSE.txt", "lib/", "bin/", "README.md", "Rakefile", "vendor"]
27+
sass:
28+
sass_dir: _sass
29+
style: compressed
2730
# Set a path/url to a logo that will be displayed instead of the title
2831
#logo: "/assets/images/just-the-docs.png"
2932

@@ -91,7 +94,7 @@ nav_external_links:
9194
back_to_top: true
9295
back_to_top_text: "Back to top"
9396

94-
footer_content: "Copyright &copy; 2017-2020 Patrick Marsceill. Distributed by an <a href=\"https://github.com/just-the-docs/just-the-docs/tree/main/LICENSE.txt\">MIT license.</a> <a href=\"https://www.netlify.com/\">This site is powered by Netlify.</a>"
97+
footer_content: "Copyright &copy; 2022 Tobias Haber. Distributed by an <a href=\"https://github.com/KartoffelToby/better_thermostat/blob/master/LICENSE\">AGPL-3.0 license.</a>"
9598

9699
# Footer last edited timestamp
97100
last_edit_timestamp: true # show or hide edit time - page must have `last_modified_date` defined in the frontmatter
@@ -103,15 +106,17 @@ last_edit_time_format: "%b %e %Y at %I:%M %p" # uses ruby's time format: https:/
103106
gh_edit_link: true # show or hide edit this page link
104107
gh_edit_link_text: "Edit this page on GitHub"
105108
gh_edit_repository: "https://github.com/KartoffelToby/better_thermostat" # the github URL for your repo
106-
gh_edit_branch: "main" # the branch that your docs is served from
107-
# gh_edit_source: docs # the source that your files originate from
109+
gh_edit_branch: "master" # the branch that your docs is served from
110+
#gh_edit_source: docs # the source that your files originate from
108111
gh_edit_view_mode: "tree" # "tree" or "edit" if you want the user to jump into the editor immediately
109112

110113
# Color scheme currently only supports "dark", "light"/nil (default), or a custom scheme that you define
111114
color_scheme: dark
112115

113116
callouts_level: quiet # or loud
114117
callouts:
118+
link:
119+
color: green
115120
highlight:
116121
color: yellow
117122
important:

_sass/custom/custom.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
a, .icon {
2+
color: #4caf50;
3+
}
4+
body{
5+
background-color: #191c1e;
6+
}
7+
8+
.side-bar {
9+
background-color: #25292c;
10+
}
11+
12+
.site-header {
13+
min-height: 120px;
14+
}
15+
16+
.site-logo {
17+
max-height: 115px;
18+
max-width: 115px;
19+
margin: 0 auto;
20+
}

assets/logo.png

137 KB
Loading

custom_components/better_thermostat/climate.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from abc import ABC
66
from datetime import datetime, timedelta
77
from random import randint
8+
9+
from custom_components.better_thermostat.weather import check_ambient_air_temperature
810
from .helpers import convert_to_float
911
from homeassistant.helpers import entity_platform
1012

@@ -24,7 +26,10 @@
2426
STATE_UNKNOWN,
2527
)
2628
from homeassistant.core import callback, CoreState
27-
from homeassistant.helpers.event import async_track_state_change_event
29+
from homeassistant.helpers.event import (
30+
async_track_state_change_event,
31+
async_track_time_change,
32+
)
2833
from homeassistant.helpers.restore_state import RestoreEntity
2934

3035
from . import DOMAIN
@@ -57,7 +62,6 @@
5762

5863
from .controlling import control_queue, set_hvac_mode, set_target_temperature
5964
from .events.temperature import trigger_temperature_change
60-
from .events.time import trigger_time
6165
from .events.trv import trigger_trv_change
6266
from .events.window import trigger_window_change, window_queue
6367

@@ -230,6 +234,7 @@ def __init__(
230234
self._saved_temperature = None
231235
self._last_reported_valve_position_update_wait_lock = asyncio.Lock()
232236
self._last_send_target_temp = None
237+
self._last_avg_outdoor_temp = None
233238
self.control_queue_task = asyncio.Queue()
234239
if self.window_id is not None:
235240
self.window_queue_task = asyncio.Queue()
@@ -257,6 +262,8 @@ async def async_added_to_hass(self):
257262
self.calibration_type = 1
258263

259264
# Add listener
265+
if self.outdoor_sensor is not None:
266+
async_track_time_change(self.hass, self._trigger_time, 5, 0, 0)
260267
async_track_state_change_event(
261268
self.hass, [self.sensor_entity_id], self._trigger_temperature_change
262269
)
@@ -287,8 +294,12 @@ def _async_startup(*_):
287294
else:
288295
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
289296

290-
async def _trigger_time(self, event):
291-
await trigger_time(self, event)
297+
async def _trigger_time(self, event=None):
298+
_LOGGER.debug("better_thermostat %s: get last avg outdoor temps...", self.name)
299+
await check_ambient_air_temperature(self)
300+
if event is not None:
301+
self.async_write_ha_state()
302+
await self.control_queue_task.put(self)
292303

293304
async def _trigger_temperature_change(self, event):
294305
await trigger_temperature_change(self, event)
@@ -350,7 +361,6 @@ async def startup(self):
350361
or trv_state.attributes.get("current_heating_setpoint")
351362
or 5
352363
)
353-
self._bt_hvac_mode = trv_state.state
354364
self._trv_hvac_mode = trv_state.state
355365
self._last_reported_valve_position = (
356366
trv_state.attributes.get("valve_position", None) or None
@@ -469,6 +479,7 @@ async def startup(self):
469479
)
470480
self._bt_hvac_mode = HVAC_MODE_OFF
471481
self._last_window_state = self.window_open
482+
await self._trigger_time()
472483

473484
self.async_write_ha_state()
474485
_LOGGER.info("better_thermostat %s: startup completed.", self.name)

custom_components/better_thermostat/weather.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import logging
2+
from datetime import datetime, timedelta
3+
import homeassistant.util.dt as dt_util
4+
from homeassistant.components.recorder import get_instance, history
25

36
# from datetime import datetime, timedelta
47

@@ -33,7 +36,7 @@ def check_weather(self) -> bool:
3336
_LOGGER.debug(
3437
f"better_thermostat {self.name}: checking ambient air sensor data..."
3538
)
36-
self.call_for_heat = check_ambient_air_temperature(self)
39+
self.call_for_heat = self._last_avg_outdoor_temp < self.off_temperature
3740
else:
3841
_LOGGER.debug(
3942
f"better_thermostat {self.name}: could not find any weather sensors... setting call_for_heat to true"
@@ -94,7 +97,7 @@ def check_weather_prediction(self) -> bool:
9497
return None
9598

9699

97-
def check_ambient_air_temperature(self) -> bool:
100+
async def check_ambient_air_temperature(self):
98101
"""Gets the history for two days and evaluates the necessary for heating.
99102
100103
Returns
@@ -112,14 +115,20 @@ def check_ambient_air_temperature(self) -> bool:
112115
f"better_thermostat {self.name}: off_temperature not set or not a float."
113116
)
114117
return None
115-
""" TODO
118+
116119
last_two_days_date_time = datetime.now() - timedelta(days=2)
117120
start = dt_util.as_utc(last_two_days_date_time)
118-
history_list = state_changes_during_period(
119-
self.hass, start, dt_util.as_utc(datetime.now()), self.outdoor_sensor, no_attributes=False, descending=True, limit=100
121+
history_list = await get_instance(self.hass).async_add_executor_job(
122+
history.state_changes_during_period,
123+
self.hass,
124+
start,
125+
dt_util.as_utc(datetime.now()),
126+
str(self.outdoor_sensor),
120127
)
121128
historic_sensor_data = history_list.get(self.outdoor_sensor)
122-
_LOGGER.debug(f"better_thermostat {self.name}: historic_sensor_data: {historic_sensor_data}")
129+
_LOGGER.debug(
130+
f"better_thermostat {self.name}: historic_sensor_data: {historic_sensor_data}"
131+
)
123132
# create a list from valid data in historic_sensor_data
124133
valid_historic_sensor_data = []
125134
invalid_sensor_data_count = 0
@@ -170,8 +179,5 @@ def check_ambient_air_temperature(self) -> bool:
170179
_LOGGER.debug(
171180
f"better_thermostat {self.name}: avg outdoor temp: {avg_temp}, threshold is {self.off_temperature}"
172181
)
173-
"""
174-
avg_temp = convert_to_float(
175-
str(self.hass.states.get(self.outdoor_sensor).state), self.name, "weather()"
176-
)
177-
return avg_temp < self.off_temperature
182+
183+
self._last_avg_outdoor_temp = avg_temp

docs/setup.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
layout: default
3+
title: Add new device
4+
nav_order: 2
5+
description: "BT."
6+
permalink: /setup
7+
---
8+
9+
# soon

docs/welcome.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ description: "BT."
66
permalink: /
77
---
88

9-
# soon
9+
# Better Thermostat
10+
11+
This custom component for Home Assistant will add crucial features to your climate-controlling TRV (Thermostatic Radiator Valves) to save you the work of creating automations to make it smart. It combines a room-temperature sensor, window/door sensors, weather forecasts, or an ambient temperature probe to decide when it should call for heat and automatically calibrate your TRVs to fix the imprecise measurements taken in the radiator's vicinity.

0 commit comments

Comments
 (0)