I am making an automation that has to switch devices on and off based on presence and the state of the sun.
Instead of making one for switching on and one (or more) for swiching off, I was wandering if i could do it with only one, were I use the outcome of the condition as a state, switch_on when true, and switch_off when not true.
This is what I have so far:
whenever one of the 3 entity’s changes state it detects that and check’s if the conditions passe or not
that works fine, only think I do not know is how to turn devices off, if conditions are not passed.
alias: test
description: ""
trigger:
- platform: state
entity_id:
- device_tracker.telefoon_dick
- device_tracker.telefoon_esther
- sun.sun
condition:
- condition: and
conditions:
- condition: or
conditions:
- condition: state
entity_id: device_tracker.telefoon_dick
state: home
- condition: state
entity_id: device_tracker.telefoon_esther
state: home
- condition: sun
before: sunset
after: sunrise
action:
- service: switch. # turn on when condition is met, turn off when not!
data: {}
target:
entity_id: switch.mf_fountain_on
mode: single
Remove everything from the conditions section of the automation.
Then, use an if-then-else action. The condition for this can be your original condition. The ‘else’ actions will handle what happens when your condition is not met.