Porchlight off with no motion for 5 mins

Hi All

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

Try splitting the condition:
From 23::00 To 23:59:59 or 00:00:01 To sunrise.

1 Like

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
1 Like

I’ll try this when I get home

Didn’t know about the double entity thing

So it is 23.04 to sunrise I want the motion as there is a different schedule for the light to be on from sunset to 23.00.

More of a way to save energy and have it come on from the occasional time I’m out later than 23.00

Thanks guys

I’ve seen a bunch of threads dealing with time and sun conditions lately. the common theme seems to be confusion about the way those things work.

time after and before and sunset and sunrise are always in relationship to midnight.

So after 23:04 means between 23:04 and midnight. Before 23:04 means between midnight the night before and 23:04.

Sunrise is the same way. Before sunrise means between midnight and sunrise and after sunrise means between sunrise and the next midnight.

After sunset would only be true if it was between sunset and midnight.

1 Like

If I wanted to delay the sunrise condition by an hour.

Eg sunrise is 8:00am but I want the condition to be +1hour so 9am

What would I set the condition too? Would it be before_offset or after_offset? And ‘01:00:00’ or ‘-01:00:00’

Sorry but this stuff is quite hard to test

If you’re using before sunrise then you use before_offset. If the offset is later than sunrise then it should be positive, so 01:00:00.

1 Like