It happend: I was outside, the sun was down, and the shutter closed. Also the door I needed to get in. Well, that was foreseeable …
Anyways, I have installed a door sensor to detect if my door is still open. In my automation I would like to delay the closing till the door is closed.
I have an automation in place which is triggered after sunset. There I can only set the condition to not go down but how do I just delay it until the door is closed? When I add a state change watch then I need to actively open and close the window that the shutters are going down.
I think the key is in the title of this thread . “If open”, then wait for trigger. And close the cover afterwards, regardless if it was open and waited for trigger or not. It’s also a good idea to add a timeout after which the automation will continue anyway (or after which it will abort and not wait any longer, depending on what you want).
If you are using graphical interface, then you can add it in actions part, as construction block. In YAML, it looks like this:
action:
- if:
- condition: state
entity_id: your contact sensor ID
state: "on"
then:
- wait_for_trigger:
- platform: state
entity_id:
- your contact sensor ID
to: "off"
timeout:
hours: 6 #or whatever you want
minutes: 0
seconds: 0
milliseconds: 0
continue_on_timeout: false # if you want it to not do anything if the windows were not closed within 6 hours
- service: cover.close_cover
# and the rest of the close call
Notice the close cover call is outside of the if condition. So it will run immediately if the if condition is false (it will not start the wait for trigger) or alternatively, if the condition is true, it will start the wait for trigger. In such case the automation will pause and only do the next action (close cover) after the trigger happened.
I’m not a fan of wait for triggers. Mostly because they break on reload, but also because I do not like long running automations in general. Also in this case, if the screens open while in the wait for trigger you need some way to abort.
What I do is very simple but effective. I have an automation triggering 5 secs after windows close, to mimic the screen position of the adjacent window that cannot open. I do this also for curtains.
Sure, there are lots of ways to get similar result. Probably the most robust would be to create a helper boolean and set it to true instead of closing the cover (then set it to false when opening the cover), then the other automation triggered by setting the boolean to true or by closing window, with a condition to check if window is closed, and action to close the cover.
But, that’s more complicated and for me more difficult to maintain. You get 2 automations and a helper.
That’s the beauty of HA, you can do things the way you prefer.
Very true. What I do is basically use the curtain beside it as the input boolean, because normally the screens do the same thing. I’m fully aware it is a matter of preference for the most part.
Perhaps not ideal, but how about if you define both situations into trigger part and then also define both situations in the condition part?
In this case:
automation will trigger when sun goes down and it will check if sun is down (yes) AND if door is closed (yes or no);
when you close the door it will also trigger and also check if sun is down (yes or no) AND if door is closed (yes).