-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcar_parking.yaml
263 lines (247 loc) · 9.17 KB
/
car_parking.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
262
263
input_datetime:
parking_timer:
name: Parking Timer
has_date: true
has_time: true
icon: mdi:timer
template:
- sensor:
- name: Parking Lot
unique_id: c7d27d36-a1d6-4b62-845c-4a19c89a677f
icon: mdi:parking
state: >-
{% from 'geofence.jinja' import point_in_polygon %}
{% set lat = state_attr('device_tracker.id_3_pro_tracker', 'latitude') %}
{% set lon = state_attr('device_tracker.id_3_pro_tracker', 'longitude') %}
{% set parking_lots = {
'RSH Parkering': [
[55.734290, 12.441878],
[55.734290, 12.440001],
[55.733776, 12.440001],
[55.733776, 12.441878],
],
'HEH P2': [
[55.733332, 12.445268],
[55.733332, 12.440081],
[55.732276, 12.440081],
[55.732276, 12.445268],
],
'HEH P3': [
[55.733330, 12.440095],
[55.733330, 12.438647],
[55.731956, 12.438647],
[55.731956, 12.440095],
],
'HEH P4': [
[55.730843, 12.439874],
[55.731913, 12.439906],
[55.731901, 12.441923],
[55.730843, 12.441902],
],
'HEH P7': [
[55.729319, 12.440760],
[55.729319, 12.439634],
[55.728428, 12.439634],
[55.728428, 12.440760],
],
'HEH P9': [
[55.729271, 12.442927],
[55.729271, 12.441393],
[55.728694, 12.441393],
[55.728694, 12.442927],
],
'HEH Runddyssen': [
[55.734704, 12.444351],
[55.734704, 12.439395],
[55.734173, 12.439395],
[55.734173, 12.444351],
],
'RH P-Hus': [
[55.699487, 12.564753],
[55.698846, 12.565826],
[55.698586, 12.565344],
[55.699251, 12.564271],
],
'RH Hovedindgangen': [
[55.696419, 12.568442],
[55.695705, 12.569654],
[55.695034, 12.568356],
[55.695772, 12.567122],
],
'RSR Varemodtagelsen': [
[55.699613, 12.564575],
[55.699480, 12.564800],
[55.699033, 12.563964],
[55.699166, 12.563733],
],
'RH Frederik Vs Vej': [
[55.699862, 12.564845],
[55.696246, 12.570810],
[55.696146, 12.570617],
[55.699735, 12.564652],
],
'RH Edel Sauntes Alle': [
[55.704858, 12.565565],
[55.703214, 12.563033],
[55.698377, 12.562218],
[55.700189, 12.565552],
[55.704589, 12.566055],
],
} %}
{% for lot in parking_lots %}
{% set points = parking_lots[lot] %}
{% if point_in_polygon(lat, lon, points) == "True" %}
{{ lot }}
{% break %}
{% endif %}
{% endfor %}
- name: "Bil Placering"
unique_id: 1d0ac9cc-40e7-4154-95ec-45f163e4b7b5
icon: mdi:car
state: >-
{% if is_state('binary_sensor.id_3_pro_car_is_active', 'on') %}
Kører
{% elif has_value('sensor.parking_lot') and not is_state('sensor.parking_lot', '') %}
{{ states('sensor.parking_lot') }}
{% else %}
{{ state_translated('device_tracker.id_3_pro_tracker') }}
{% endif %}
- name: Parking Clock
unique_id: 1b039e84-9fbe-46f5-9ff9-f34ac68a34f7
icon: mdi:parking
state: >-
{{ states('sensor.parkeringsskive') | as_timestamp | timestamp_custom('%H:%M') }}
- name: Parking Duration Limit
unique_id: 6eab91a5-6fe1-47fa-ac76-2f000ce2e39b
icon: mdi:timer
device_class: duration
unit_of_measurement: s
state: >
{% set parking_limits = {
'HEH P2': 3*60*60,
'HEH P4': 3*60*60,
} %}
{{ parking_limits.get(states('sensor.parking_lot'), 0) }}
- name: Parking Limit
unique_id: 18ed291c-f453-49c3-b763-68a8bbbeeb8e
device_class: timestamp
state: >-
{% if is_state('binary_sensor.parking_limit', 'on') %}
{{ (as_timestamp(states('sensor.parkeringsskive')) + states('sensor.parking_duration_limit')|int) | as_datetime }}
{% endif %}
- name: Parking Limit Clock
unique_id: 141f07b0-4205-40bf-9ede-99956e72ea15
icon: mdi:timer
state: >-
{% if is_state('binary_sensor.parking_limit', 'on') %}
{{ states('sensor.parking_limit') | as_timestamp | timestamp_custom('%H:%M') }}
{% endif %}
- name: Parking Alarm
unique_id: 5675dfe4-8ef6-4673-a0fd-dab9242b230f
device_class: timestamp
state: >-
{% if is_state('binary_sensor.parking_limit', 'on') %}
{{ (as_timestamp(states('sensor.parking_limit')) - (15 * 60)) | as_datetime }}
{% endif %}
- name: Parking Alarm Clock
unique_id: 86007395-04ff-46c1-ad1a-ab3c94dd24ba
icon: mdi:alarm
state: >-
{% if is_state('binary_sensor.parking_limit', 'on') %}
{{ states('sensor.parking_alarm') | as_timestamp | timestamp_custom('%H:%M') }}
{% endif %}
- trigger:
- platform: state
entity_id:
- device_tracker.id_3_pro_tracker
- input_datetime.parking_timer
not_to:
- "unknown"
- "unavailable"
sensor:
- name: Parkeringsskive
unique_id: ede9dcb5-8cd0-49f9-a08c-93a7fe81d806
icon: mdi:clock-time-eight-outline
device_class: timestamp
state: >-
{% set parked = state_attr('device_tracker.id_3_pro_tracker', 'last_captured') | as_datetime | as_local %}
{% set seconds_past = (parked.minute % 15) * 60 + parked.second %}
{% set seconds_until_next_quarter = (15 * 60) - seconds_past %}
{% set next_quarter_timestamp = as_timestamp(parked) + seconds_until_next_quarter %}
{% set car_parking_timer = next_quarter_timestamp | as_datetime %}
{% set manual_parking_timer = states('input_datetime.parking_timer') | as_datetime | as_local if has_value('input_datetime.parking_timer') %}
{% if manual_parking_timer and car_parking_timer < manual_parking_timer %}
{{ manual_parking_timer }}
{% else %}
{{ car_parking_timer }}
{% endif %}
- binary_sensor:
- name: Parking Limit
unique_id: d0c30716-e823-49f6-b4fb-a3af86f6b77b
state: "{{ has_value('sensor.parking_duration_limit') and not is_state('sensor.parking_duration_limit', '0') }}"
- name: Parking Lot Paid
unique_id: 2967a5ab-e79f-4fbf-8e26-e18ace9311da
icon: mdi:credit-card
state: >
{{ states('sensor.parking_lot') in [
'RH Frederik Vs Vej',
'RH Edel Sauntes Alle',
'RSR Varemodtagelsen',
] }}
automation:
- alias: "Paid parking"
id: 9639dddf-8e3b-4321-811d-6df6b8562c24
initial_state: True
trigger:
platform: state
entity_id: binary_sensor.parking_lot_paid
to: "on"
action:
- action: script.notify_darkphone
data:
message: |
Du har parkeret på {{ states('sensor.parking_lot') }}.
Husk at oprette parkering i receptionen eller online.
- alias: "Set Parked Time"
id: c562770a-5958-46b7-ace8-3cbf4996fe88
initial_state: True
trigger:
platform: state
entity_id: sensor.parkeringsskive
for:
seconds: 10
action:
- condition: numeric_state
entity_id: sensor.parking_duration_limit
above: 0
- variables:
parked_time: "{{ as_timestamp(state_attr('device_tracker.id_3_pro_tracker', 'last_captured')) | timestamp_custom('%H:%M') }}"
parkeringsskive: "{{ as_timestamp(states('sensor.parkeringsskive')) | timestamp_custom('%H:%M') }}"
parking_limit: "{{ as_timestamp(states('sensor.parking_limit')) | timestamp_custom('%H:%M') }}"
parking_alarm: "{{ as_timestamp(states('sensor.parking_alarm')) | timestamp_custom('%H:%M') }}"
- action: script.android_set_alarm
data:
action: notify.mobile_app_darkphone
timehour: "{{ parking_alarm.split(':')[0] }}"
timemin: "{{ parking_alarm.split(':')[1] }}"
message: Flyt bilen!
- action: script.notify_darkphone
data:
message: |
Parkeret på {{ states('sensor.parking_lot') }} klokken {{ parked_time }}.
Timer sat til kl. {{ parkeringsskive }}, flyt bilen inden kl. {{ parking_limit }}.
Alarm sat til kl. {{ parking_alarm }}.
- alias: "Parking Alarm"
id: parking_alarm
initial_state: True
trigger:
platform: time
at: sensor.parking_alarm
action:
- action: script.notify_darkphone
data:
message: >-
Flyt bilen!
- action: switch.turn_on
target:
entity_id: switch.id_3_pro_climatisation