/
managing_a_door_contact.yaml
190 lines (185 loc) · 5.84 KB
/
managing_a_door_contact.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
blueprint:
name: Managing a door contact
domain: automation
description: "`- Version: 1.0 -`\n\n # Managing a door contact\n
In this project I try to exploit a sensor port for multiple uses.\n
Automation is divided into two parts:\n
#### Turns on a light when the door is opened for a customizable time by following rules:\n
- Let it be after sunset\n
- You can insert switch and light\n
- The light is turned on/off only if the initial state was not on\n
- The light is turned off after a customizable time that starts from the moment the door is closed\n
#### Receive an alert in case the door was left open for a customizable time:\n
- You can decide whether to enable push notification.\n
- You can decide whether to enable TTS notification.\n
- You can decide whether to enable Alexa notification.\n
- You can customize the text of the notification.\n
- You can opt out of receiving alerts by not enabling any of the notify services\n
## Requirements:\n
In order to use the project:\n
- The door sensor must be *device_class: door*.\n
"
input:
light:
name: Light
description: Select the entity that should light up when you open the door
selector:
entity:
#multiple: true
domain:
- switch
- light
light_off:
name: Delay to turn off the light
description: Waiting time to turn off the light since the door is closed
default: 30
selector:
number:
min: 0
max: 360
unit_of_measurement: sec
mode: slider
step: 1
door:
name: Door
description: Select the door sensor
selector:
entity:
domain: binary_sensor
device_class: door
time_door:
name: Open door warning time
description: Waiting time before receiving notice that the door has been left open
default: 30
selector:
number:
min: 0
max: 360
unit_of_measurement: sec
mode: slider
step: 1
text_notify:
name: Text noty
description: "**Example of the text in Italian:** Porta d'ingresso dimentica aperta"
default: false
selector:
text:
push:
name: "Notify push"
description: Enable to receive push notification
default: false
selector:
boolean:
notify_device:
name: Device to notify push
description: Device needs to run the official Home Assistant app to receive notifications.
default: false
selector:
device:
integration: mobile_app
tts:
name: "Notify TTS announcement "
description: "Enable to receive TTS notification"
default: false
selector:
boolean:
notify_tts:
name: Speaker for notify TTS
default: false
description: "Insert at least one media_player. \n
**IMPORTANT** The tts service called by default is **tts.google_translate_say** "
selector:
entity:
domain: media_player
device_class: speaker
multiple: true
alexa:
name: "Notify Alexa"
description: "Enable to receive notification on Alexa"
default: false
selector:
boolean:
notify_alexa:
name: Speaker for notify Alexa
default: false
description: "Insert at least one media_player.\n
**IMPORTANT** If Alexa not integrated set the *notify alexa* button to off"
selector:
entity:
domain: media_player
multiple: true
mode: restart
variables:
light: !input light
porta: !input door
tts: !input tts
push: !input push
alexa: !input alexa
trigger:
- platform: state
entity_id: !input door
from: "off"
to: "on"
- platform: state
entity_id: !input door
from: "off"
to: "on"
for:
seconds: !input time_door
id: open
action:
- alias: Avviso porta aperta
if:
- condition: trigger
id: open
then:
- parallel:
- if:
- "{{ alexa == true }}"
then:
- service: notify.alexa_media
data:
target: !input notify_alexa
data:
type: announce
method: spoken
message: !input text_notify
- if:
- "{{ push == true }}"
then:
- domain: mobile_app
type: notify
device_id: !input notify_device
title: Door Open
message: !input text_notify
- if:
- "{{ tts == true }}"
then:
- service: tts.google_translate_say
data:
message: !input text_notify
entity_id: !input notify_tts
- alias: Accensione luce per apertura porta
if:
- "{{trigger.entity_id == porta and is_state(light,'off')}}"
- alias: Dopo tramonto
condition: state
entity_id: sun.sun
state: below_horizon
then:
- alias: Accendi luce
service: homeassistant.turn_on
target:
entity_id: !input light
- alias: Attendi
wait_for_trigger:
- alias: Porta chiusa per x sec
platform: state
entity_id: !input door
to: "off"
for:
seconds: !input light_off
- alias: Spegni luce
service: homeassistant.turn_off
target:
entity_id: !input light