I´m a beginner and I dont know if the following is even possible.
Long story short:
i want to combine 2 simple Automations into 1
alias: lighttest off
description: ''
trigger:
- platform: state
entity_id: input_boolean.test
to: 'off'
condition:
- condition: state
entity_id: input_boolean.test
state: 'off'
action:
- service: light.turn_on
data:
transition: 7
color_name: red
target:
entity_id: light.wled_2
mode: single
and
alias: lighttest on
trigger:
- platform: state
entity_id: input_boolean.test
to: 'on'
condition:
- condition: state
entity_id: input_boolean.test
state: 'on'
action:
- service: light.turn_on
data:
transition: 7
color_name: green
target:
entity_id: light.wled_2
mode: single
so either the light is green or red.
I´m not sure if I´m completly wrong or if this isnt even possible.
(can do it with node red but it´s slow as hell…)
Could someone point out what to do or show me the tutorial i´m missing?
alias: lighttest
description: ''
trigger:
- platform: state
entity_id: input_boolean.test
to:
- 'on' # trigger on either state. We could also leave to: out to trigger on all states but that might trigger on 'unavailable'
- 'off'
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.test
state: 'off'
sequence: # do this if the test input boolean is off
- service: light.turn_on
data:
transition: 7
color_name: red
target:
entity_id: light.wled_2
default: # do this if the test input boolean is not off (it must be on, because of the two trigger states specified)
- service: light.turn_on
data:
transition: 7
color_name: green
target:
entity_id: light.wled_2
mode: single
Another way to write it with choose
alias: lighttest
description: ''
trigger:
- platform: state
entity_id: input_boolean.test # no to: or from: specified -> trigger on all state or attribute changes of the entity
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.test
state: 'off'
sequence: # do this only if the test input boolean is off
- service: light.turn_on
data:
transition: 7
color_name: red
target:
entity_id: light.wled_2
- choose:
- conditions:
- condition: state
entity_id: input_boolean.test
state: 'on'
sequence: # do this only if the test input boolean is on
- service: light.turn_on
data:
transition: 7
color_name: red
target:
entity_id: light.wled_2
mode: single
The template version would look like this:
alias: lighttest
description: ''
trigger:
- platform: state
entity_id: input_boolean.test
to:
- 'on' # trigger on either state. We could also leave to: out to trigger on all states but that might trigger on 'unavailable'
- 'off'
action:
- service: light.turn_on
data:
transition: 7
color_name: "{{ 'red' if is_state('input_boolean.test', 'off') else 'green' }}"
target:
entity_id: light.wled_2
mode: single
You can read more about templates here: Templating
NOTE: listing trigger to: states like I did above only works in YAML and does not work in the UI automation editor. You have to use this instead:
trigger:
- platform: state
entity_id: input_boolean.test
to: 'on'
- platform: state
entity_id: input_boolean.test
to: 'off'
That’s because the default block is indented too far. It should line up with choose:. My mistake.
Can you see why?
It is a simple mistake in the sequence of choose actions you should be able to spot. Try to learn from this rather than just copying things you don’t understand.