So i had the same thing, was driving me crazy cause I would get notifications from the future, not sure if you’re on Ubuntu but I am and ended up running “timedatectl status” then got a warning about how ```
The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
‘timedatectl set-local-rtc 0’.
so i ran the command and rebooted and this has fixed my time being off for a little bit under boot up.
timedatectl set-local-rtc 0
hope that helps
Sorry, no, I don’t have any answers for the previous post.
But for this post, for starters, can you explain why each of the four template sensors manipulate the time differently? Why are you using last_changed as is with two, but changing the other two first to timestamps, then converting to strings in the local time zone, but with one having -07:00 appended and the other using %z? I don’t understand why you’re changing last_changed at all with those two.
All I’m after is for the last_changed value to be shown the same in both mobile and desktop UIs. This is just my running tally of the various things that I’ve tried to get it to work. Initially, IIRC, it was showing one as UTC and the other as PST, so I tried to see if I could fix it with the 7 hour PST offset, but that didn’t work. I’m just confused why I’m getting two different results from two different devices even though the code is the same.
Maybe we should take a step back, because I’m at least confused now about what you have in your config and the results you’re seeing on the two devices. Also, let’s take the frontend out of the picture for now and start with concentrating on the backend first.
Please put the following in the Template Editor, on both devices, and post what you get. Then we can take it from there:
I totally don’t get it… below screenshot I tripped my motion sensor and took the screenshot…
the time is 18:35 and the tripped time in the sensor is 16:35… and the
Hi, it has nothing to do with my browser, nor OS. But for completeness, I have windows 10 (up to date) and Firefox, Edge, Chome, etc. All same behavior. And it is also the case in the official home assistant app (which is also a browser (?)):
I wouldn’t be too sure. It is my understanding that the “3 hours ago” part is determined by the browser, and is based on the OS’s time settings. Clearly the last_tripped_time attribute is correct, so that’s not the problem.
What do you get if you enter this into the Template Editor:
It is. It is not, everything appears to be UTC. It basically subtracts javascript datetimes: new Date() - new Date('string'). The string has the timezone, so the discrepency is coming from new Date() which is essentially datetime.now() in python.
EDIT: Just confirmed this btw. The delta is here, so you can see it’s just straight making a new Date() object.
So something that just occurred to me. I believe the “X ago”/“in X” information is based on the entity’s state’s last_changed field, which indicates the last time the state’s “state” changed, not the last time just one of its attributes (like, in this case, last_tripped_time) changed.
Of course it’s kind of hard to tell from a picture of an entity’s “more info” window, especially when it’s not expanded horizontally, when the state last changed. But going back to the picture that was posted, it does look like maybe the state actually didn’t change for 3 hours. Hence the “3 hours ago”, even though the last_tripped_time attribute had just changed.
So, unless I’ve now really confused myself, I don’t see anything wrong. It’s behaving as I would expect.
If @sender can post the results from the Template Editor like I asked for, that should clear things up.
Ok, you’ll see that both the last_tripped_time and the entity’s state’s last_updated field (the last line) are about the same. But you’ll also notice the state’s last_changed field is about 5 hours earlier. That’s when the switch changed to off. That is the time that is used to display the “X ago” / “In X” line. If you look at the history of the entity, is it saying “5 hours ago” now?
Yeah, I see the confusion… Last Changed is not the last_tripped that you’re seeing. YOu need to make a template sensor from last tripped to get the correct time it was last tripped. The value in the more-info page is UTC.
If you want the last_tripped_time, yes, you would. No you can’t just tell hass to treat it’s internals as UTC. What you are seeing is a property that’s not meant to be used. If you want to use it, make a template sensor using the code I posted.