Person state

Hello there,
so I am trying to make a template sensor telling me the state of a person based on the mobile app and the router device tracking.

So basically there are 3 states: home, away and sleeping. A person is home when the geo position of the mobile app says that is home AND the router device tracking says is home, a person is away if the geo position of the mobile app says that is not_home, a person is sleeping if the geo position of the mobile app says that is home AND the router device tracking says is not_home (mobile phone in aero mode or turned off).

The state itself is working fine, my problem is the state changing.
So from home to sleeping is ok, same as from home to away.

I am facing problems from away to home because the geo position arrives before the router can again track the mobile phone, so I have alway a certain amount of time of SLEEPING between away and home. So now the flow is not AWAY -> HOME but AWAY -> SLEEPING -> HOME

Any idea on how to solve this?
Thanks in advance

It would help a lot if you were to share the existing template.


  - platform: template
        value_template: >-
          {% if is_state('device_tracker.mobile_app', 'not_home') %}
          {% elif is_state('device_tracker.mobile_app', 'home') and is_state('device_tracker.router_scan','home') %}
          {% elif is_state('device_tracker.mobile_app', 'home') and is_state('device_tracker.router_scan','not_home') %}
          {% else %}
          {% endif %}

Thanks. You can check the current state:

          {% elif is_state('device_tracker.mobile_app', 'home') 
            and is_state('device_tracker.router_scan','not_home') 
            and not is_state('sensor.person_state','Away') %}
          {% else %}

You’ll need to re-work the logic flow though.

You may also want to see

Thanks, I’ll check the link.
Meanwhile with and not is_state('sensor.person_state','Away') you mean I can use the sensor.person_state inside "sensor.person_state ??

Thanks again

As far as I know, yes. I’ve never fully tested it, but … theory says it’ll work.

Let’s give a try then :sunglasses:

@CapitanCatarro which mobile os are you using? Are you using the iOS companion app?

So, I’ve solved using that article about making Presence not so binary.
Anyway @Bart274 not IOS but Android one… sorry

No worries :slight_smile: I was just asking because I ‘solved’ my issues with my ‘night’ mode by using the automation with Shortcuts in iOS. I think you can do similar things with Tasker on Android.