mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-12-03 11:31:42 +00:00
Refactor vacuum automation logic for improved room queue handling
- Updated vacuum.yaml to streamline the processing of room queues and enhance the logic for determining the next room to clean. - Replaced multiple variables with a more efficient approach using regex for room identification and queue management. - Simplified the remaining rooms logic to improve clarity and maintainability of the automation conditions.
This commit is contained in:
@@ -204,38 +204,38 @@ automation:
|
|||||||
for: '00:03:00'
|
for: '00:03:00'
|
||||||
variables:
|
variables:
|
||||||
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') | string | replace(' ', '') }}"
|
queue_ints: >
|
||||||
queue_list: "{{ queue_raw.split(',') if queue_raw | length > 0 else [] }}"
|
{% set queue = states('input_text.l10s_vacuum_room_queue') | default('', true) | string | replace(' ', '') %}
|
||||||
queue_ints: "{{ queue_list | map('int') | list }}"
|
{% if queue %}
|
||||||
next_room_id: "{{ queue_list[0] | int(0) if queue_list | length > 0 else 0 }}"
|
{{ queue | regex_findall('[0-9]+') | map('int') | list }}
|
||||||
current_room_id: "{{ state_attr('sensor.l10s_vacuum_current_room', 'room_id') | int(0) }}"
|
|
||||||
next_room_name: "{{ room_map.get(next_room_id, '') }}"
|
|
||||||
current_room_name: "{{ states('sensor.l10s_vacuum_current_room') | lower | replace('-', ' ') }}"
|
|
||||||
name_match: "{{ next_room_name | lower | replace('-', ' ') }}"
|
|
||||||
matched_room_id: >
|
|
||||||
{% set target = 0 %}
|
|
||||||
{% if current_room_id in queue_ints %}
|
|
||||||
{% set target = current_room_id %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for r in queue_ints %}
|
[]
|
||||||
{% set nm = room_map.get(r, '') | lower | replace('-', ' ') %}
|
|
||||||
{% if nm != '' and nm in current_room_name %}
|
|
||||||
{% set target = r %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
current_room_id: >
|
||||||
{% endif %}
|
{% set trigger_room_id = trigger.to_state.attributes.room_id if trigger.to_state and trigger.to_state.attributes and 'room_id' in trigger.to_state.attributes else none %}
|
||||||
{{ target }}
|
{% set sensor_room_id = state_attr('sensor.l10s_vacuum_current_room', 'room_id') %}
|
||||||
|
{{ (trigger_room_id if trigger_room_id is not none else sensor_room_id) | int(0) }}
|
||||||
|
matched_room_id: >
|
||||||
|
{% set q = queue_ints %}
|
||||||
|
{% set cur = current_room_id %}
|
||||||
|
{{ cur if cur > 0 and cur in q else 0 }}
|
||||||
remaining_rooms: >
|
remaining_rooms: >
|
||||||
|
{% set m = matched_room_id %}
|
||||||
|
{% set q = queue_ints %}
|
||||||
|
{% if m == 0 %}
|
||||||
|
{{ q | join(',') }}
|
||||||
|
{% else %}
|
||||||
|
{% set found = false %}
|
||||||
{% set rem = [] %}
|
{% set rem = [] %}
|
||||||
{% set removed = namespace(done=false) %}
|
{% for r in q %}
|
||||||
{% for r in queue_ints %}
|
{% if not found and r == m %}
|
||||||
{% if not removed.done and r == matched_room_id %}
|
{% set found = true %}
|
||||||
{% set removed.done = true %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set rem = rem + [r] %}
|
{% set rem = rem + [r] %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ rem | join(',') }}
|
{{ rem | join(',') }}
|
||||||
|
{% endif %}
|
||||||
condition:
|
condition:
|
||||||
- condition: template
|
- condition: template
|
||||||
value_template: "{{ queue_ints | length > 0 }}"
|
value_template: "{{ queue_ints | length > 0 }}"
|
||||||
@@ -247,12 +247,6 @@ automation:
|
|||||||
action:
|
action:
|
||||||
- condition: template
|
- condition: template
|
||||||
value_template: >
|
value_template: >
|
||||||
{% set head = (states('input_text.l10s_vacuum_room_queue') | string | replace(' ', '')).split(',')[0] if states('input_text.l10s_vacuum_room_queue') | length > 0 else '' %}
|
|
||||||
{% set head_int = head | int(0) %}
|
|
||||||
{% set head_name = room_map.get(head_int, '') %}
|
|
||||||
{% set current_id = state_attr('sensor.l10s_vacuum_current_room', 'room_id') | int(0) %}
|
|
||||||
{% set current_name = states('sensor.l10s_vacuum_current_room') | lower | replace('-', ' ') %}
|
|
||||||
{% set name_match_check = head_name | lower | replace('-', ' ') %}
|
|
||||||
{{ is_state('vacuum.l10s_vacuum', 'cleaning') and matched_room_id != 0 }}
|
{{ is_state('vacuum.l10s_vacuum', 'cleaning') and matched_room_id != 0 }}
|
||||||
- service: input_text.set_value
|
- service: input_text.set_value
|
||||||
target:
|
target:
|
||||||
|
|||||||
Reference in New Issue
Block a user