forked from robwolff3/homeassistant-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoccupancy.yaml
executable file
·184 lines (154 loc) · 5.39 KB
/
occupancy.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
#################################################################
## Sensors
binary_sensor:
- platform: template
sensors:
user1_occupancy:
device_class: presence
value_template: >-
{{ is_state('device_tracker.user1', 'home')
or states('sensor.user1_office')|float > 9
or states('sensor.user1_bedroom')|float > 9
or states('sensor.user1_upstairs')|float > 9 }}
user2_occupancy:
device_class: presence
value_template: >-
{{ is_state('device_tracker.user2', 'home')
or states('sensor.user2_office')|float > 9
or states('sensor.user2_bedroom')|float > 9
or states('sensor.user2_upstairs')|float > 9 }}
user3_occupancy:
device_class: presence
value_template: >-
{{ is_state('device_tracker.user3', 'home')
or states('sensor.user3_office')|float > 9
or states('sensor.user3_bedroom')|float > 9
or states('sensor.user3_upstairs')|float > 9 }}
user4_occupancy:
device_class: presence
value_template: >-
{{ is_state('device_tracker.user4', 'home')
or states('sensor.user4_office')|float > 9
or states('sensor.user4_bedroom')|float > 9
or states('sensor.user4_upstairs')|float > 9 }}
sensor:
## User1 Occupancy Detection ##
- platform: mqtt
state_topic: !secret topic_office_user1
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User1 Office'
- platform: mqtt
state_topic: !secret topic_bedroom_user1
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User1 Bedroom'
- platform: mqtt
state_topic: !secret topic_upstairs_user1
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User1 Upstairs'
## User2 Occupancy Detection ##
- platform: mqtt
state_topic: !secret topic_office_user2
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User2 Office'
- platform: mqtt
state_topic: !secret topic_bedroom_user2
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User2 Bedroom'
- platform: mqtt
state_topic: !secret topic_upstairs_user2
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User2 Upstairs'
## User3 Occupancy Detection ##
- platform: mqtt
state_topic: !secret topic_office_user3
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User3 Office'
- platform: mqtt
state_topic: !secret topic_bedroom_user3
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User3 Bedroom'
- platform: mqtt
state_topic: !secret topic_upstairs_user3
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User3 Upstairs'
## User4 Occupancy Detection ##
- platform: mqtt
state_topic: !secret topic_office_user4
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User4 Office'
- platform: mqtt
state_topic: !secret topic_bedroom_user4
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User4 Bedroom'
- platform: mqtt
state_topic: !secret topic_upstairs_user4
value_template: '{{ value_json.confidence }}'
unit_of_measurement: '%'
name: 'User4 Upstairs'
#################################################################
## Automations
automation:
## Publish Message - Arrival Scan
- alias: Publish Message - Arrival Scan
trigger:
- platform: state
entity_id: binary_sensor.frontdoor_contact, binary_sensor.sidedoor_contact, binary_sensor.backdoor_contact
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.user1_occupancy
state: 'off'
- condition: state
entity_id: binary_sensor.user2_occupancy
state: 'off'
- condition: state
entity_id: binary_sensor.user3_occupancy
state: 'off'
- condition: state
entity_id: binary_sensor.user4_occupancy
state: 'off'
action:
- service: mqtt.publish
data_template:
topic: "home/scan/ARRIVE"
payload: 'null'
## Publish Message - Departure Scan
- alias: Publish Message - Departure Scan
trigger:
- platform: state
entity_id: binary_sensor.frontdoor_contact, binary_sensor.sidedoor_contact, binary_sensor.backdoor_contact
from: 'on'
to: 'off'
condition:
condition: or
conditions:
- condition: state
entity_id: binary_sensor.user1_occupancy
state: 'on'
- condition: state
entity_id: binary_sensor.user2_occupancy
state: 'on'
- condition: state
entity_id: binary_sensor.user3_occupancy
state: 'on'
- condition: state
entity_id: binary_sensor.user4_occupancy
state: 'on'
action:
- delay: '00:00:15'
- service: mqtt.publish
data_template:
topic: "home/scan/DEPART"
payload: 'null'