Motion automation after specific time

Hi all,

I’ve got a motion sensor in my garden which I want to use to trigger the light outside. I thought I had it dialed in, but no luck this morning.

The idea is: An outdoor Hue light is triggered at sunset to turn on. That works fine. It will then be on all the time, the motion sensor will not affect it. But here’s the catch; at midnight (00:00) the light should turn off (since I’m most likely sleeping and I don’t need it anymore). But when there’s motion after midnight it should turn on the lights until the motion sensor no longer detected movement. It should do this until sunrise.

  • action:
    • data:
      entity_id: light.hue_outdoor_wall
      service: light.turn_on
      alias: Movement on
      condition: and
      • condition: time
        after: ‘00:00:00’
      • condition: state
        entity_id: sun.sun
        state: ‘below_horizon’
        id: ‘1515321712072’
    • entity_id: binary_sensor.motion_sensor
      platform: state
      to: ‘on’

The problem with this is that it also turns on and off (I also have a 99% identical automation to turn OFF the light) during the period that it should be on all the time (sunset - midnight).

I tried the 23:59 time yesterday, but that resulted in the light not turning on this morning. That made sense since it’s not passed 23:59.

Would be great if someone could help me in the right direction!


- alias: Garden light on at sunset
    platform: sun
    event: sunset
    service: light.turn_on
    entity_id: light.hue_outdoor_wall
- alias: Garden light off at midnight
    platform: time
    at: '00:00:00'
    service: light.turn_off
    entity_id: light.hue_outdoor_wall
- alias: Garden light on with motion after midnight
    platform: state
    entity_id: binary_sensor.motion_sensor
    to: 'on'
    # This means between midnight and sunrise
    condition: sun
    before: sunrise
    - service: script.turn_off
      entity_id: script.garden_light
    - service: script.garden_light


    - service: light.turn_on
      entity_id: script.garden_light
    - wait_template: "{{ is_state('binary_sensor.motion_sensor', 'off') }}"
    - service: light.turn_off
      entity_id: light.hue_outdoor_wall

Let me know if you have any questions.

1 Like

Thanks, but I think I already got it fixed. I simply changed my time condition to: after 00:00:00 and before 12:00:00. It’s a hacky solution, but it works fine. I choose 12 because I’m sure the sun is up by then, and not down. Was the most simple solution It think.