forked from jeremywillans/ha-rest980-roomba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vacuum.yaml
364 lines (338 loc) · 10.3 KB
/
vacuum.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
###################################
# iRobot Vacuum Package
###################################
###################################
# Sensor
###################################
sensor:
# Roomba via Rest980 Docker Image
- platform: rest
name: rest980
json_attributes:
- batPct
- bin
- cleanMissionStatus
- dock
- pose
resource: !secret vacuum_state
value_template: 'OK'
scan_interval: 10
- platform: template
sensors:
vacuum_battery:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Battery
value_template: >-
{{ state_attr('sensor.rest980', 'batPct') }}
unit_of_measurement: '%'
device_class: battery
vacuum_cycle:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Cycle
value_template: >-
{% set mapper = {
'clean' : 'Cleaning',
'evac' : 'Emptying Robot',
'dock' : 'Returning Home',
'none' : 'Ready' } %}
{% set state = state_attr('sensor.rest980', 'cleanMissionStatus')["cycle"] %}
{{ mapper[state] if state in mapper else 'Unknown' }}
icon_template: mdi:broom
vacuum_phase:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Status
value_template: >-
{% if state_attr('sensor.rest980', 'cleanMissionStatus')["phase"] == 'charge' and state_attr('sensor.rest980', 'batPct') == 100 %}
Fully Charged
{% else %}
{% set mapper = {
'charge' : 'Charging',
'run' : 'Cleaning',
'evac' : 'Emptying Robot',
'stop' : 'Stopped/Paused',
'stuck' : 'Stuck',
'hmUsrDock' : 'Sent Home',
'hmMidMsn' : 'Returning Home mid Clean',
'hmPostMsn' : 'Returning Home' } %}
{% set state = state_attr('sensor.rest980', 'cleanMissionStatus')["phase"] %}
{{ mapper[state] if state in mapper else 'Unknown' }}
{% endif %}
icon_template: mdi:settings
vacuum_bin:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Bin Status
value_template: >-
{% set mapper = {
true : 'Full',
false : 'Not Full' } %}
{% set state = state_attr('sensor.rest980', 'bin')["full"] %}
{{ mapper[state] if state in mapper else 'Unknown' }}
icon_template: mdi:delete
vacuum_dock:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Clean Base Status
value_template: >-
{% set mapper = {
300 : 'Ready',
301 : 'Ready',
302 : 'Emptying Robot',
350 : 'Bag Missing',
351 : 'Base Clogged',
353 : 'Bag Full' } %}
{% set state = state_attr('sensor.rest980', 'dock')["state"] %}
{{ mapper[state] if state in mapper else 'Unknown' }}
icon_template: mdi:home-minus
vacuum_location:
friendly_name_template: >-
{{ states('input_text.vacuum_name') }} Location
value_template: >-
{% if state_attr('sensor.rest980', 'pose')['theta'] is defined %}
({{ state_attr('sensor.rest980', 'pose')['point']['x'] }}, {{ state_attr('sensor.rest980', 'pose')['point']['y'] }}, {{ state_attr('sensor.rest980', 'pose')['theta'] }})
{% else %}
Unavailable
{% endif %}
icon_template: mdi:home-map-marker
###################################
# Rest Command
###################################
rest_command:
vacuum_action:
url: >-
{{ states('input_text.vacuum_action') }}{{ command }}
verify_ssl: !secret vacuum_verify_ssl
method: 'get'
timeout: 20
vacuum_clean:
url: >-
{{ states('input_text.vacuum_action') }}cleanRoom
verify_ssl: !secret vacuum_verify_ssl
method: POST
content_type: 'application/json'
payload: '{{ payload }}'
###################################
# Input Boolean
###################################
input_boolean:
vacuum_kitchen:
name: Kitchen
icon: mdi:silverware-fork-knife
vacuum_entry:
name: Entry
icon: mdi:coat-rack
vacuum_hall:
name: Hall
icon: mdi:ceiling-light
vacuum_living_room:
name: Living Room
icon: mdi:sofa
vacuum_bathroom:
name: Bathroom
icon: mdi:shower
vacuum_bedroom:
name: Bedroom
icon: mdi:bed-empty
vacuum_wardrobe:
name: Wardrobe
icon: mdi:wardrobe-outline
vacuum_master_ensuite:
name: Master Ensuite
icon: mdi:shower
vacuum_master_bedroom:
name: Master Bedroom
icon: mdi:bed-empty
vacuum_table:
name: Table
icon: mdi:room-service
###################################
# Input Text
###################################
input_text:
vacuum_name:
name: Vacuum Name
initial: !secret vacuum_name
vacuum_action:
name: Vacuum Action URL
initial: !secret vacuum_action
vacuum_map:
name: Vacuum Map URL
initial: !secret vacuum_map
vacuum_log:
name: Vacuum Log Path
initial: !secret vacuum_log
vacuum_floorplan:
name: Floorplan ID
initial: !secret vacuum_floorplan
vacuum_user_floorplan:
name: User Floorplan ID
initial: !secret vacuum_user_floorplan
vacuum_kitchen:
name: Kitchen
initial: !secret vacuum_kitchen
vacuum_entry:
name: Entry
initial: !secret vacuum_entry
vacuum_hall:
name: Hall
initial: !secret vacuum_hall
vacuum_living_room:
name: Living Room
initial: !secret vacuum_living_room
vacuum_bathroom:
name: Bathroom
initial: !secret vacuum_bathroom
vacuum_bedroom:
name: Bedroom
initial: !secret vacuum_bedroom
vacuum_wardrobe:
name: Wardrobe
initial: !secret vacuum_wardrobe
vacuum_master_ensuite:
name: Master Ensuite
initial: !secret vacuum_master_ensuite
vacuum_master_bedroom:
name: Master Bedroom
initial: !secret vacuum_master_bedroom
vacuum_table:
name: Table
initial: !secret vacuum_table
###################################
# Group
###################################
group:
vacuum_rooms:
- input_boolean.vacuum_kitchen
- input_boolean.vacuum_entry
- input_boolean.vacuum_hall
- input_boolean.vacuum_living_room
- input_boolean.vacuum_bathroom
- input_boolean.vacuum_bedroom
- input_boolean.vacuum_wardrobe
- input_boolean.vacuum_master_ensuite
- input_boolean.vacuum_master_bedroom
- input_boolean.vacuum_table
###################################
# Automation
###################################
automation:
# Initiate Selective Room Clean
- alias: Vacuum Clean Rooms
hide_entity: true
trigger:
- platform: event
event_type: initiate_vacuum_clean
action:
- service: rest_command.vacuum_clean
data_template:
payload: >
{
"ordered": 0,
"pmap_id": "{{ states('input_text.vacuum_floorplan') | string }}",
"regions": [{% for boolean in states.input_boolean if 'vacuum' in boolean.entity_id and is_state(boolean.entity_id, 'on') %}
{% set room = 'input_text.' + boolean.entity_id.split('.')[1] %} {{ states(room) | string }} {%- if not loop.last %},{%- endif %}
{%- endfor %}
],
"user_pmapv_id": "{{ states('input_text.vacuum_user_floorplan') | string }}"
}
- service: input_boolean.turn_off
data:
entity_id: group.vacuum_rooms
# Update Vacuum REST Sensor for Location Details
- alias: Vacuum Update Location
initial_state: true
trigger:
- platform: time_pattern
seconds: /2
- platform: event
event_type: call_service
event_data:
domain: rest_command
service: vacuum_clean
condition:
condition: state
entity_id: sensor.vacuum_cycle
state: 'Cleaning'
action:
- service: homeassistant.update_entity
entity_id: sensor.rest980
# Log Vacuum Location to File
- alias: Vacuum Log Position
initial_state: true
trigger:
platform: state
entity_id: sensor.vacuum_location
condition:
condition: state
entity_id: sensor.vacuum_cycle
state: 'Cleaning'
action:
- service: notify.vacuumfile
data_template:
message: "{{ states('sensor.vacuum_location') }}"
# Initialize Blank Vacuum Log File
- alias: Vacuum Clean Log
initial_state: true
trigger:
platform: state
entity_id: sensor.vacuum_cycle
from: 'Ready'
to: 'Cleaning'
action:
- service: shell_command.vacuum_clear_log
- service: shell_command.vacuum_clear_image
# Update Vacuum Log File with Finished Status
- alias: Vacuum Notify on Finished Cleaning
initial_state: true
trigger:
platform: state
entity_id: sensor.vacuum_cycle
from: 'Cleaning'
to: 'Ready'
action:
- service: notify.vacuumfile
data_template:
message: "Finished"
# Update Vacuum Log File with Stuck Status
- alias: Vacuum Notify on Stuck Status
initial_state: true
trigger:
platform: state
entity_id: sensor.vacuum_phase
to: 'Stuck'
action:
- service: notify.vacuumfile
data_template:
message: "Stuck"
# Generate Complete Vacuum Map
- alias: Vacuum Generate Image after Cleaning
initial_state: true
trigger:
platform: state
entity_id: sensor.vacuum_cycle
from: 'Cleaning'
to: 'Ready'
for:
seconds: 10
action:
service: shell_command.vacuum_generate_image
###################################
# Notify
###################################
notify:
- name: VacuumFile
platform: file
filename: !secret vacuum_log
###################################
# Camera
###################################
camera:
- platform: generic
still_image_url: !secret vacuum_map
content_type: image/png
name: Roomba
###################################
# Shell Command
###################################
shell_command:
vacuum_clear_log: cp /dev/null {{ states('input_text.vacuum_log') }}
vacuum_clear_image: curl -X GET -s -O /dev/null '{{ states("input_text.vacuum_map") }}?clear=true'
vacuum_generate_image: curl -X GET -s -O /dev/null '{{ states("input_text.vacuum_map") }}?last=true'