Hi team,
I’m just starting to wrap my head around more complicated automations, and I’m trying to build one that essentially only turns the light on when a. I am home, AND b. it’s between the hours of 06:00 and 23:00.
Based on one test, I think I’ve got something that works. But pretty sure I could simplify this if I could just wrap my head around how to use ELSE statements, i.e., IF user is home AND hours between 06:00 and 23:00 turn light on ELSE turn light off.
I have read pages and pages of documentation, and have managed to break (and restore) my Home Assistant a couple times already and just need someone to highlight what I’m missing.
Thanks in advance. Here’s the script I’ve got so far:
trigger:
- platform: state
entity_id:
- person.user1
to: home
for:
hours: 0
minutes: 5
seconds: 0
- platform: state
entity_id:
- person.user1
to: not_home
for:
hours: 0
minutes: 5
seconds: 0
- platform: time
at: "23:00:00"
- platform: time
at: "06:00:00"
condition: []
action:
- if:
- condition: state
entity_id: person.user1
state: not_home
- condition: or
conditions:
- condition: time
after: "06:00:00"
before: "23:00:00"
then:
- service: switch.turn_off
data: {}
target:
entity_id: switch.bad_light
- if:
- condition: state
entity_id: person.user1
state: home
- condition: time
after: "06:00:00"
before: "23:00:00"
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.bad_light
- if:
- condition: time
after: "23:00:00"
before: "06:00:00"
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.bad_light
mode: single