-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
update_map_extractor.yaml
194 lines (188 loc) · 7.16 KB
/
update_map_extractor.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
---
blueprint:
name: Update Map Extractor camera
description: |-
Controls update interval of a Map Extractor camera.
There are 5 modes available:
- Two intervals - automation controls camera updates both when vacuum is cleaning or docked. To use with `auto_update: false` in camera's configuration.
- Turn off when docked - completely turns off vacuum updates when the vacuum is docked. Uses default interval when cleaning.
- Default when docked - automation controls camera updates when vacuum is cleaning, default interval is used when vacuum is docked. To use with long `scan_interval` set up in camera's configuration.
- Default when cleaning - automation controls camera updates when vacuum is docked, default interval is used when vacuum is cleaning. To use with short/default `scan_interval` set up in camera's configuration.
- Only when card visible - completely turns off vacuum updates when the card is not visible. Uses default interval when visible. Requires configured view path (below) and installed [browser mod](https://github.com/thomasloven/hass-browser_mod) with "Auto-register" enabled to work properly.
domain: automation
source_url: https://github.com/PiotrMachowski/Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor/blob/master/blueprints/automation/update_map_extractor.yaml
input:
vacuum:
name: Vacuum device
selector:
entity:
domain: vacuum
camera:
name: Vacuum camera
selector:
entity:
domain: camera
mode_to_handle:
name: Mode
description: |-
Desired mode camera's updates
selector:
select:
options:
- value: two_intervals
label: Two intervals
- value: turn_off_when_docked
label: Turn off when docked
- value: default_when_docked
label: Default when docked
- value: default_when_cleaning
label: Default when cleaning
- value: browser_mod_path
label: Only when card visible
interval_docked:
name: Interval docked
description: |-
Camera's update interval that should be used when the vacuum is docked.
Not used in `Turn off when docked` and `Default when docked` modes.
selector:
number:
max: 10000
min: 1
unit_of_measurement: s
default: 1800
interval_cleaning:
name: Interval cleaning
description: |-
Camera's update interval that should be used when the vacuum is cleaning.
Not used in `Turn off when docked` and `Default when cleaning` modes.
selector:
number:
max: 10000
min: 1
unit_of_measurement: s
default: 10
update_once_after_docking:
name: Update once after docking
description: |-
Update the camera image after the vacuum is docked for 10 seconds.
selector:
boolean:
default: True
browser_mod_path:
name: Path to the view that contains the map card.
description: |-
Used only in `Only when card visible` mode
selector:
text:
default: "/lovelace/vacuum"
mode: parallel
variables:
interval_docked: !input interval_docked
interval_cleaning: !input interval_cleaning
mode_to_handle: !input mode_to_handle
update_once_after_docking: !input update_once_after_docking
vacuum_entity: !input vacuum
camera_entity: !input camera
browser_mod_path: !input browser_mod_path
is_vacuum_docked: "{{ states(vacuum_entity) in ['unavailable', 'unknown', 'docked', 'sleeping'] }}"
is_interval_docked_trigger: |-
{{
mode_to_handle in ['two_intervals', 'default_when_cleaning']
and trigger.id == 'time_pattern'
and (trigger.now | as_timestamp(0) | int(0) % interval_docked | int(0)) == 0
and is_vacuum_docked
}}
is_interval_cleaning_trigger: |-
{{
mode_to_handle in ['two_intervals', 'default_when_docked']
and trigger.id == 'time_pattern'
and (trigger.now | as_timestamp(0) | int(0) % interval_cleaning | int(0)) == 0
and not is_vacuum_docked
}}
is_vacuum_state_trigger: |-
{{
mode_to_handle in ['turn_off_when_docked', 'default_when_cleaning', 'default_when_docked']
and trigger.id == 'vacuum_changed'
}}
is_browser_mod_template_trigger: |-
{{
mode_to_handle in ['browser_mod_path']
and trigger.id == 'state_changed'
and (
trigger.event.data.new_state != None
and trigger.event.data.new_state.attributes != None
and "pathSegments" in trigger.event.data.new_state.attributes
and browser_mod_path == trigger.event.data.new_state.state
or
trigger.event.data.old_state != None
and trigger.event.data.old_state.attributes != None
and "pathSegments" in trigger.event.data.old_state.attributes
and browser_mod_path in trigger.event.data.old_state.state
)
}}
is_vacuum_docked_trigger: |-
{{
trigger.id == 'vacuum_docked' and update_once_after_docking
}}
active_browsers: |-
{{
states.sensor
| selectattr('attributes.pathSegments', 'defined')
| selectattr('attributes.type', '==', 'browser_mod')
| selectattr('state', '==', browser_mod_path)
| list
| count
}}
trigger:
- platform: event
event_type: state_changed
id: state_changed
- platform: state
entity_id: !input vacuum
id: vacuum_changed
- platform: state
entity_id: !input vacuum
to: docked
for:
seconds: 10
id: vacuum_docked
condition:
- condition: or
conditions:
- condition: template
value_template: "{{ is_interval_docked_trigger }}"
- condition: template
value_template: "{{ is_interval_cleaning_trigger }}"
- condition: template
value_template: "{{ is_vacuum_state_trigger }}"
- condition: template
value_template: "{{ is_browser_mod_template_trigger }}"
- condition: template
value_template: "{{ is_vacuum_docked_trigger }}"
action:
- choose:
- conditions: "{{ is_interval_docked_trigger or is_interval_cleaning_trigger or is_vacuum_docked_trigger }}"
sequence:
- service: homeassistant.update_entity
entity_id: !input camera
- conditions: "{{ is_vacuum_state_trigger }}"
sequence:
- choose:
- conditions: |-
{{
mode_to_handle in ['turn_off_when_docked', 'default_when_cleaning']
}}
sequence:
- service: "camera.{{ is_vacuum_docked | iif('turn_off', 'turn_on') }}"
entity_id: !input camera
- conditions: |-
{{
mode_to_handle in ['default_when_docked']
}}
sequence:
- service: "camera.{{ is_vacuum_docked | iif('turn_on', 'turn_off') }}"
entity_id: !input camera
- conditions: "{{ is_browser_mod_template_trigger }}"
sequence:
- service: "camera.{{ (active_browsers > 0) | iif('turn_on', 'turn_off') }}"
entity_id: !input camera