Motion light only certain time of day

So i have been playing with this automation and i am dtill having issues.

This is what i want:

1 motion only triggers light during the time of 11pm and 7am
2. turn lights off after 1:30 with no motion.

Here is my code:

alias: Living room motion lights
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.living_room_motion_occupancy
    attribute: occupancy
    from: 'off'
    to: 'on'
condition:
  - condition: time
    before: '07:00:00'
    after: '23:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: light.turn_on
    data:
      transition: 15
      brightness_pct: 25
    target:
      entity_id: light.living_room_lights
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.living_room_motion_occupancy
        from: 'on'
        to: 'off'
        for: '00:01:30'
  - service: light.turn_off
    data:
      transition: 20
    target:
      entity_id: light.living_room_lights
mode: single

If someone can help that would be awesome.

Thanks in advance

It looks ok. What isn’t working?

If you give the automation an id you can use the automation trace to debug it:

I would split the off command to a separate automation. So,

  1. automation 1: Lights on with occupancy.
    Turn off after a certain wait – or leave on?

  2. automation 2 turn off at 1:30
    – you can just turn them off, or if you don’t want an error use is_state

I’m not sure what the “occupancy” attribute contains but if it’s not “on” or “off” it won’t work.

you need to likely remove this:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.living_room_motion_occupancy
    attribute: occupancy  #<--- remove this line
    from: 'off'
    to: 'on'
1 Like

these are the options on the sensor

just leave the “attribute:” section blank. It’s optional so don’t use it.

This just worked for me:

alias: Turn on porch light when motion detected
description: ""
condition:
  - condition: time
    after: "21:30:00"
  - condition: sun
    before: sunrise
    after: sunset
use_blueprint:
  path: homeassistant/motion_light.yaml
  input:
    motion_entity: binary_sensor.front_door_motion
    light_target:
      device_id: e0e6de23047e42cbd9e8da2c077b5706
    no_motion_wait: 60
1 Like