Template condition person left zone for over 2 h

Hi i was using the states card before to see when persons.rodz was away for 2 hrs as a condition. However since I set up some zones, if I leave my home and get to work then im “home” again.

I was wondering if I could achieve this with a template but was unsure how to get person and zones in the template.

I have
{{ (as_timestamp(now())-as_timestamp(states.person.rodz.last_changed, ‘away’))/60 > 120}}

but it doest work,

thanks

Is this the way you want it to work, or are you saying this is a problem that you are experiencing?

sorry this is my problem, I basically want to know when im away from the home zone for 2h. Previously I could use home and away, but now Ive set a work zone this is no longer an viable method.

One way would be to set up a template binary sensor:

template:
  - binary_sensor:
      - name: "Rodz not at home"
        state: "{{ not(is_state('person.rodz', 'home')) }}"

That would filter out any other zones, and you could use the last_changed of that sensor in the condition:

{{ as_timestamp(now()) - as_timestamp(states['binary_sensor.rodz_not_at_home'].last_changed, 0) > 7200 }}

That worked perfectly, thanks. I had an issue where it said i was home but i noticed my ipad had been added to the device tracker. So removed that, with a few reboots its working as expected. Just need to test.

Thanks again

This is why I asked about the problem… You likely need to change the user that your ipad and any other normally-at-home devices are using to log into HA. If you have “Allow person to login” enabled for your person entity, you will continue to experience this problem.

I was wondering why the iPad device tracker kept being added. That’s good advice I’ll do that.

Ive been able to use zones in conditions for most my automations now and a few triggers too. I have the Rodz home sensor to use state change for time. Think I have it all covered now.

thanks