Sensor Template for than X minutes


I have the follow template sensor on my configuration.yaml

  - platform: template
        unique_id: home_parents
        unit_of_measurement: 'Parents'
        value_template: "{{ [ states.device_tracker.mobilephone1,states.device_tracker.mobilephone2,states.device_tracker.mobilephone3,states.device_tracker.mobilephone4 ] | selectattr('state', 'eq', 'home') | list | count }}"

This code returns how many people are at my home. I would like to modify this or a new template sensor that returns how many people are at my home more than X minutes.

for example I want a counter / number with the persons that are more than 1 hour.

What is the source integration for the device trackers?

You may need to alter the consider_home value or use a manually configured device tracker to accomplish what you want.

Device Tracker

I use GitHub - amosyuen/ha-tplink-deco: Home Assistant TP-Link Deco Custom Component

The integration returns values like this Screenshot by Lightshot . So i have the “time” value.

If you are just starting out you should use the current format for template sensors instead of the legacy format.

| selectattr('state', 'eq', 'home')
| selectattr('last_changed', 'lt', now()-timedelta(minutes=60))
| list | count}}

One thing to keep in mind is that the last_changed property updates on restart, so any sensor based on it will not be accurate after restart either.

Thank you.

Seems to work.