A motion sensor should turn my lights on (and off when motion is gone)
But ONLY if the lights were off, it should turn in on and then later off
Its easy to create an automation for turning it on if its not already on - but how should I make sure its only turned off, if it was OFF initially when motion occured ?
So when kids go up at night (lights are off) and they turn on and then off after they go back to bed - but if its at 8pm, and lights are probably on already, it should not turn on at motion and expecially NOT turn OFF when motion is gone.
In my case a have and script, that when motion is detected, light turn ON, and after few minutes (i define these minutes in the script), then the light turn OFF.
This is the script:
timed_lamp:
alias: 'Switch ON light'
sequence:
- service: script.turn_off
data:
entity_id: script.timer_off
- service: light.turn_on
data:
entity_id: light.yeelight_white_f0xxxxxxxxx
brightness: 64
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: 'Switch off light after 3 minutes'
sequence:
- delay:
minutes: 3
- service: light.turn_off
data:
entity_id: light.yeelight_white_f0xxxxxxxxxxx
I found this script in forum.
Then in automation, you must have something similar to this:
alias: Switch ON Corridor light
hide_entity: False
initial_state: 'off'
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_xxxxxxxxxxx
to: 'on'
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
And if you want, you can add a condition about the status of light.
But I think the example with a timer to shut off the light will work too - as it only initiates if the light was off (and its nighttime and so forth) …