- 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.
{% 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 %}
{% 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:>
{% set m = matched_room_id %}
{% set q = queue_ints %}
{% if m == 0 %}
{{q | join(',') }}
{% else %}
{% set found = false %}
{% set rem = [] %}
{% set removed = namespace(done=false) %}
{% for r in queue_ints %}
{% if not removed.done and r == matched_room_id %}
{% set removed.done = true %}
{% for r in q %}
{% if not found and r == m %}
{% set found = true %}
{% else %}
{% set rem = rem + [r] %}
{% endif %}
{% endfor %}
{{rem | join(',') }}
{% endif %}
condition:
- condition:template
value_template:"{{ queue_ints | length > 0 }}"
@ -247,12 +247,6 @@ automation:
action:
- condition: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) %}