#Do I need Templates or Helpers to accomplish garage auto-close

1 messages · Page 1 of 1 (latest)

dry hornet
#

I want to automate closing my garage door in case someone forgot to do so. The following conditions have to be met for the garage door to be Actioned to close:

  • The garage door must be in an open state
  • The obstruction sensor must have been clear for 5 minutes. This ensures no one is actively moving in and out of the garage through the garage door (meaning the garage door being open is still being utilized).

As I read up on Triggers and Actions, it seems like a timer that tracks (1) how long the garage door has been open (2) how long the obstruction sensor has been clear, cannot be tracked independently. To elaborate, once the automation is triggered due to the garage door being open for 5 minutes, the timer of the obstruction sensor cannot be tracked in the same automation using a naive implementation.

I even tried setting the trigger to the obstruction sensor, however I only see a 'changed state' trigger for the obstruction sensor, rather than a 'has been closed for X minutes'' trigger.

Do I need to consider templates for this, or helpers to track time, or both?

red panther
#

Don’t use device triggers, use an entity trigger instead. Trigger -> entity -> state

Then you can choose the obstruction entity (should be a binary_sensor) and set for: "00:05:00"

dry hornet
# red panther Don’t use device triggers, use an entity trigger instead. Trigger -> entity -> s...

Okay sure, but I still face the same issue which is that I cannot meet both the trigger timer condition of the door being opened, and the 'and if' condition of the obstruction sensor being clear, or vice versa. As soon as the door is in an opened state, the 5 minute timer begins, and if at any point during those 5 minutes, the obstruction sensor is triggered, the automation will not Action, even if the obstruction remains cleared for a successive 5.

Also, choosing the entity-state item also requires that the sensor 'changes' states. If the garage door is opened, and left open, but the sensor is never triggered, then the obstruction state is never 'changed' so the trigger will never occur.

craggy sky
#

Use multiple triggers, for example obstructuon clear for 5min, doors open for 5min, … then use the condition to check the desired conditions and then run actions
In worst case you could add time pattern to fire every 5min, and then guard it with conditions but that is the last resort in my view.
Add also ha started as a trigger in case ha was down when these events happened

red panther
# dry hornet Okay sure, but I still face the same issue which is that I cannot meet both the ...

What I described was for the behavior you outlined in the bullets. Based on your comments did you want this instead?:

  • the garage door must have been open for at least 5 minutes
  • the obstruction sensor must have been clear for at least 5 minutes

If that is what you want, then as AllUpInYa was alluding to, you want matching triggers and conditions:

  • triggers:
    • entity state: garage door open for 5 minutes
    • entity state: obstruction sensor clear for 5 minutes
  • conditions:
    • entity state: garage door open for 5 minutes
    • entity state: obstruction sensor clear for 5 minutes
craggy sky
#
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.door
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - trigger: state
    entity_id:
      - binary_sensor.sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
    to: "off"
conditions:
  - condition: state
    entity_id: binary_sensor.sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
    state: "off"
  - condition: state
    entity_id: binary_sensor.door
    for:
      hours: 0
      minutes: 5
      seconds: 0
    state: "on"
#

Yep, you just wrote it faster - automation to me looks very easy to manage

dry hornet
#

Thanks to you both. But I don't understand, why do we need the 'conditions' if we already have the two triggers that check to ensure both triggers are met before further execution?
I understand the automation is triggered with either trigger, so the first run of the automation will fail, until both triggers are met, at which point the automation will run again and pass this time.

#

That being said, why are we checking to see if ha is running, as mentioned above? If ha is not running then the automation logic will not be available for the system to check anyways @craggy sky

craggy sky
#

because you are triggering on the different events. COnsider a trigger to "when do I call the automation"

#

Imagine sensor being off for 4:30 and doors just open, while sensor remains off

#

without conditions, sensor will be off in 30seconds for total of 5:00, trigger will fire and if there are no conditions for doors being open for at least 5 minutes, the doors will go off

#

strange, isn't it?

#

Why are we checking if HA is running -> because if HA is down when the 5 minutes event happen, you'll will miss the trigger event so nobody will trigger the automation

#

All the safety automations, in my view, must have "ha started" event

red panther
#

To be clear, you aren’t checking if HA is running.

You are forcing the automation to execute when HA starts up.

But, if you add that trigger, you need to think about the conditions you want to be true in order for it to execute. Your two conditions will certainly not pass because there is no way for them to have been true for 5 minutes of HA just started. You’d have to move all your conditions underneath a choose block in the actions section, and pick the appropriate response based on which trigger fired the automation (using trigger ID’s)