diff --git a/config/packages/vacuum.yaml b/config/packages/vacuum.yaml index f85a7215..29a710aa 100755 --- a/config/packages/vacuum.yaml +++ b/config/packages/vacuum.yaml @@ -7,6 +7,9 @@ # Related Issue: 1550 # 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 @@ -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'} 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) }}" - current_room_id: "{{ trigger.to_state.attributes.room_id | default(state_attr('sensor.l10s_vacuum_current_room', 'room_id'), true) | int(0) }}" - matched_room_id: "{{ current_room_id if current_room_id > 0 and current_room_id in (queue_ints | default([], true)) else 0 }}" + cleaned_room_state: "{{ trigger.to_state.state if trigger.to_state is not none else '' }}" + 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: > {% set rem = [] %} {% set removed = namespace(done=false) %} @@ -229,6 +233,9 @@ automation: next_phase: "{{ phase_order[phase_index + 1] if has_next_phase else '' }}" 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 value_template: "{{ queue_ints | length > 0 }}" - condition: template @@ -241,6 +248,9 @@ automation: state: 'on' 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 target: entity_id: input_text.l10s_vacuum_room_queue @@ -249,7 +259,7 @@ automation: - variables: cleaned_raw: "{{ states('input_text.l10s_vacuum_rooms_cleaned_today') | default('', true) | string }}" 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: > {% set parts = cleaned_parts %} {% if room_name not in parts %} @@ -265,11 +275,11 @@ automation: - service: script.send_to_logbook data: topic: "VACUUM" - message: "{{ room_name }} is clean. Phase: {{ phase }}. Remaining: {{ remaining_count }}." + message: "{{ room_name }} completed. Phase: {{ phase }}. Remaining: {{ remaining_count }}." - choose: - conditions: - condition: template - value_template: "{{ remaining_count > 0 }}" + value_template: "{{ remaining_count > 0 and not is_state('vacuum.l10s_vacuum', 'cleaning') }}" sequence: - service: script.l10s_vacuum_start_next_room - conditions: @@ -286,6 +296,9 @@ automation: entity_id: input_text.l10s_vacuum_room_queue data: 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 - conditions: - condition: template @@ -304,7 +317,10 @@ automation: - service: input_boolean.turn_off target: 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' id: 6548de52-a4a4-4df2-9d66-9c2c15577a7f