So your “Off” automation will trigger if either the doors have been closed for two minutes OR there has been no motion for two minutes.
So, the way I did the trigger coupled with condition that they’re all closed is the correct way to have AND triggers? This wasn’t very intuitive, but now that I know it’s workable.
Since they are all binray sensors, you could add them all to a group, and it would be behave the same way, but with only one trigger.
I have the 3 camera’s in one group as their motion and the 3 doors in a group as they’ve all contact. I didn’t think I could put motion and contacts in the same group, but if I can it would simplify it a bit.
The gui does its own thing but is getting much better. I don’t use it though, just a text editor (though VSC is more than just a text editor)
Yes, I’m seeing that. Being new to HA I was trying to not manipulate the yaml files directly, but it seems this is a better way. Currently, I’m using SSH/Vi to edit them.
The problem I have with this is, if it is triggered say 2 minutes before sunrise, it will never go off again until 10 minutes after its triggered again the next night.
This is just really a night light. Sunset isn’t immediately dark here, so I’m ok with a 10min lapse. I’ll see what winter brings and if it’s a problem I’ll change the condition to say -30 before sunset or something.
Actually, after switching to Hubitat from SmartThings, I installed NodeRED to try and use it to queue off of Arlo motion. I couldn’t get this working and haven’t looked at it again. It seems fairly intuitive for middleware, but I’m starting to overload my RPi server with Pi-Hole, Home Assistant, NodeJS and sonos-http-api. I may visit it again, so if you have some good tips/pointers or a site you like please share.
# Garage Lights ON As Long as There Is Motion - TESTED
- id: garage_lights_on_when_motion_atm
alias: Keep Garage Lights ON As Long as There Is Motion (ATM)
description: Keep Garage Lights ON As Long as There Is Motion
trigger:
# Motion Detected in Garage
- platform: state
entity_id:
- binary_sensor.motion_garage_bs
- binary_sensor.motion_garage_2_bs
- binary_sensor.motion_garage_3_bs
to: 'on'
mode: restart
action:
- service: switch.turn_on
data:
entity_id: switch.zooz_zen21_switch_garage
- delay:
minutes: 10
- service: switch.turn_off
data:
entity_id: switch.zooz_zen21_switch_garage
I am still searching also for an elegant solution. But I don’t think this will ever work.
Why? Because it won’t change the status to “on” again from anything during motion in front of the sensor. It will stick with that status all the time.
You can test by yourself. Set the timer down to e.g 20-30 Seconds. Result will be that the light turns off. I was just in front of the sensor and had some fun while jumping up and down meanwhile checking my phone the whole time for the status. The Status was “on”. but the light turned off.
So I am thinking of something like
If state of sensor = on, THEN turn light on, ELSE turn light off. (For sure with IF before sunrise and after sunset. Because otherwise the automation won’t work for turning the lights on between 00:00:00 and let say sunrise at 06:00:00AM )
But since im playing just some days with HA, I am sadly even not sure how to implement this by now.
Then how do you explain all the people here that have working solutions.
I admit mine is a bit complicated given the dual timing nature’s and the conditions for firing but I recently saw a post by Taras that did it all in one automation
It’s the mode: restart that is responsible for making it work correctly (i.e. GrizzlyAK’s example).
If the mode were single (which is the default) then subsequent triggers would be ignored by the automation while the delay is counting down. In other words, the countdown would not be reset by the detection of additional movement.
I don’t really understand why you would want the “turn lights off” action to be dependent on the “motion sensor is on” trigger (with a delay).
Why not have the “motion sensor is on” turn the lights on, and a “motion sensor has been off for X minutes” turn the lights off?
No idea, why it did not show that I used the “reply” button to his comment.
But in fact it does not work for me. I tried it several times. Result was - not working.
But correct me if my assumption is wrong. My testing result shown me, that the status is not changing. But the code says change status “to” ON. Since if the status is ongoing at ON, there won’t happen a change of the status. Like change from bla to ON, change from OFF to ON, because the status will remain until the motion stops. After the status changed to what ever, the trigger can be used again.
I’ve tried now Turn ON light for 10 minutes when motion detected
This works perfectly for me. But I really would like to have it run with just one automation. Because this way I’ve splitted the automation in two pieces. The ON, and the OFF automation. But am still struggling to understand how I could make it with only one automation entry and maybe with a script in the backend.
What is the benefit of having one automation with complex syntax and conditions which is difficult to read, undersand and debug, instead of having two simple, easy to understand automations that does exactly what you would expect?
Less automation entries? Make it more flexible? Make it usable for other sensors, too?
There are several reasons why you want to do such things.
In bash i also do not write 10 scripts, when I can do it in one shot and being able to use it for other topics. Or like to extend the the functionality of a script.
Well. When I write scripts, I tend to write them to do one thing and do that well. And if I want to do several things, I add a wrapper that can trigger the individual scripts in the order I need.
But ymmv.
And I dont really understand why you feel it is more “flexible” and “usable” to introduce delays and conditions, than to simply do something like:
- id: garage_lights_on_when_motion
trigger:
- platform: state
entity_id: group.motion_garage
to: 'on'
action:
- service: switch.turn_on
data:
entity_id: switch.zooz_zen21_switch_garage
- id: garage_lights_off_when_no_motion
trigger:
- platform: state
entity_id: group.motion_garage
to: 'off'
for: '00:10:00'
action:
- service: switch.turn_off
data:
entity_id: switch.zooz_zen21_switch_garage
Easy to read, easy to understand, easy to add more sensors, more switches or lights etc.
The delay before the lights are turned off can easily be set by an input_datetime if you want to have a more dynamic delay. You can also add different conditions to the “on” and “off” automation.
The OP talked about not turning the lights on during the day. Add a condition to the “turn on” automation only, and you still turn the lights off automatically if there is no motion detected, even if the ligths were turned on by something else than the automations. So at daytime, you can turn on the lights manually if needed, and if you forget to turn them off, they are turned off after 10 minutes of no motion.
All of this gets more and more complicated because you need to handle both the “turn on” and “turn off” cases in the same automation.
If you insist on having them as a single automation, follow @123 s example. At least add triggers on both “pir on” and “pir off”, instead of waiting for a given time after “pir on”.
I am trying to do something similar (except it’s 1min instead of 10 ^^
The first part works. I get the lights to turn on when there is a movement detected. However, they don’t turn off.
Here is what I have in my automation :
Now, I don’t see your triggger here. But guessing it is something like “Motion detected in hallway”.
So this automation will turn on the lights when motion is detected, and turn it off again after one minute, even if there is still motion in the hallway.
I might be wrong, but I don’t believe this is what you really want…
My problem is that my XIaomi sensor only send update “off” after 2:30 minutes aproximately.
However, when I cross the hallway, I usually stay way less than that I did not want to leave the light on for so long. So I decided to automaticaly turn it off after 1min.
But you are right. The issue is that the sensor won’t send an movement detection signal if someone is still in the hallway or if someone else enter less thatn 2:30 min after the first person entered.
For me its working perfectly with the motion sensor of fibaro.
As long as movement is recognized in the kitchen the light stays on. Without movement the light goes off after 30 seconds. Can be even extended or reduced.
Not sure about the xiaomi sensors. I have a very cheap eWeLink MS01 (Sonoff SNZB-3) which is not able to handle my goal for example. This is due to the blindtime which cannot be changed. Here it would be 1m - and thats useless for my kitchen or bedroom lights.