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:
      condition: and
      conditions:
      • condition: time
        after: ‘00:00:00’
      • condition: state
        entity_id: sun.sun
        state: ‘below_horizon’
        id: ‘1515321712072’
        trigger:
    • 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!

Automations:

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

Script:

garden_light:
  sequence:
    - 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.