Hi everyone,
I am getting a strange behaviour when trying to set up an automation using a choose conditions for the resulting actions.
I want to check if the sun goes down and also is below an elevation of 2.
In that case I want to modify a switch to on state, otherwise it should turn off.
The conditions and trigger all match so that for the sake of simplicty I am removing them.
The statement that acts strange is the check for the boolean state attribute “rising” of “sun.sun”.
alias: Turn my switch on/off
description: ''
trigger: []
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: '2'
- condition: state
entity_id: sun.sun
state: 'false'
attribute: rising
sequence:
- type: turn_on
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
- conditions:
- condition: state
entity_id: sun.sun
state: 'true'
attribute: rising
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: '-4'
sequence:
- type: turn_on
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
default:
- type: turn_off
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
mode: single
It does not matter what I try the result is always that the switch is off even if the conditions are matching.
I tried to write the state in different formats (“true”, “True”, “1”) but none seems to be working.
If I change the condition types for “state” to template using the following pattern it works like a charm:
alias: Turn my switch on/off
description: ''
trigger: []
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: '2'
- condition: template
value_template: '{{state_attr("sun.sun", "rising") == false}}'
sequence:
- type: turn_on
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
- conditions:
- condition: template
value_template: '{{state_attr("sun.sun", "rising") == true}}'
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: '-4'
sequence:
- type: turn_on
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
default:
- type: turn_off
device_id: 1234567890
entity_id: switch.my_switch
domain: switch
mode: single
Any idea what I am missing or doing wrong when using the state?