I have a state trigger using several input_booleans. As a result of any of them changing their state to “on” I would like to switch all others to “off”.
I cant seem to find a way to reference the entire list of trigger entity ids though (in order to set the corresponding booleans to “off”) but only the boolean triggering/changing it’s state to “on” via trigger.entity_id.
I feel like I am missing something really obvious. Anybody know how to generate/reference all triggers? Or is there a more elegant way manipulate “all others”?
I realized that you cannot use templates in the trigger statement? Then at least we could’ve avoided the double manual entry.
I will eventually try to make it so that I have to enter the list of booleans only once and preferably via the GUI for its selection and typo-avoidance capabilities .
If anyone has any suggestions to move in those directions that’d be most welcome
In the meantime I found a way to just draw all entity ids from states and filter them. That kind of shifts the problem to a more rigorous naming convention (I’m filtering for all input booleans that are “tagged” Room Occupation), but I’m confident I need that anyways.
That way I can use the GUI to add the triggers (technically I could use your approach + the filter to populate that list, automatically, too - so I’d only have to create the booleans) which at this point feels more convenient.
alias: Turn Off Other Input Booleans
trigger:
platform: state
entity_id:
- input_boolean.room_occupation_basement
- input_boolean.room_occupation_bathroom_downstairs
- input_boolean.room_occupation_bathroom_upstairs
- input_boolean.room_occupation_bedroom
- input_boolean.room_occupation_gaming_room
- input_boolean.room_occupation_kitchen
- input_boolean.room_occupation_living_room
- input_boolean.room_occupation_office
- input_boolean.room_occupation_stairs
action:
- service: input_boolean.turn_off
target:
entity_id: >
{% set triggering_id = trigger.entity_id %}
{% set filtered_ids = states | selectattr('entity_id', 'match', '^input_boolean\.room_occupation_.*') | map(attribute='entity_id') | reject('eq', triggering_id) | list %}
{{ filtered_ids | join(', ') }}