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