I have the following automation but I need some help to make it work.
its my garage door. My binary sensor is state on/off.
In the condition state below I have tried on and off and I have tried open and closed.
Im looking for it to close at sunset. when door is open my state is “on” and in my card its is “open”
indent preformatted text by 4 spaces
- id: ‘1559883055017’
alias: 'Close garage if door is open at sunset ’
trigger:
- event: sunset
platform: sun
condition:
- condition: state
entity_id: binary_sensor.garage_door
state: ‘“open”’
action:
- data:
entity_id: switch.lynette_s_garage_control
service: switch.turn_on
Please see the banner at the top, and the pinned message, about correctly formatting your post correctly. Without it it’s hard to see what the code really is.
That said, check the dev-state menu - binary sensors are never "open", and ‘“open”’ with smart quotes is never going to work.
my error. state is on when door is open, and off when door is closed.
I have tried both ways. I also tried open and I tried closed…
I see your saying to remove the quotes from the binary sensor state. I will try that.
didn’t work.
I changed the state to ‘on’ (reading present state of on so the switch would trigger to move the state to off)
I put in a - offset ( its now three minutes past the offset)
I just noticed that I put the state to ‘on’
when I looked at the actual automation.yaml file it is ’ ’ on ’ ’
I removed ALL quotes. i.e., now set to on , without quotes.
- id: '1559883055017'
alias: 'Close garage if door is open at sunset'
trigger:
- platform: sun
event: sunset
condition:
- condition: state
entity_id: binary_sensor.garage_door
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.lynette_s_garage_control
Here’s my offer, instead of coffee or beer, do me a favor. In the future, format your code when posting here. It will make it much easier for others to read it and check it for possible errors.
Select the code and then click the editor’s </> icon.
Another way is to enter three back-quotes ``` on a separate line before your code and another three on a separate line after your code.
That was only to force the automation to run. It’s now set for sunset without offset.
My understanding is all I needed was hh:mm
hh:mm:ss is correct but I didn’t need it. Next time I will use it correctly.
You can’t have a time offset in an event, because the system can’t tell when an event will fire. You can have an offset in the sun trigger though.
- id: '1559883055017'
alias: 'Close garage if door is open at sunset '
trigger:
platform: sun
event: sunset
offset: '-02:50:00'
condition:
- condition: state
entity_id: binary_sensor.garage_door
state: 'on'
action:
- service: switch.turn_on
data:
entity_id: switch.lynette_s_garage_control
You initially swayed me to your reasoning … and then I noticed your trigger example is effectively identical to jaltman’s example.
Original:
trigger:
- event: sunset
offset: -02:50
platform: sun
Suggested:
trigger:
platform: sun
event: sunset
offset: '-02:50:00'
The primary difference is the original example is sorted by option name (a peculiar characteristic of the Automation Editor). Both use the sun platform.
I’m working on another garage automation from last night.
The one is supposed to close the door if open, after 1 min 30 seconds, when my wife leaves.
door state is on when open
car is off when away
- id: '1559952424696'
alias: Close garage after Lynette leaves.
trigger:
- entity_id: binary_sensor.lynette_s_car
for: 00:01:30
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.garage_door
state: 'on'
action:
- data:
entity_id: switch.lynette_s_garage_control
service: switch.turn_on
When automating a garage door, you should consider how to handle failure situations.
For example, what happens if the door fails to close? Obvious answer is the average garage-door opener will reverse and leave the door open. Leaving the garage door open, after you’ve left the house, is undesirable (to say the least) so you have to mitigate it with additional automations (minimally a notification alerting you to the fact the door failed to close).
In addition, a garage-door that closes by itself, without anyone in attendance, can pose a potential risk. Although openers typically detect obstructions, and excessive resistance, (and then reverse to the open position), most people have never actually tested these features and assume they work. Odds of ever actually exercising this feature are usually low when people are nearby to monitor the door’s closure. Odds increase when the door closes autonomously … and the neighbors pets and/or kids get overly curious about your wide-open garage. Maybe no one is injured, just shut inside your garage. You know your situation best and what risks, if any, are probable.
In my case, I added an audible notification when the door closes autonomously. A voice speaks the phrase: “Attention! The door will close in 10 seconds.” When driving away, we close the door via the car’s remote-control. If we forget to do that, it auto-closes after 5 minutes and sends us a notification. If the closure attempt fails, we’re notified of that as well.