OK, this is what I’m trying to do with limited success.
I’m trying to make a automation that will turn my garage light on when the garage door, back door or motion is detected and only turn it off if both doors are closed and no motion is detected. What’s happening is I keep getting overlapping results.
I’m doing this with the visual editor as I don’t know how to edit code, but I was only able to copy the raw code to show what I did as shown below.
Any help is appreciated
alias: Garage light door automation
description: Turn on light when door is opened and off when closed
trigger:
- platform: device
device_id: 5423237e0abc2ec18b5ef90e4a3a0517
domain: cover
entity_id: 73faf1e4348595354a9882985ef5ecd4
type: opening
id: garage door opening
- platform: device
device_id: 5423237e0abc2ec18b5ef90e4a3a0517
domain: cover
entity_id: 73faf1e4348595354a9882985ef5ecd4
type: closed
for:
hours: 0
minutes: 1
seconds: 30
id: garage door closed
- type: opened
platform: device
device_id: 7599f5938e99866ea477e34b8dbb8f85
entity_id: 99b6c1906bd970264a824a948dae15c2
domain: binary_sensor
id: back door open
- type: not_opened
platform: device
device_id: 7599f5938e99866ea477e34b8dbb8f85
entity_id: 99b6c1906bd970264a824a948dae15c2
domain: binary_sensor
id: back door closed
for:
hours: 0
minutes: 0
seconds: 0
- type: motion
platform: device
device_id: 0ce91f21afdb5699108aa390731a88f3
entity_id: 26c20461235b00540aa9c40a21ad153b
domain: binary_sensor
id: Occupancy
- type: no_motion
platform: device
device_id: 0ce91f21afdb5699108aa390731a88f3
entity_id: 26c20461235b00540aa9c40a21ad153b
domain: binary_sensor
id: "no Occupancy "
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- garage door opening
- back door open
- Occupancy
sequence:
- service: light.turn_on
data: {}
target:
device_id: e239dea5401308bb3b7552047ae699aa
- conditions:
- condition: and
conditions:
- condition: trigger
id:
- garage door closed
- back door closed
- "no Occupancy "
sequence:
- service: light.turn_off
target:
device_id: e239dea5401308bb3b7552047ae699aa
data: {}
mode: single
I have a similar objective to that stated by CintonJD from June 8. I’ve tried a lot of different things with no success thus far, and have been using the UI versus YAML coding.
If I have a lamp turn on from a door being opened OR motion being sensed, how do I turn off the lamp if either 5 minutes has elapsed, OR if no motion has been sensed for 5 minutes?
I realize this sounds really simple, but I can’t get it work correctly. If the trigger is the door, then I’d like the lamp to turn off after 5 minutes.
If the trigger is the motion sensor, then I’d like the lamp to stay on until the motion sensor is clear for 5 minutes.
Can this be accomplished in one automation via the UI?
This is likely pretty straight-forward, but I’ve been getting wrapped around the axle trying to make it work…
I started with HA about 2 1/2 weeks ago and am not a programmer.
When door opens set a date time helper now() + 5 min.
When motion, turn on light.
When motion clear, set date time helper now() + 5 min.
Trigger on time helper, turn off.
It worked! Not only do the triggers work correctly, but the timer resets when the motion detector is active again prior to the timer being finished - it seems to reset the timer and start it again! That’s exactly what I was looking for! One reason it was driving me nuts is that I realized that one of the motion sensors in question is defective and doesn’t react to motion anymore.
I’m going to use this technique for the identical automation in my garage.
The 5 triggers are all defined with the same trigger id. This way, only one corresponding Option (via a building block “Choose”) can be used to start a helper timer regardless of which device was the trigger.
The first option actions are to start the helper timer and turn on the lights.
I’ve found that defining the helper timer without a duration is the way to go. This gives you the flexibility to assign the duration of the timer within the action.
The second option simply turns off the garage lights upon expiration of the timer.
I haven’t tested every trigger yet but I’m confident this will work based on other automations I’ve created for similar scenarios (ie multiple triggers and using a timer helper).
Looks good!
Only thing I would change is the device triggers and device actions.
I would make them entity triggers and service calls (actions).
When a device is broken then it’s hard to replace it in automations, but entities are easy.
Another thing I just realized is that you use a state trigger on the timer.
The timer entities are supposed to be used with events Timer - Home Assistant .
In your case I don’t think it will matter since you do not use the timer manually at all.
But I recall there are some issues that comes with using the state instead of events.
Just not sure how that was.
But feel free to leave it as it is if it works.
But keep it in mind for next time.
That raises another question: in the UI, for an “event” trigger, the only option I see is a “Manual” event. I can specify the timer in YAML as required, but then how do I set the duration?
Here is what the UI creates thus far when I use the Manual Event trigger:
The timer duration in the example is set in configuration.yaml:
timer:
test:
duration: "00:00:30"
So not very UI friendly
But you can use the UI by means of a helper
The preferred way to configure timer helpers is via the user interface at Settings > Devices & services > Helpers and click the add button; next choose the Timer option.
It doesn’t work, the lights have been on for a couple of hours now. The lights on was triggered by opening one of the trigger devices, so I know that still works.
Could it be because I didn’t set the timer duration in the helper? I left it at zero so I could define the duration using the State trigger.
OK, this seems to work. I haven’t set durations on the timer helpers so that I can adjust the timer from the automation. When I use the timer finished state as a trigger, this is how it looks in YAML:
platform: state
entity_id:
- timer.garage_lights_timer
to: idle
id: Garage Timer Finished
for:
hours: 0
minutes: 10
seconds: 0
enabled: true
I’ve realized there are often different ways to skin the cat. I have another automation where one trigger is when motion is sensed. The related actions are to start the timer and turn on the light(s):
The timer duration is set within the action. The second trigger is when the timer is finished, turn off the light(s).
Both approaches seem to behave the same way. Not sure if one method causes more cpu usage or whatever.
Since I don’t plan on ever triggering those helper timers manually, leaving the duration at zero when setting up the timer helper gives you the flexibility of defining the timer duration “on the fly” using either approach.