Days until template sensor

as_timestamp is working with script posted.
I cant recall right now where I read that, i read many topics without finding working template for my sensor/helper, but it was about using time&date instead of now(), because that updating like 123 said.

Tried this and it looks like working, it came up with 0 days (because I shutdown/reboot my system today)

{{ (now() - states('sensor.system_monitor_viimeinen_kaynnistys') | as_datetime).days }}

But this returned unavailable

{{ (now() - strptime(states('sensor.system_monitor_viimeinen_kaynnistys'), "%B %d, %Y at %H:%M")|as_local).days }}

That sensor.system_monitor_viimeinen_kaynnistys is giving date as May 24, 2024 at 17:11

I think you’re looking at the translated state and not the under the hood state. Go to developer tools states page and post what the state shows there for sensor.system_monitor_viimeinen_kaynnistys.

1 Like

Yes, sorry about that, it gives 2024-05-24T19:18:40+00:00

Then this is the correct one.

{{ (now() - states('sensor.system_monitor_viimeinen_kaynnistys') | as_datetime).days }}