I'd like to switch a device off when the last person leaves home, and on when the first person enters.
I wrote the following automation, and I think it works. But it also doesn't seem quite right:
alias: Turn on lights if anyone is home
triggers:
- trigger: state
entity_id:
- zone.home
actions:
- if:
- condition: numeric_state
entity_id: zone.home
above: 0
then:
- action: switch.turn_on
target:
entity_id: switch.christmas_lights
else:
- action: switch.turn_off
target:
entity_id: switch.christmas_lights
For starters, I believe this will trigger everytime the state changes, e.g. from 1 to 2. I want it to only trigger if it crosses the threshold either from below to above (0 -> x) or from above to below (x -> 0).
Shouldn't there be a way to use the numeric_state trigger in the first place (instead of the state workaround)? But then how do I perform separate actions when the numeric state crosses above vs. below the threshold?