Labels and Conditionals

I have switched back to native automations in Home Assistant from using Node Red for a while and i really like how its becoming now.

I try to use labels for most of my devices and entities, and automate based on the label/tags. For example i do have assigned two tags two all my curtains “Curtains” and “Common area curtains”

Based on the modus of the house, if i select home (from beeing away) all curtiains with the label “curtains” is opening. However while beeing home i would only curtains in the common area, meaning only partials of the curtains of the total should follow a schedule.

This works mostly, but i would like to add some conditionals to make sure that the automation succeeds 100%. I have some issues due to silabs 700/800 chips but have a workaround for pinging dead nodes.

I fail to find a way to use the labels as conditionals for automations. Is it something i am overlooking, or could i do this someway else? Could i create a dynamic sensor based on the labels and then use that in the conditionals in automations? Not sure where to go from here

It might help get an answer if you could clarify how you want to use the labels in conditional logic and include an example automation or script.

There are a number of Label-related functions available through Templating which can be used in Template conditions or in actions.

Lets say that based on my intial description we are now Home, and the house is now in Home Mode.

Only partial of all of my blinds should follow the schedule based on time. However since i have some communication issues on z-wave i allready know that on the first attempt mostly 20-30% of the blinds will fail. But this ask is not only unique to z-wave but more towards errorhandling and to be able to guarantee that an native automation is actually succeeded and has a state equal to the automation`s ask.

Ideally i would like to add a conditional based on the same label, something more robust than using repeat. For example “until” all labels “Common are curtinas” = open, as long as the action is “open”. As long as I use the same label for doing the actual automation.

alias: When Home, close curtains 2300 in common area
description: ""
triggers:
  - trigger: time
    at: "23:00:00"
conditions:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.home
        state: "on"
actions:
  - action: cover.close_cover
    data: {}
    target:
      label_id: curtain_common_area
mode: single

Unless your curtains’ integration provides some special action, Repeat is probably your only option. Some users have reported more reliable results with curtains by sending commands to each entity in sequence. With that in mind, you might consider nesting repeats like:

alias: Repeat actions until all Common Area Curtains are closed
repeat:
  until:
    - condition: template
      value_template: |
        {{ label_entities('curtain_common_area') | select('match', 'cover.') 
        | select('is_state', 'open') | list | count == 0 }}
  sequence:
    - alias: Send "close" command to "open" curtains one-by-one 
      repeat:
        for_each: |
          {{ label_entities('curtain_common_area') | select('match', 'cover.') | select('is_state', 'open') | list }}
        sequence:
          - action: cover.close_cover
            data: {}
            target:
              label_id: "{{ repeat.item }}"
          - alias: delay between action calls
            delay:
              milliseconds: 200
    - alias: Delay before checking if still open
      delay:
        seconds: 10

Its`s not possible to create sensors based on labels? for examples “all common area blinds sensor” and then as long as its not true (all open/closed) then repeat the automation?

Yes, you can use the same template I used above to create a binary sensor.

{{ label_entities('curtain_common_area') | select('match', 'cover.') 
| select('is_state', 'open') | list | count == 0 }}

Thank @Didgeridrew, i belive that would solve my usecase for now.

Ideally using labels for conditinal check would be more streamlined, but that might be an option in the future.