Display Date Instead of Yesterday, Last Month

I am having an issue and have been digging for awhile now. I have a couple sensors that are a date, but HA wants to display them differently then I would like. I would like them to always display the date and time instead of yesterday or last month. See below.

image
image

Home Assistant knows the last reboot, but I can’t seem to figure out how to create anything that will put this in a useable sensor or display it.

image
image

Same with last Hass Reboot.

I suspect those sensors have their device_class set to timestamp. Home Assistant’s frontend automatically displays a timestamp sensor’s value as relative to the current time (i.e. Yesterday, Last month). To my knowledge there’s no override in the frontend for this automatic timestamp formatting (maybe in the future).

The workaround is to create a Template Sensor that simply reports the timestamp’s sensor’s state value (just be sure not to set the Template Sensor’s device_class to timestamp otherwise its value will also be displayed as relative time by the frontend).

To anyone that is looking for this information here is what I did:

And here is what appears in the dashboard now:

image

3 Likes

Thanks for sharing this solution Erik. Can you tell me where you placed this piece of code?

Many thanks

Entities card has an option for timestamps.

1 Like

I had similar annoyance where I wanted an actual sunset timestamp but HA kept giving it to me ‘In X hours’.

Simplest way I found was to create a template sensor under Helpers in ‘Devices & Services’. Pasted the following line in State template field and left 3 dropdown menus blank.

{{ as_timestamp(states('sensor.sun_next_setting'))|timestamp_custom('%H:%M') }}
1 Like

It is in my config.yaml file. It creates a sensor that displays the exact time instead of relative time.

No need.
You seem to miss my post.

…unless you definitely need a date of a particular format like “DD-MM-YY” etc

2 Likes

I saw your post but I only skimmed through it as I had my sensor already setup and working.

Thanks for bringing it up again, as changing time format on the card is far simpler than a template sensor. I’ve simplified my setup so thanks again.

Few options there for others to consider. :grin:

1 Like