little info provided so non specific response…
you can customize it Customizing entities - Home Assistant (home-assistant.io)
or create a template sensor based on this one Template - Home Assistant (home-assistant.io)
or use a template within a card to convert it.
…it boils down to the use you hae in mind, I an not guess this with above
EDIT: my preference would be in the card itself, adding sensors just for this is imo inefficient
1 Like
IMHO changing a device_class is a bad idea.
Better to use a custom card which may present the entity in a user-defined way - like template-entity-row.
code
type: entities
entities:
- entity: sensor.test_timestamp
- type: custom:template-entity-row
entity: sensor.test_timestamp
- type: custom:template-entity-row
entity: sensor.test_timestamp
state: >-
{{ as_datetime(states(config.entity)).date() }}
Care to add why? I did this twice as I similarly got annoyed about cards showing ‘in x minutes’
IMHO changing a device_class is smth like “changing a nature of data on a low level”; if some issue may be easily solved by a different presentation - then it should be done on a Frontend side.
Agree, my preference too (see above) but in the past when I just started…I did this twice and never had any issue
MelleD
June 24, 2023, 8:25pm
9
What information do you need exactly?
The sensor comes from the Home Connect integration and I’m currently only trying to convert the timestamp in the frontend.
Haven’t you been given possible solutions already?
MelleD
June 24, 2023, 9:20pm
11
No. Iam looking for a solution for “custom:mushroom-template-card”. And in your example I see not the same result, what I am looking for. Currently I play with “timestamp_custom” around
Not sure what you want to achieve but template stuff… alike this?
{{ as_datetime('2023-06-21T09:50:18+00:00').strftime("%A %d %H:%M") }}
will give you: Wednesday 21 09:50
or in your case
{{ as_datetime(states('sensor.waschmaschine_remaining_program_time')).strftime("%A %d %H:%M") }}
MelleD
June 25, 2023, 7:59am
13
@vingerha
Thats looks better
{{ relative_time(now()-timedelta(seconds =
as_timestamp(states('sensor.waschmaschine_remaining_program_time'))
- as_timestamp(now())))}}
petro
(Petro)
June 26, 2023, 11:45am
14
why are you doing all those calculations?
{{ relative_time(states('sensor.waschmaschine_remaining_program_time') | as_datetime) }}
MelleD
June 26, 2023, 12:32pm
15
Example:
{{ relative_time(states('sensor.waschmaschine_remaining_program_time') | as_datetime) }}
out put 2023-06-26 13:31:49+00:00
My output is.
57 minutes
or
1 hour
etc.
And this iam showing in the mushroom card template something like:
“The washing machine needs 57 minutes”
petro
(Petro)
June 26, 2023, 12:37pm
16
Ah, that’s a future time. That’s why.
MelleD
June 26, 2023, 1:47pm
17
Exact timestamp when the program ended (in future).
I still find it interesting that the entity card with device class timestamp displays it like this and not just the date and time or something like that
petro
(Petro)
June 26, 2023, 1:55pm
18
That’s what device_class does, it lets the frontend (and other aspects of HA) know what to do with the entities state. The filter/function relative_time does not work with future datetimes. Probably something that should be updated.
MelleD
June 26, 2023, 4:23pm
19
Yes off course but timestamp looks in every card a little different, correct?
petro
(Petro)
June 26, 2023, 4:24pm
20
Nope. They will always display relative time.
MelleD
June 26, 2023, 4:59pm
21
Ok I will check again, but for template card I have to do it, correct?
petro
(Petro)
June 26, 2023, 5:01pm
22
Yes you have to do it for a template. I did write a utility to handle this for people.
Hello community!
As you may know, 2023.4 offers a new global template macro option in Home Assistant.
How does this benefit you? The introduction of this feature allows me to easily share all the templates I’ve helped you create over the years in a single easy-to-use template library! All in your native language!
Introducing…
Easy Time Jinja
A 1-stop-shop for easy time calculations.
Get it from HACS!
These templates are now available in HACS, with a caveat. In order to see templat…
which would just be (after you install easy_time
)
{% from 'easy_time.jinja' import easy_time %}
{{ easy_time('sensor.waschmaschine_remaining_program_time') }}
1 Like