Person, home and not_home

Hi,

Before yesterday, I always used my device tracker for my phone to track my presence. In the Lovelace UI, it was showing as Home or Away (even if the real state was home/not_home).

I have now create a Person for me and assigned my phone device tracker to it. The weird thing is that the Person state is showing home/not_home in the Lovelace UI instead of showing Home/Away. Even weirder, the phone device tracker still show Home/Away correctly.

Is that an issue with the Person component?

Anyone has an idea for this? Should I raise an issue for this?

Hi
Same here home / not home.

What are your expectations? For it to show home/away in the UI?

Yes, same as my other device tracker.

The new person functionality is in it’s infancy. I don’t think it is getting executed through the same code a device tracker. There are other issues with person, i.e. it doesn’t show you what zone you are in. I do not know for certain, but I believe this will change over time.

So with that being said, you could get around this currently by making a template sensor. But then in the UI, you’d need to use the sensor in all the places you wanted to use the person.

It’s a bandaide, but it will get you what you want.

sensor:
- platform: template
  sensors:
    my_person_bandaide:
      value_template: "{{ 'Home' if is_state('person.x','home') else 'Away' }}"

You’re also welcome to report the issue with person on Github. I thought there would be some reported issues on this, but I don’t see any. Might be advantageous to get it on paper.

EDIT: Just replace ‘person.x’ with whatever your person name is. You can also add other fields to the template as well

2 Likes

It’s probably just not set up to show like that in the UI. The actual state of device trackers is the same home/not_home but the UI knows to show it as Home/Away (see here).

I don’t see anything in there for person, so it’s just going to show the actual state in the UI. It probably just didn’t get updated when the person component was added.

Yep, you must be right. Just dug in further and found the issue on HA polymer. So the good news is that it’s been reported

So, it’s needed to create a new template sensor to have this

I used to use this way templates:, with a custom-card, but it shouldn’t work in Lovelace, right?

person.x:
  icon: mdi:human-male
  templates:
    icon_color: >
       if (state === 'home') return 'rgb(255, 0, 0)';
       return 'rgb(0, 255, 0)';
     _stateDisplay: >
        if (state === 'home') return 'A casa';
        return 'Fuori casa';

So this is the only way, creating a new template sensor?

Thanks

@Mariusthvdb might know if that template will work in Lovelace. I believe it does but he might have a better explanation.

Thanks for finding the issue. It’s good to know that is not only on my side.

I’ve updated the Custom-ui from here and now the state template seems to work, it doesn’t work instead, the icon_color change

_stateDisplay: has been replaced by state:

So now I have

person.x:
  icon: mdi:human-male
  templates:
    icon_color: >
       if (state === 'home') return 'rgb(255, 0, 0)';
       return 'rgb(0, 255, 0)';
    state: >
       if (state === 'home') return 'A casa';
       if (state === 'not_home') return 'Fuori casa';

state: works, icon_color: doesn’t. I’ve tried also using the color name

And tried also what suggested in another thread

I don’t use the else since I’m using Life360 as device tracker and this is reporting also other states.

regarding icon_color: not working I found that there is an issue already opened.

that would be good news, where is this documented? Not on the link you provided…?

I am not sure if it has been replaced, but reading the examples I saw it was using the state: and I gave it a try and it’s working…

state: is documented here: https://github.com/andrey-git/home-assistant-custom-ui/blob/master/docs/features.md#template-attributes

Be ware, there is a major difference between actually changing the state (which this does) and changing the display of the state (_stateDisplay obviously…). As the author states, it can have performance implications, but more importantly, it interferes with the internal state handling in HA.

so, _stateDisplay: hasn’t been replaced by state: which has always been there. They are different, and state: should be used with care.

see this binary_sensor, used with _stateDisplay:

used with state:

don’t think it is very wise to use state: unless you really really keep an eye for that, it messes with internal affairs and logic.

We might just have to accept _stateDisplay has been deprecated and won’t come back to regular HA (dixit @andrey himself)

You’re right.

So now I’m changing the state and not showing something else based on a state value.

I will remove this customization hoping that some day it will be possible to have something similar to _stateDisplay also in Lovelace…

Thanks

I think I may be having a similar issue.

As I type this, I have one device tracker (via my home wifi) which correctly says I’m ‘not_home’, but a second device tracker (Owntracks GPS) which correctly says I’m at ‘Work’. I am using Zones for home and work.
But my Person entity says I’m ‘not_home’, instead of at ‘Work’.

I’m on 0.92, and I could have sworn it was working in a previous version.