Motion sensor automation with manual override option.
I have a motion sensor that automatically turns on and after 2 minutes turns off a device called ‘Gardenlights’. When I manually switch on the Gardenlights with the wall switch or Lovelace interface and then walk into the garden, the lights automatically turn off again after 2 minutes because the motion sensor automation kicks in. I don’t want that.
Here’s how to create a manual override so that when the wall switch or lovelace interface is used, the motion sensor automation is disabled. When the wall switch or lovelace interface is used to turn the garden lights off again, the motion sensor automation will be enabled again.
Because the Homeassistant team have created a wonderful UI to create automations, we’re going to use that as much as possible.
First we’ll create a helper to set the override option to on or off.
In the Automation Editor’s upper right hand corner is its overflow menu.
Click it and select ‘Edit in YAML’
Select and copy all of the displayed YAML and paste it into the forum.
Select what you pasted and click the </> icon in the forum editor’s menu. This step displays the YAML correctly (see FAQ guideline 11).
This is the standard procedure for sharing automations and scripts. A user can simply copy the YAML you posted and paste it into a new, empty automation on their system. They can then switch from ‘Edit in YAML’ to ‘Edit in visual editor’ to display it in visual mode.
That’s far more convenient, and less error prone, than following dozens of steps to create an automation.
Thanks for posting this @pkp. It looks like your automation override is what I’m looking for but I’m confused at the step that says to “Repeat all the steps above from STARTON but change the Value Template”. The template values all appear to be the same for the second & third STARTON sections.
Perhaps you can copy and paste the YAML code so I can see the full example.
@pkp Thanks for taking the time to post the above.
I was going to create a new post for a similar question as I couldn’t find any posts with the exact scenario I’m trying to achieve, but thought I would ask here first. I think I might be able to use something similar to what has been described here but would appreciate some guidance.
I have a Philips Hue smart bulb in our small WC room. This is currently being activated by a Philips Motion Sensor after I created a Helper based on motion detected, giving me an input_boolean to show ‘Toilet Occupancy’.
I have an automation which turns on the light when this input_boolean is toggled to on, provided the light level in the room is lower than 40lux, so avoid unnecessarily coming on during the day unless it’s quite dark. Then after no movement is detected for 2 minutes, the input_boolean changes to off, and this triggers the automation to turn the light off.
All works well, except we still have a dumb wall light switch. Sometimes my other half will enter the WC but doesn’t want the light on for whatever reason, so has to use the wall switch to turn it off. Obviously this renders the system useless as she rarely flicks the switch back on again upon leaving the WC (why would you I suppose).
So I’ve bought an Aqara Zigbee wireless smart switch which has a single button and can register either a single, double, hold, or release state in HA from Z2M. I’m hoping I can make the dumb wall switch redundant and leave it connected, and fit the small Aqara button over the top/on a blanking plate, so that it can also be used to turn the light both on or off manually.
Not having much experience writing automations, I am trying to come up with a way of handling all scenarios. I’ve found so many ‘motion lights’ posts and examples online but don’t know how to write an automation to cater for all possible scenarios.
If the Aqara button is pressed, it will probably be to turn off the light that came on automatically due to motion being detected.
However, it could also be used to turn the light ON if it’s above 40lux and someone just wants to have the light on for whatever reason.
If the button is used to turn the light either on or off, it needs to override the motion sensor from triggering the light to go on or off.
after the button has been used manually for turning the light on or off, how does the motion detector then get reactivated ready for that automation to start working as normal again.
If someone leaves the light on after using the button, and the motion sensor is overridden, how do I cater for turning the light off automatically at some point, without it ending up being left on all day?
I think those scenarios cover most possible eventualities, but I’m completely stuck on how to put a set of rules within an automation to cater for this. Appreciate any help, and of course, happy to create a new thread if this one isn’t suitable.
I"m confused. The 6 trigger conditions (3 for on and 3 for off) are all identical. Am I supposed to make each one do something different? Please advise
What about just making a condition to not run the automation if the lights are already on?
Pseudo config for this:
trigger:
motion_sensor == detected
condition:
garden_light == off < --- "abort if the light is alraedy on"
action:
set: garden_light = on
wait: motion_sensor == clear
set: garden_light = off
I am aware that it will not work if there is already activity in the garden, but I guess it’s most often not the case and it would make the whole setup extremely simple.