Blueprints, lists & selectors

Hi,
I am trying my first texts with blueprints and automation.

I want to make a blueprint that:

  1. takes a list of entities (switch)
  2. when you turn on one of them, it turns off all the others.

Maybe it’s something that can be done in a different way, but that’s not the point, I want to learn how to do it using blueprints.

I am trying something like this.

blueprint:
  name: Alternative switches
  domain: automation
  input:
    switchList:
      name: List of switches
      selector:
        entity:
          domain: switch
          multiple: true
trigger:
  - platform: state
    entity_id: !input switchList
    to: "on"
action:
  - service: switch.turn_off
    #entity_id: !input switchList
    entity_id: {{ (!input switchList) | recject("equalto",trigger.entity_id) }}
mode: single

When I set action to entity_id: !input switchList, of course it works.

I want to exclude the the entity that triggered the automation.
But when I try:

entity_id: {{ (!input switchList) | recject("equalto",trigger.entity_id) }}

everything stops working.

Thanks,
Roberto

OK I found a solution myself.

you cant use a !input variable in a template.
First you need to declare it in the variables section.
And also the template needed fixing:

blueprint:
  name: Switch alternativi
  description: Rende due switch alternativi
  domain: automation
  input:
    switchList:
      name: List of switches
      selector:
        entity:
          domain: switch
          multiple: true
variables:
  switches: !input switchList
trigger:
  - platform: state
    entity_id: !input switchList
    to: "on"
action:
  - service: switch.turn_off
    target:
      entity_id: '{{ expand(switches) | selectattr("entity_id", "!=", trigger.entity_id) | map(attribute="entity_id") | list }}'
mode: single
2 Likes