Seting a value to a custom component variable

Hello, im having a little bit trouble understanding a template. Im using this behaviour to control in which rooms the vacuum will clean. Everything works as expected, when i press one of the buttons the notification displays the correct number, the vacuum goes where i told it to etc.
The problem comes when it finishes the cleaning - I want to reset all the buttons’ states to 0 so they dont display the notification. Any idea how can I do that? The script that adds/removes rooms from the variable is this:

deebot_room_queue:
  description: Add/Remove a room from the queue
  fields:
    queue:
      description: The queue variable
      example: hans_queue
    room:
      description: Room, which should be removed or added
      example: kitchen
  sequence:
    - service: variable.set_variable
      data:
        variable: "{{ queue }}"
        value: >-
          {%- set queue = states("variable.hans_queue").split(",") -%}
          {%- if states("variable.hans_queue") | length == 0 -%}
            {{ room }}
          {%- elif room in queue -%}
            {{ queue | reject("eq", room) | list | join(",")}}
          {%- else -%}
            {{ (queue + [room]) | join(",") }}
          {%- endif -%}

But i cant seem to figure out how it works so I can use it for my scenario. Any help would be appreciated. This is the variable component that i use

Rather than trying to change anything here, could you have a separate automation that monitors the vacuum’s state and clears the list when it is done cleaning?

in your example and on the linked sites i only see all buttons set to 0 when HA restarts.
Edit: and of course with the posted script, when you press the card from UI

template:
  unique_id: deebot_susi_queue
  trigger:
    - platform: homeassistant
      event: start
    - platform: state
      entity_id: variable.deebot_susi_queue
  sensor:
    # Add for each room the following. Change "living_room" accordingly
    - unique_id: deebot_susi_queue_living_room
      name: deebot_susi_queue_living_room
      state: >
        {% set queue = trigger.to_state.state.split(",") if trigger.to_state is defined else "" %}
        {{ queue.index('living_room')+1 if 'living_room' in queue else 0 }}

queue is then " "

{% set queue = trigger.to_state.state.split(",") if trigger.to_state is defined else "" %}

and the room 0

{{ queue.index('living_room')+1 if 'living_room' in queue else 0 }}

does your vacuum have a sensor exposed in HA that reports in some kind when he finished his job like deebot here Entities - DeebotUniverse when the state reports that he finished?

you could then try to set an additional trigger like this (below is just an expample how it could look like)

template:
  unique_id: deebot_susi_queue
  trigger:
    - platform: homeassistant
      event: start
    - platform: state
      entity_id: variable.deebot_susi_queue
    - platform: state
      entity_id: sensor.last_cleaning_job
      to: "finished"

@r-j-taylor

Rather than trying to change anything here, could you have a separate automation that monitors the vacuum’s state and clears the list when it is done cleaning?

yes Im trying to the exact same thing :smiley:

@florian.ec

does your vacuum have a sensor exposed in HA that reports in some kind when he finished his job

Yes it has. Based on that i’ve created this automation:

- id: ''
  alias: Clean Room Queue
  description: ''
  trigger:
  - platform: device
    device_id: b8ee12367e7617eedf918dd46923fbfb
    domain: vacuum
    entity_id: vacuum.hans
    type: docked
  condition: []
  action:
  - service: script.clear_room_queue
  mode: single

and here is the script in which I can’t figure out what to do :sweat_smile:

clear_room_queue:
  description: Resets all the rooms that have been put into the cleaning queue
  sequence:
    - service: variable.set_variable
      data:
        variable: variable.hans_queue
        value: >
          {{ 0 }}

ok :grinning: i think setting the value to “” should work and you only have to set the variable name in the service call, not the entity.

clear_room_queue:
  description: Resets all the rooms that have been put into the cleaning queue
  sequence:
    - service: variable.set_variable
      data:
        variable: hans_queue
        value: ""

Yes, that worked excellent ! Thank you very much !