Automation condition state "home" not longer than

Hi,

I’m trying to define a rule that switches one specific light on, but only when we get home. If we’re at home already it should not get switched on.
So, if the front door opens (trigger) and we just got home (group.family = home not longer than 2 minutes) it should fire. If somebody is at home for a longer period of time it should not fire.
Because the presence detection (companion app) works so fast, I cannot simply check if we are home or not. I need to check if the status of group.family changed to ‘home’ within the last 2 minutes or so.

Any idea how to check this? The default condition has a time check but it checks “the wrong way” I think.

Thanks,
Viktor

A basic State condition with a duration (for) will be true when the entity has been in the desired state for at least the defined duration. That means, when the entity is not in the desired state or has not been in it for at least the defined duration the condition will return false. To reverse that, use a not condition:

trigger:
  - platform: state
    entity_id: binary_sensor.front_door
    to: 'on'
    from: 'off'
condition:
  - alias: Check if family is not home or has been home less than 2 minutes
    not:
      - condition: state
        entity_id: group.family
        state: home
        for:
          minutes: 2
1 Like

Oh wow. That was easier than I thought :smiley:

Thanks a lot