mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2026-05-03 21:46:45 +00:00
Use Dreame segment cleaning services in vacuum automations
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
# - Treat 2+ minutes in a room as "being cleaned" and dequeue immediately (queue = remaining rooms).
|
||||
# - Phase changes happen only after verified completion at dock (`task_status: completed`).
|
||||
# - Guarded fallback: if docked with empty queue for 10 minutes but no `completed`, advance with `fallback_advance` log.
|
||||
# - Use `vacuum.clean_area` (HA 2026.3+) and keep room->area mappings aligned with Home Assistant Areas.
|
||||
# - Use `dreame_vacuum.vacuum_clean_segment` with the integration's segment ids.
|
||||
# - Jinja2 loop scoping: use a `namespace` when building lists (otherwise the queue can appear empty and get cleared).
|
||||
# - If docked+completed still has queue entries, treat queue as stale and clear it before phase advance.
|
||||
# - Mop phases use `sweeping_and_mopping` instead of mop-only.
|
||||
@@ -133,30 +133,7 @@ script:
|
||||
{{ bath_ids }}
|
||||
{% endif %}
|
||||
segments_to_clean: "{{ queue_ints if queue_ints | length > 0 else phase_segments }}"
|
||||
segment_area_name_map:
|
||||
14: Kitchen
|
||||
12: "Dining Room"
|
||||
10: "Living Room"
|
||||
7: "Master Bedroom"
|
||||
15: Foyer
|
||||
9: "Stacey Office"
|
||||
13: Hallway
|
||||
8: "Justin Bedroom"
|
||||
6: "Paige Bedroom"
|
||||
4: "Master Bathroom"
|
||||
2: Office
|
||||
1: "Pool Bath"
|
||||
3: "Kids Bathroom"
|
||||
cleaning_area_ids: >
|
||||
{% set ns = namespace(ids=[]) %}
|
||||
{% for seg in segments_to_clean %}
|
||||
{% set area_name = segment_area_name_map.get(seg) %}
|
||||
{% set aid = area_id(area_name) if area_name else none %}
|
||||
{% if aid %}
|
||||
{% set ns.ids = ns.ids + [aid] %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ ns.ids }}
|
||||
segment_ids: "{{ segments_to_clean | list }}"
|
||||
|
||||
# 0. Reseed the current phase when queue is empty.
|
||||
- choose:
|
||||
@@ -192,19 +169,6 @@ script:
|
||||
- stop: 'No rooms left to clean today.'
|
||||
default: []
|
||||
|
||||
# 2b. Clean-area needs a mapped Home Assistant area ID for every segment
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ cleaning_area_ids | length != segments_to_clean | length }}"
|
||||
sequence:
|
||||
- service: script.send_to_logbook
|
||||
data:
|
||||
topic: "VACUUM"
|
||||
message: "Missing area mappings for one or more segments {{ segments_to_clean }}; skipping clean_area."
|
||||
- stop: "Incomplete Home Assistant area mappings."
|
||||
default: []
|
||||
|
||||
# 3. Start cleaning (but don't clobber an active job)
|
||||
- choose:
|
||||
- conditions:
|
||||
@@ -214,7 +178,7 @@ script:
|
||||
- service: script.send_to_logbook
|
||||
data:
|
||||
topic: "VACUUM"
|
||||
message: "Vacuum is already cleaning; queue/phase updated but not issuing a new clean_area action."
|
||||
message: "Vacuum is already cleaning; queue/phase updated but not issuing a new segment clean action."
|
||||
- stop: "Already cleaning."
|
||||
default: []
|
||||
|
||||
@@ -229,12 +193,12 @@ script:
|
||||
entity_id: vacuum.l10s_vacuum
|
||||
data:
|
||||
fan_speed: Standard
|
||||
- service: vacuum.clean_area
|
||||
- service: dreame_vacuum.vacuum_clean_segment
|
||||
target:
|
||||
entity_id: vacuum.l10s_vacuum
|
||||
data:
|
||||
# Clean mapped Home Assistant areas for this phase queue.
|
||||
cleaning_area_id: "{{ cleaning_area_ids }}"
|
||||
# Clean the queued room segments directly.
|
||||
segments: "{{ segment_ids }}"
|
||||
|
||||
|
||||
## 3. Automations
|
||||
@@ -347,8 +311,6 @@ automation:
|
||||
kids_bathroom: {segment: 3, name: 'Kids Bathroom', area: 'Kids Bathroom'}
|
||||
room_key: "{{ trigger.id }}"
|
||||
room_name: "{{ room_map[room_key].name }}"
|
||||
area_name: "{{ room_map[room_key].area }}"
|
||||
area_id_value: "{{ area_id(area_name) if area_name else none }}"
|
||||
segment_id: "{{ room_map[room_key].segment | int }}"
|
||||
vac_state: "{{ states('vacuum.l10s_vacuum') }}"
|
||||
on_demand: "{{ is_state('input_boolean.l10s_vacuum_on_demand', 'on') }}"
|
||||
@@ -358,7 +320,7 @@ automation:
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ can_start and area_id_value is not none }}"
|
||||
value_template: "{{ can_start and segment_id | int > 0 }}"
|
||||
sequence:
|
||||
- service: script.send_to_logbook
|
||||
data:
|
||||
@@ -377,17 +339,17 @@ automation:
|
||||
data:
|
||||
fan_speed: Standard
|
||||
- continue_on_error: true
|
||||
service: vacuum.clean_area
|
||||
service: dreame_vacuum.vacuum_clean_segment
|
||||
target:
|
||||
entity_id: vacuum.l10s_vacuum
|
||||
data:
|
||||
cleaning_area_id: "{{ [area_id_value] }}"
|
||||
segments: "{{ [segment_id] }}"
|
||||
- delay: "00:00:02"
|
||||
default:
|
||||
- service: script.send_to_logbook
|
||||
data:
|
||||
topic: "VACUUM"
|
||||
message: "One-off clean blocked: {{ room_name }} (area={{ area_name }}, area_id={{ area_id_value }}, vac={{ vac_state }}, on_demand={{ on_demand }}, queue='{{ queue_raw }}')."
|
||||
message: "One-off clean blocked: {{ room_name }} (segment={{ segment_id }}, vac={{ vac_state }}, on_demand={{ on_demand }}, queue='{{ queue_raw }}')."
|
||||
- service: input_boolean.turn_off
|
||||
data:
|
||||
entity_id: "{{ trigger.entity_id }}"
|
||||
|
||||
Reference in New Issue
Block a user