-
Notifications
You must be signed in to change notification settings - Fork 5
/
car_heater.yaml
262 lines (251 loc) · 8.86 KB
/
car_heater.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
automation:
- id: 'car_heater_on_timer'
alias: 'Turn on car heating timer'
trigger:
- entity_id: input_boolean.car_heater_enable
from: 'off'
platform: state
to: 'on'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.car_heater_3h_before_temp
# CHANGE-ME: outside temperature sensor
value: '{{ states.weather.home.attributes.temperature }}'
- event: car_heater_timer_enabled
- id: 'car_heater_start_if_needed'
alias: 'Turn on car heating immediately if needed'
trigger:
- platform: event
event_type: car_heater_timer_enabled
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.sensor.car_time_until_departure.state|float > 0 }}'
- condition: template
value_template: '{{ (states.sensor.car_heater_run_time.state|float * 60) >= states.sensor.car_time_until_departure.state|float }}'
action:
- service: switch.turn_on
# CHANGE-ME: car heater power switch
entity_id: switch.car_heater
- id: 'car_heater_push'
alias: 'Send no car heater connected -push notification'
description: ''
trigger:
- platform: state
# CHANGE-ME: car heater power switch
entity_id: switch.car_heater
from: 'off'
to: 'on'
condition: []
action:
# CHANGE-ME: power consumption sensor
- wait_template: '{{ states(''sensor.car_heater_power'') | float
> 0 }}'
timeout: 00:00:35
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: '{{ not wait.completed }}'
sequence:
# CHANGE-ME: mobile app notification device
- service: notify.mobile_app_samsung_s10
data:
message: Car heating power cable is not connected!
title: Car heater
default: []
mode: single
- id: 'car_heater_calculated_time'
alias: 'Start engine heater at calculated start time'
trigger:
- platform: time_pattern
minutes: "/1"
seconds: 00
condition:
condition: and
conditions:
- condition: template
value_template: '{{ now().time().strftime("%H:%M") == states.sensor.car_heater_start_time.state }}'
- condition: template
value_template: '{{ states.sensor.car_heater_run_time.state|float > 0 }}'
- condition: state
entity_id: input_boolean.car_heater_enable
state: 'on'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.car_heater_weekday
state: 'off'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: switch.turn_on
# CHANGE-ME: car heater power switch
entity_id: switch.car_heater
- id: 'car_heater_departure'
alias: 'Stop engine heater at departure time'
trigger:
- platform: time_pattern
minutes: "/1"
seconds: 00
condition:
condition: and
conditions:
- condition: template
value_template: '{{ now().time().strftime("%H:%M:%S") == states.input_datetime.car_heater_departure_time.state }}'
- condition: template
value_template: '{{ states.sensor.car_heater_run_time.state|float > 0 }}'
- condition: state
entity_id: input_boolean.car_heater_enable
state: 'on'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.car_heater_weekday
state: 'off'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: switch.turn_off
# CHANGE-ME: car heater power switch
entity_id: switch.car_heater
- id: 'car_heater_temp_sample_3h'
alias: 'Sample temperature 3h before departure time'
trigger:
- platform: time_pattern
minutes: "/1"
seconds: 00
condition:
condition: and
conditions:
- condition: template
value_template: '{{ now().time().strftime("%H:%M") == states.sensor.car_heater_3h_before_start_time.state }}'
- condition: state
entity_id: input_boolean.car_heater_enable
state: 'on'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.car_heater_weekday
state: 'off'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: input_number.set_value
data_template:
entity_id: input_number.car_heater_3h_before_temp
# CHANGE-ME: outside temperature sensor
value: '{{ states.weather.home.attributes.temperature }}'
# Input sensors
input_datetime:
car_heater_departure_time:
name: Car heater departure time
has_time: true
has_date: false
input_number:
car_heater_3h_before_temp:
name: Sample temp
unit_of_measurement: °C
icon: mdi:thermometer
min: -30
max: 30
step: 0.5
# Boolean sensors
input_boolean:
car_heater_weekday:
name: Only weekdays
icon: mdi:calendar
car_heater_enable:
name: Enable car heating timer
sensor:
- platform: template
sensors:
car_heater_run_time:
friendly_name: 'Calculated run time'
unit_of_measurement: h
value_template: >
{% if ((states('input_number.car_heater_3h_before_temp')|float) < 10) %}
{% if not states('input_number.car_heater_3h_before_temp') == 'unknown' %}
{{(states('input_number.car_heater_3h_before_temp')|float * (-0.05) + 1)|round(1)}}
{%endif%}
{%else%}
0
{%endif%}
- platform: template
sensors:
car_heater_start_time:
friendly_name: 'Calculated start time'
icon_template: mdi:clock
value_template: >
{% if states.input_datetime.car_heater_departure_time.state is defined %}
{% if ((states('sensor.car_heater_run_time')|float) > 0) %}
{{ strptime(((as_timestamp('1970-01-01 ' ~ states('input_datetime.car_heater_departure_time')) - (states('sensor.car_heater_run_time')|float *3600))|timestamp_custom), '%Y-%m-%d %H:%M:%S').strftime("%H:%M") }}
{%else%}
Never
{%endif%}
{% else %}
waiting for sensors
{% endif%}
- platform: template
sensors:
car_heater_3h_before_start_time:
friendly_name: '3h before start time'
icon_template: mdi:clock
value_template: >
{% if states.input_datetime.car_heater_departure_time.state is defined %}
{{ strptime(((as_timestamp('1970-01-01 ' ~ states('input_datetime.car_heater_departure_time')) - (10800))|timestamp_custom), '%Y-%m-%d %H:%M:%S').strftime("%H:%M") }}
{% else %}
waiting for sensors
{% endif%}
- platform: template
sensors:
car_heater_status:
friendly_name: 'Car heater status'
icon_template: mdi:clock
# CHANGE-ME: car heater power switch (note: two entrys in this block)
value_template: >
{% if is_state('input_boolean.car_heater_enable', 'on') %}
{% if is_state('switch.car_heater', 'on') %}
Car heating is currently active and will be stopped at {{ states.input_datetime.car_heater_departure_time.state }}
{% else %}
Car heating will start approximately at {{ states.sensor.car_heater_start_time.state }} and will be stopped at {{ states.input_datetime.car_heater_departure_time.attributes.timestamp | timestamp_custom("%H:%M", false) }}
{% endif%}
{% else %}
{% if is_state('switch.car_heater', 'on') %}
Car heating is active and controlled manually!
{% else %}
No car heating scheduled
{%endif %}
{% endif%}
- platform: template
sensors:
car_time_until_departure:
friendly_name: 'time until set departure'
icon_template: mdi:clock
value_template: >-
{%- if as_timestamp(now().strftime("%Y-%m-%d ") + states.input_datetime.car_heater_departure_time.state) < as_timestamp(now()) -%}
{{ ((as_timestamp(now().strftime("%Y-%m-%d ") +
states.input_datetime.car_heater_departure_time.state) + (3600*24)) -
as_timestamp(now().strftime("%Y-%m-%d %H:%M"))) / 60 }}
{%- else -%}
{{ (as_timestamp(now().strftime("%Y-%m-%d ") +
states.input_datetime.car_heater_departure_time.state) -
as_timestamp(now().strftime("%Y-%m-%d %H:%M"))) / 60 }}
{%- endif -%}