Condition and for a duration

Hello,
I need to have an action if both my and my wife not at home.
I use nmap to know if a person is at home, but the wifi of cell phone is off often.
So the rule is:
if both person are not at home during one hour, take the action.

I think I can have the time as a condtion, nice for even ‘after’ or befor, but not ‘for’:

condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'person.vorms'
        state: 'not_home'
      - condition: state
        entity_id: 'person.caron'
        state: 'home'
      - condition: time
        for: 01:00:00

Is that a mean to write it ?
many thanks for your help.
Best regards

no it isn’t :wink:

depending on your wishes, you’d better create a group with both entities, and use the state changing of the group (if you want the being away from home for your wife and you to be together, as you describe)

personally, Id create a binary_sensor, with a delay_off value and use the binary_sensor’s state as the trigger for the automation.

or,
you could have a condition in the automation like this:

        value_template: >
          {{ (now() - trigger.from_state.last_changed | default(0)).total_seconds() > 
                                           60*60}}

or use this:

  - alias: 'Empty home for 1 hour'
    id: 'Empty home for 1 hour'
    trigger:
      platform: state
      entity_id: group.family
      to: 'not_home'
      for:
        minutes: 60

I’ve never used it like that as far as I know and the docs don’t say you can use ‘for:’ in a condition that I saw. However, I just wrote a test automation to test it and it seemed to have worked. May need further testing tho.

this is the conditions you would need:

condition:
  - condition: state
    entity_id: 'person.vorms'
    state: 'not_home'
    for:
      hours: 1
  - condition: state
    entity_id: 'person.caron'
    state: 'not_home'
    for:
      hours: 1

By default all conditions are ‘and’ unless otherwise specified so you don’t need to write that part.

1 Like

many thanks !
Thierry

many thanks !

Thierry