-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHomeAssistant_template_weather.yaml
173 lines (171 loc) · 9.43 KB
/
HomeAssistant_template_weather.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Simple WeatherBoard
- trigger:
- platform: time_pattern
minutes: /5
variables:
# Here you can edit the increments
increment_0: "2"
increment_1: "4"
increment_2: "6"
increment_3: "8"
# Here you can edit the 3 titles: Handle it in the order of the 3 titles (WEATHER, TODAY, OUTLOOK are defaults #}
# Be sure the font in your ESPHome YAML can handle the characters! ie. "WEATHR" for font_title and "TODAYULK" for the font_small_title #}
titles: >
{%- set titles = [] %}
{%- set titles = titles + ["WEATHER"] %}
{%- set titles = titles + ["TODAY"] %}
{%- set titles = titles + ["OUTLOOK"] %}
{{titles}}
daily_0: "1"
daily_1: "2"
daily_2: "3"
daily_3: "4"
# Edit how timestamps are shown
time_format: "%I:00%p" # %H:00 = 24hrs (13:00) / %I:00%p = 12hrs + AM/PM (01:00PM)
strip_zero: "0" # 0 to strip leading zero (1:00PM), empty quotes if not
action:
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.openweathermap
response_variable: hourly
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.openweathermap
response_variable: daily
sensor:
- name: eInk WeatherBoard Data
unique_id: eink_weatherboard_data
state: "OK"
attributes:
hourly_times: "{{hourlytimes}}"
weather_now_temperature: >
{{ hourly["weather.openweathermap"].forecast[0].temperature | round }}
weather_now_condition: >
{%- set cond_now = hourly["weather.openweathermap"].forecast[0].condition %}
{%- if states('sun.sun') == 'below_horizon' %}
{%- if cond_now == 'sunny' %} night {% elif cond_now == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond_now }} {% endif %}
{%- else %}
{{ cond_now }}
{%- endif %}
weather_hourly_title: "{{ titles[1] }}"
weather_hourly_condition_0: >
{%- set cond0 = hourly["weather.openweathermap"].forecast[increment_0].condition %}
{%- set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{%- set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{%- set cond0_time = as_timestamp(hourly["weather.openweathermap"].forecast[increment_0].datetime) %}
{%- if cond0_time > next_setting and cond0_time < next_rising %}
{%- if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
{%- else %}
{{ cond0 }}
{%- endif %}
weather_hourly_temperature_0: >
{{ hourly["weather.openweathermap"].forecast[increment_0].temperature | round }}
weather_hourly_timestamp_0: >
{%- set timestamp = as_timestamp(hourly["weather.openweathermap"].forecast[increment_0].datetime) | timestamp_custom(time_format) %} {{ timestamp.lstrip(strip_zero) }}
weather_hourly_condition_1: >
{%- set cond0 = hourly["weather.openweathermap"].forecast[increment_1].condition %}
{%- set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{%- set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{%- set cond0_time = as_timestamp(hourly["weather.openweathermap"].forecast[increment_1].datetime) %}
{%- if cond0_time > next_setting and cond0_time < next_rising %}
{%- if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
{%- else %}
{{ cond0 }}
{%- endif %}
weather_hourly_temperature_1: >
{{ hourly["weather.openweathermap"].forecast[increment_1].temperature | round }}
weather_hourly_timestamp_1: >
{%- set timestamp = as_timestamp(hourly["weather.openweathermap"].forecast[increment_1].datetime) | timestamp_custom(time_format) %} {{ timestamp.lstrip(strip_zero) }}
weather_hourly_condition_2: >
{%- set cond0 = hourly["weather.openweathermap"].forecast[increment_2].condition %}
{%- set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{%- set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{%- set cond0_time = as_timestamp(hourly["weather.openweathermap"].forecast[increment_2].datetime) %}
{%- if cond0_time > next_setting and cond0_time < next_rising %}
{%- if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
{%- else %}
{{ cond0 }}
{%- endif %}
weather_hourly_temperature_2: >
{{ hourly["weather.openweathermap"].forecast[increment_2].temperature | round }}
weather_hourly_timestamp_2: >
{%- set timestamp = as_timestamp(hourly["weather.openweathermap"].forecast[increment_2].datetime) | timestamp_custom(time_format) %} {{ timestamp.lstrip(strip_zero) }}
weather_hourly_condition_3: >
{%- set cond0 = hourly["weather.openweathermap"].forecast[increment_3].condition %}
{%- set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{%- set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{%- set cond0_time = as_timestamp(hourly["weather.openweathermap"].forecast[increment_3].datetime) %}
{%- if cond0_time > next_setting and cond0_time < next_rising %}
{%- if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
{%- else %}
{{ cond0 }}
{%- endif %}
weather_daily_title: "{{ titles[2] }}"
weather_daily_condition_0: >
{{ daily["weather.openweathermap"].forecast[daily_0].condition }}
weather_daily_temperature_0: >
{{ daily["weather.openweathermap"].forecast[daily_0].temperature | round }}
weather_daily_timestamp_0: >
{{ as_timestamp(daily["weather.openweathermap"].forecast[daily_0].datetime) | timestamp_custom('%a') }}
weather_daily_condition_1: >
{{ daily["weather.openweathermap"].forecast[daily_1].condition }}
weather_daily_temperature_1: >
{{ daily["weather.openweathermap"].forecast[daily_1].temperature | round }}
weather_daily_timestamp_1: >
{{ as_timestamp(daily["weather.openweathermap"].forecast[daily_1].datetime) | timestamp_custom('%a') }}
weather_daily_condition_2: >
{{ daily["weather.openweathermap"].forecast[daily_2].condition }}
weather_daily_temperature_2: >
{{ daily["weather.openweathermap"].forecast[daily_2].temperature | round }}
weather_daily_timestamp_2: >
{{ as_timestamp(daily["weather.openweathermap"].forecast[daily_2].datetime) | timestamp_custom('%a') }}
weather_daily_condition_3: >
{{ daily["weather.openweathermap"].forecast[daily_3].condition }}
weather_daily_temperature_3: >
{{ daily["weather.openweathermap"].forecast[daily_3].temperature | round }}
weather_daily_timestamp_3: >
{{ as_timestamp(daily["weather.openweathermap"].forecast[daily_3].datetime) | timestamp_custom('%a') }}
- trigger:
- platform: time_pattern
minutes: /1
variables:
waketime: >
{# Edit and order the schedule from midnight 00:00 to 23:59 as needed #}
{%- set waketimes = [] %}
{%- set waketimes = waketimes + ["00:07"] %}
{%- set waketimes = waketimes + ["06:07"] %}
{%- set waketimes = waketimes + ["08:07"] %}
{%- set waketimes = waketimes + ["10:07"] %}
{%- set waketimes = waketimes + ["12:07"] %}
{%- set waketimes = waketimes + ["14:07"] %}
{%- set waketimes = waketimes + ["16:07"] %}
{%- set waketimes = waketimes + ["18:07"] %}
{%- set waketimes = waketimes + ["21:07"] %}
{%- set waketime = namespace(next = "") %}
{%- set waketime_all = [] %}
{%- for test in waketimes %}
{%- set waketime.next = (now().strftime('%Y-%m-%d')|string) + " " + (test|string) %}
{%- if (now().strftime('%Y-%m-%d %H:%M:%S')|string|as_datetime) < (waketime.next|as_datetime) %}
{%- break %}
{%- endif %}
{%- endfor %}
{%- if (now().strftime('%Y-%m-%d %H:%M:%S')|string|as_datetime) > (waketime.next|as_datetime) %}
{%- set waketime.next = (now().strftime('%Y-%m-%d')|string) + " " + (waketimes[0]|string) %}
{%- set waketime_helper = ((as_timestamp(waketime.next|as_datetime + timedelta(days=1)) - as_timestamp(now()|as_datetime))|int(0)) %}
{%- else %}
{%- set waketime_helper = ((as_timestamp(waketime.next|as_datetime) - as_timestamp(now()|as_datetime))|int(0)) %}
{%- endif %}
{%- set waketime_all = [waketime.next] + [waketime_helper] + [waketimes] %}
{{waketime_all}}
sensor:
- name: eInk WeatherBoard Wake Times
unique_id: eink_weatherboard_wake_times
state: "{{ this.attributes.next_wake_time | default('Not Available') }}"
attributes:
wake_times: "{{ waketime[2] | default('Not Available') }}"
next_wake_time: "{{ waketime[0] | default(999999) }}"
wake_time_helper: "{{ waketime[1] | default('Not Available') }}"