I tried to setup an automation to turn off our porch light after 5 mins of no activity but only outside of its On schedule which is sunset to 11 pm) - but it never fires…
Any ideas?
- alias: Turn off Porch light 5 minutes after last doorbell movement
trigger:
platform: state
entity_id: binary_sensor.ring_frontdoor_motion
to: 'off'
from: 'on'
for:
minutes: 5
condition:
condition: and
conditions:
- condition: time
after: '23:04:00'
- condition: sun
before: sunrise
action:
service: homeassistant.turn_off
entity_id: switch.PorchLight
- alias: Turn off Porch light 5 minutes after last Floodlight movement
trigger:
platform: state
entity_id: binary_sensor.ring_frontfloodlight_motion
to: 'off'
from: 'on'
for:
minutes: 5
condition:
condition: and
conditions:
- condition: time
after: '23:04:00'
- condition: sun
before: sunrise
action:
service: homeassistant.turn_off
entity_id: switch.PorchLight
The problem is the condition will never be met. The way you wrote it it means between 23:04:00 and midnight, AND between midnight and sunrise. That can never happen. What you want is to OR the two conditions. And (at least given your initial description) I think you want sunset, not sunrise. Lastly, you can do this with just one automation (each entity will effectively have its own 5 minute ‘off’ timer):
- alias: Turn off Porch light 5 minutes after last doorbell or Floodlight movement
trigger:
platform: state
entity_id:
- binary_sensor.ring_frontdoor_motion
- binary_sensor.ring_frontfloodlight_motion
from: 'on'
to: 'off'
for:
minutes: 5
condition:
condition: or
conditions:
- condition: time
after: '23:04:00'
- condition: sun
before: sunset
action:
service: switch.turn_off
entity_id: switch.PorchLight