Enhance vacuum automation logic by refining room state tracking and adding wait conditions to ensure proper phase transitions. Update logbook messages for clarity and improve handling of cleaning state changes.

This commit is contained in:
Carlo Costanzo
2025-12-15 10:41:57 -05:00
parent 7a6491709b
commit 69edb0658d

View File

@@ -7,6 +7,9 @@
# Related Issue: 1550 # Related Issue: 1550
# Phases: sweep main, sweep baths, mop main, mop baths; notifications + idle auto-start # Phases: sweep main, sweep baths, mop main, mop baths; notifications + idle auto-start
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# Notes:
# - `sensor.l10s_vacuum_current_room` can change during transit; require a dwell (`for:`) and then wait for the vacuum to leave before dequeue/phase advance.
# - Avoid reissuing `dreame_vacuum.vacuum_clean_segment` while already cleaning; only send a new segment job when starting/resuming or switching phases.
###################################################################### ######################################################################
## 1. Helpers ## 1. Helpers
@@ -206,8 +209,9 @@ automation:
room_map: {14:'kitchen',12:'dining-room',10:'living room',7:'master-bedroom',15:'foyer',9:'stacey-office',17:'formal-dining',13:'hallway',8:'justin-bedroom',6:'paige-bedroom',4:'master-bathroom',2:'office',1:'pool-bath',3:'kids-bathroom'} room_map: {14:'kitchen',12:'dining-room',10:'living room',7:'master-bedroom',15:'foyer',9:'stacey-office',17:'formal-dining',13:'hallway',8:'justin-bedroom',6:'paige-bedroom',4:'master-bathroom',2:'office',1:'pool-bath',3:'kids-bathroom'}
queue_raw: "{{ states('input_text.l10s_vacuum_room_queue') | default('', true) | string | replace(' ', '') }}" queue_raw: "{{ states('input_text.l10s_vacuum_room_queue') | default('', true) | string | replace(' ', '') }}"
queue_ints: "{{ queue_raw | regex_findall('[0-9]+') | map('int') | list | default([], true) }}" queue_ints: "{{ queue_raw | regex_findall('[0-9]+') | map('int') | list | default([], true) }}"
current_room_id: "{{ trigger.to_state.attributes.room_id | default(state_attr('sensor.l10s_vacuum_current_room', 'room_id'), true) | int(0) }}" cleaned_room_state: "{{ trigger.to_state.state if trigger.to_state is not none else '' }}"
matched_room_id: "{{ current_room_id if current_room_id > 0 and current_room_id in (queue_ints | default([], true)) else 0 }}" cleaned_room_id: "{{ (trigger.to_state.attributes.room_id if trigger.to_state is not none else 0) | int(0) }}"
matched_room_id: "{{ cleaned_room_id if cleaned_room_id > 0 and cleaned_room_id in (queue_ints | default([], true)) else 0 }}"
remaining_list: > remaining_list: >
{% set rem = [] %} {% set rem = [] %}
{% set removed = namespace(done=false) %} {% set removed = namespace(done=false) %}
@@ -229,6 +233,9 @@ automation:
next_phase: "{{ phase_order[phase_index + 1] if has_next_phase else '' }}" next_phase: "{{ phase_order[phase_index + 1] if has_next_phase else '' }}"
condition: condition:
- condition: template
value_template: >
{{ trigger.from_state is not none and trigger.to_state is not none and trigger.from_state.state != trigger.to_state.state }}
- condition: template - condition: template
value_template: "{{ queue_ints | length > 0 }}" value_template: "{{ queue_ints | length > 0 }}"
- condition: template - condition: template
@@ -241,6 +248,9 @@ automation:
state: 'on' state: 'on'
action: action:
- wait_template: "{{ states('sensor.l10s_vacuum_current_room') != cleaned_room_state }}"
timeout: '02:00:00'
continue_on_timeout: false
- service: input_text.set_value - service: input_text.set_value
target: target:
entity_id: input_text.l10s_vacuum_room_queue entity_id: input_text.l10s_vacuum_room_queue
@@ -249,7 +259,7 @@ automation:
- variables: - variables:
cleaned_raw: "{{ states('input_text.l10s_vacuum_rooms_cleaned_today') | default('', true) | string }}" cleaned_raw: "{{ states('input_text.l10s_vacuum_rooms_cleaned_today') | default('', true) | string }}"
cleaned_parts: "{{ cleaned_raw | regex_findall('[^,]+') | map('trim') | reject('equalto','') | list }}" cleaned_parts: "{{ cleaned_raw | regex_findall('[^,]+') | map('trim') | reject('equalto','') | list }}"
room_name: "{{ room_map.get(matched_room_id, states('sensor.l10s_vacuum_current_room')) }}" room_name: "{{ room_map.get(matched_room_id, cleaned_room_state) }}"
updated_cleaned: > updated_cleaned: >
{% set parts = cleaned_parts %} {% set parts = cleaned_parts %}
{% if room_name not in parts %} {% if room_name not in parts %}
@@ -265,11 +275,11 @@ automation:
- service: script.send_to_logbook - service: script.send_to_logbook
data: data:
topic: "VACUUM" topic: "VACUUM"
message: "{{ room_name }} is clean. Phase: {{ phase }}. Remaining: {{ remaining_count }}." message: "{{ room_name }} completed. Phase: {{ phase }}. Remaining: {{ remaining_count }}."
- choose: - choose:
- conditions: - conditions:
- condition: template - condition: template
value_template: "{{ remaining_count > 0 }}" value_template: "{{ remaining_count > 0 and not is_state('vacuum.l10s_vacuum', 'cleaning') }}"
sequence: sequence:
- service: script.l10s_vacuum_start_next_room - service: script.l10s_vacuum_start_next_room
- conditions: - conditions:
@@ -286,6 +296,9 @@ automation:
entity_id: input_text.l10s_vacuum_room_queue entity_id: input_text.l10s_vacuum_room_queue
data: data:
value: "" value: ""
- wait_template: "{{ not is_state('vacuum.l10s_vacuum', 'cleaning') }}"
timeout: '01:00:00'
continue_on_timeout: false
- service: script.l10s_vacuum_start_next_room - service: script.l10s_vacuum_start_next_room
- conditions: - conditions:
- condition: template - condition: template
@@ -304,7 +317,10 @@ automation:
- service: input_boolean.turn_off - service: input_boolean.turn_off
target: target:
entity_id: input_boolean.l10s_vacuum_on_demand entity_id: input_boolean.l10s_vacuum_on_demand
- service: script.l10s_vacuum_start_next_room - service: vacuum.return_to_base
target:
entity_id: vacuum.l10s_vacuum
default: []
- alias: 'Vacuum Sensor Cleaning Silencer' - alias: 'Vacuum Sensor Cleaning Silencer'
id: 6548de52-a4a4-4df2-9d66-9c2c15577a7f id: 6548de52-a4a4-4df2-9d66-9c2c15577a7f