Hello All,
I’m looking for a better way to program a motion automation trigger. For example:
I have a motion sensor on my front porch that triggers the porch light on, waits 5 minutes and then shuts the light off. This works fine unless you are out there for more 5 minutes. You are then in the dark and it doesn’t come back on. Is there a better way to write the script or add additional scripts?
I have hall and bathroom motion sensors which light up my bubble my when there is a movement then I start a timer for 2 mins and if there is no movement next 2 mins it shutdown the light if there is a movement timer is reset. When I’m under the shower every 2 mins there is a “detecting occupancy” event which reset the 2 mins timer and does not let bulb to be turned off.
Be aware that your body / movement sensors has timer inside it mine is Xiaomi aqara body sensor and HW timer is 2mins and I calculate my Hass time to 2 mins because of that and it depends how is best for you. Experiment I tried 5 mins . 4 mins 3 mins and now im on 2 mins and im happy.
# Bathrom light
- id: Bathroom_light_100
alias: Turn on bathroom light at 100% when there is movement
trigger:
- platform: state
entity_id: binary_sensor.bathroom_occupancy
to: 'on'
action:
- service: light.turn_on
entity_id: light.bathroom
data:
brightness_pct: 100
- id: Bathroom_light_5
alias: Turn on bathroom lights at 5% at night
trigger:
- platform: state
entity_id: binary_sensor.bathroom_occupancy
to: 'on'
condition:
- condition: time
after: '00:30'
before: '06:00'
action:
- service: light.turn_on
entity_id: light.bathroom
data:
brightness_pct: 5
Turn off the lights.
# Turn off ligts when there is no movement - PIR have 1 min sleep which does not measure
- id: Bathroom_turnoff_lights
alias: Turn off bathroom light 2 minutes after last movement
trigger:
- platform: state
entity_id: binary_sensor.bathroom_occupancy
to: 'off'
for:
minutes: 2
action:
- service: light.turn_off
entity_id: light.bathroom
- id: Hall_turnoff_lights
alias: Turn off hall light 2 minutes after last movement
trigger:
- platform: state
entity_id: binary_sensor.hall_occupancy
to: 'off'
for:
minutes: 2
action:
- service: light.turn_off
entity_id: light.hall
Have you looked at the “entity-controller”?
It will handle these cases any many more (ie. manual override etc (if you turned on the light, the automation will not turn it off etc)).
I use it, with several motion detectors to control both common and other lights.
I have built something like this using Node Red ( in fact have moved all my automations to node red… muuuch more flexible)
I have my basement light tied to the alarm system ir sensor… turns on and off after 5 min of inactivity, but is constantly re triggered as long the ir is being activated. Also manually turning on or off the lights via the switch (so off) changes the behaviour, respecting the manual choice for a longer period of time.
Not sure exactly how, but if interested I can see if uploading the moderes flow here…
I want to thank all of you for your responses.I have been keeping an eye on HA for quite a few years now, but did not dive in. It left a sour taste and I just simply went the Smartthings way. I am disappointed in all things zwave. There is no one great solution. However, HA seems to be the bright star of so many. There is so much to learn and so little time.
I am trying each of your suggestions to see where this takes me.
This suggestion was the easiest to implement. The light stays on for 5 minutes after the last motion detection as given in this examples. I used this on all my motion sensor areas and the lights function as intended.