Motion light off failing

The first automation is supposed to turn on the light between 11:30PM and 6:30AM when motion is detected. The second one is supposed to turn off the light after 2 minutes of no motion detected.

The first one works as expected. The light turns on with motion between the scheduled times but the second does not turn off the light

  • id: ‘1594703035209’
    alias: Motion Sensor Lights On
    trigger:
    platform: state
    entity_id: binary_sensor.family_room
    to: ‘on’
    condition:
    condition: time
    after: ‘23:30’
    before: 06:30
    action:
    service: homeassistant.turn_on
    entity_id: light.family_room_right_level_on_off
    data:
    brightness: 35
    transition: 15

  • id: ‘1594739127485’
    alias: Motion Sensor Lights Off
    trigger:

    • entity_id: light.family_room_right_level_on_off
      for: 0:02:00
      platform: state
      to: ‘off’
      action:
    • data:
      transition: 160
      entity_id: light.family_room_right_level_on_off
      service: homeassistant.turn_off

Hi there. I was tweaking with my motion sensor to work as I wanted with the help of the HA community. I finally found my solution. I do not know what sensor you have, but I have the newer model Ikea sensor (fixed 3 min timer). It turns on with motion for 3 minutes. If there are no motion detected, it will shut off in 30 sec. What I like about this setup is that if you happen to pass by right after the lights turn off, it will turn back on. My pass code didn’t work that way. You will need to adjust the code for your lighting, sensor, etc.

# Hallway Light Sensor
- alias: 'hallway motion on'
  trigger:
  - entity_id: binary_sensor.0x588e81fffe11693e_occupancy
    from: 'off'
    platform: state
    to: 'on'
  condition:
    - condition: or
      conditions:
        - condition: state
          entity_id: input_boolean.duc_home
          state: 'on'
        - condition: state
          entity_id: input_boolean.eri_home
          state: 'on'
        - condition: state
          entity_id: input_boolean.shion_home
          state: 'on'
  action:
  - service: light.turn_on
    entity_id: light.h_2
    data_template:
      brightness: '{% if now().hour > 19 %}50{% elif now().hour < 7 %}50{% else %}200{% endif %}'

- alias: 'hallway motion off'
  trigger:
  - entity_id: binary_sensor.0x588e81fffe11693e_occupancy
    for: 00:00:30
    from: 'on'
    platform: state
    to: 'off'
  action:  
  - service: light.turn_off
    data:
      entity_id: light.h_2

Please read point 11 here about formatting your post then edit your post: How to help us help you - or How to ask a good question

You have the wrong trigger for your second automation.

You are not checking to see if the motion sensor binary_sensor.family_room has been off for 2 minutes, you are checking if light light.family_room_right_level_on_off has been off for two minutes.

Also note that because you have a 160 second transition to off, the light will not turn back on if motion is detected during this time. If that is going to be a problem, shorten the transition time. Transitions can not be interrupted. It’s annoying but that’s the way it is.

Spot on @tom_l. That solved my issue… Appreciate the help

1 Like