Presence sensing, time home/away

Hope someone can help and give some ideas on a way I can do what I am trying to achieve

Basically I have a floorplan and on that plan I have home and away sensors (Using Samsung Presence Sensors) and these display home and away depending on sensor state which work perfectly. What I also want to do is display underneath the last time that person left or arrived home so that is says “Home since yesterday at 9:59 PM” for example.

Now I found some code and got it to work by using the “last_changed” attribute of the presence sensor/binary sensor and it does work perfectly and shows the correct time someone left or arrived back home. The problem is though that if I restart home assistant it also changes the last changed attribute and therefore throws off the time that I am trying to display.

Anyone have an idea of how I can get around this? In a perfect world restarting home assistant would not affect the last changed attribute but I don’t believe this is possible

Use an automation to store the last changed attribute in an input_datetime whenever the tracker changes state.

1 Like

Thanks tom I never even thought of that! Hopefully now it’s solved, thanks again

1 Like

@liamstears Is it still working well for you? If so, would you mind sharing your code? I’m trying to do the exact same thing…however, I’m more of a hack when it comes to templating/scripting code…haha thanks in advance!