I have two input boolean switches: “Relax” and “Work”.
Right now, I use two automations and I would like to use only one!
Is it possible ?
1 Like
petro
(Petro)
June 19, 2018, 5:00pm
2
alias: blah
trigger:
- platform: state
entity_id: input_boolean.svegliarelax, input_boolean.svegliawork
from: 'off'
to: 'on'
action:
service: input_boolean.turn_off
data_template:
entity_id: >
{% set booleans = [ 'input_boolean.svegliarelax', 'input_boolean.svegliawork' ] | reject('equalto', trigger.entity_id) | list %}
{{ booleans[0] }}
This will only work for a pair of input booleans. If you want to do this with more input_booleans:
alias: blah
trigger:
- platform: state
entity_id: input_boolean.svegliarelax, input_boolean.svegliawork, input_boolean.other
from: 'off'
to: 'on'
action:
service: input_boolean.turn_off
data_template:
entity_id: >
{% set booleans = [ 'input_boolean.svegliarelax', 'input_boolean.svegliawork','input_boolean.other' ] | reject('equalto', trigger.entity_id) %}
{{ booleans | list | join(', ') }}
7 Likes
Thanks @petro !
I get:
ERROR (MainThread) [homeassistant.core] Invalid service data for input_boolean.turn_off: Entity ID is an invalid entity id for dictionary value @ data['entity_id']. Got ''
petro
(Petro)
June 21, 2018, 11:47am
4
Which method did you use?
Edit: I adjusted the top method, it had an issue.
woodmj74
(Mike Wood)
November 23, 2020, 12:53pm
6
Brilliant - thank you for this @petro . Cut a growing automation down a single action. Simplistic and beautiful
1 Like