I have a YAML puzzle, and it’s the conditions section that has me stumped. I’ve made multiple attempts at revising, but so far no luck. I probably just need a fresh pair of eyes.
FWIW, this is related to an automation for the house night time security routine. It’s used it when one or both of my sons is out late. If we accidentally arm the house for bedtime while they’re away, we get a warning message.
Here’s the logic I’m after:
When switch.main_stairs_nighttime_security turns on,
If date_night is off
and if son 1 is away
or son 2 is away and he’s not at the University
Then announce the warning
First version of the code (anonymized a bit):
- alias: Bed Time Warning
initial_state: on
trigger:
- platform: state
entity_id: switch.main_stairs_nighttime_security
to: "on"
conditions:
- condition: state
entity_id: input_boolean.date_night
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: switch.pres_son_1
state: "off"
- condition: and
conditions:
- condition: state
entity_id: switch.pres_son_2
state: "off"
- condition: not
conditions:
- condition: state
entity_id: device_tracker.son_2_phone
state: "University"
action:
# ...
Second version (conditions only):
conditions:
- condition: state
entity_id: input_boolean.date_night
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: switch.pres_son_1
state: "off"
- condition: and
conditions:
- condition: state
entity_id: switch.pres_son_2
state: "off"
- condition: not
condition: state
entity_id: device_tracker.son_2_phone
state: "University"
action:
# ...
Third version:
conditions:
- condition: state
entity_id: input_boolean.date_night
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: switch.pres_son_1
state: "off"
- condition: template
value_template: >
{{ states('switch.pres_son_2') == 'off' and not is_state('device_tracker.son_2_phone', 'University') }}
action:
# ...
Fourth version:
conditions:
- condition: state
entity_id: input_boolean.date_night
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: switch.pres_son_1
state: "off"
- condition: template
value_template: "{{ states('switch.pres_son_2') == 'off' and not is_state('device_tracker.son_2_phone', 'University') }}"
action:
# ...
I can’t promise that the error message in the logs has been the same each time, but it’s always concerning the conditions, something like this:
Automation with alias 'Bed Time Warning' could not be validated and has been disabled: extra keys not allowed @ data['conditions']. Got [{'condition': 'state', 'entity_id': 'input_boolean.date_night', 'state': 'off'}, {'condition': 'or', 'conditions': [{'condition': 'state', 'entity_id': 'switch.pres_son_1', 'state': 'off'}, {'condition': 'template', 'value_template': "{{ states('switch.pres_son_2') == 'off' and not is_state('device_tracker.son_2_phone', 'University') }}"}]}]
Any help appreciated.