Condition: For using more than (>) instead of specific value

I have 2 sensors, Door A and Door B. Door A being external door and Door B being internal door. Currently have an automation that triggers based on Door A being opened (if Door B is open = it is an exit, if Door B is closed = it is an entry).

However, sometimes Door A is left open and opening Door B will thus not trigger any automation.
Wondering if anyway to specify if Door A has been open for more than X minutes, opening Door B will trigger an automation (regardless of entry/exit), as I know condition only works based on exactly specified X minutes instead of on > (more than) X minutes.

No, the for: time in conditions is at least that time. i.e. that time or greater than that time. You can use it.

I’m going to call them door_internal and door_external for clarity.

- alias: entry
  trigger:
    platform: state 
    entity_id: binary_sensor.door_external
    to: 'on' # open
  condition:
    condition: or
    conditions:
    - condition: state
      entity_id: binary_sensor.door_internal
      state: 'off' # closed
    - condition: state
      entity_id: binary_sensor.door_internal
      state: 'on' #open
      for:
        minutes: 10 # true if open for 10 minutes or more
  action:
  - service: yadda_yadda...

A better solution:

rBVaVVzWVa-AboRZAABrVbiEjQw440

3 Likes

I would tend to agree with Tom
But I’m conscious that I have worked at locations where such measures have been defeated by a wedge or a convenient weighty object (a brick)
Some justifications are valid “it’s hot and this creates a breeze”
You could have the door being open for > x mins to sound an alarm, but people then justify violence (to the sounder (sometimes with the brick) ) or the clever ones to the sensor (I’ve seem contacts bridged or magnets dug out of walls and taped to the trave etc.)
It’s often better to make an individual responsible and give them a silent alarm (a light in the corner or something)
You could also use magnetic door locks and enforce an airlock system, just hope you never have to bring a ladder in through the opening or paint the door frames (both doors wedged open).

But you yadda yadda’d over the best part!

As @tom_l said, the time specified in the for option of a state condition means it has been in that state for at least that amount of time. To get the behavior you asked for, try something like this:

trigger:
  platform: state
  entity_id: binary_sensor.door_b
  to: 'on'
condition:
  condition: state
  entity_id: binary_sensor.door_a
  state: 'on'
  for:
    minutes: X
action:
  ...

Thanks, I thought the for condition was for specific X minutes so it would only trigger at X minutes. Good to know that it is for at least X minutes.

1 Like

Don’t get the for option for triggers and conditions confused. What you described is for triggers. I.e., when the state changes to the specified value and stays that way for X minutes, then at X minutes after the state changed it will trigger.

For conditions, it would be nearly impossible for an entity to have been in the specified state for exactly X minutes when the automation triggers (due to probably some unrelated event.) Hence, for conditions, the for option means that it has been in that state for at least X minutes.

Also, conditions don’t “trigger”. They are either true or false when they are evaluated. Triggers trigger. :slightly_smiling_face:

1 Like

Is this method still valid? I’m trying to follow the logic here to turn off a light “after hours.” I want to turn off the Beta tank light if it’s turned off after 9pm or before 10am, but I want to do it only if the light stays on for 10 min (testing below for 10 sec for quicker response to test the automation) and it’s not turning off.

alias: Beta Lights Auto Off
description: ''
trigger:
  - platform: state
    to: 'on'
    entity_id: switch.smart_energy_switch_2
condition:
  - condition: time
    after: '21:00:00'
    before: '10:00:00'
  - condition: device
    type: is_on
    device_id: 5c2ac5a7135d7f0be55767f4b5015838
    entity_id: switch.smart_energy_switch_2
    domain: switch
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
action:
  - type: turn_off
    device_id: 5c2ac5a7135d7f0be55767f4b5015838
    entity_id: switch.smart_energy_switch_2
    domain: switch
mode: single