#Entity card showing full date+time

1 messages · Page 1 of 1 (latest)

snow tartan
#

Hi,

I have an entity card with:

`type: entity
entity: sensor.washing_machine_remaining_program_time
name: "Washing machine finished at:"
state_color: true
visibility:

  • condition: state
    entity: switch.washing_machine_power
    state: "on"
    `
    Which displays the full time and date the washing machine will be finished (ie 16 October 2024 at 15:07). What's the best way to just show the HH:MM?

Thanks!

dusty viper
#

Either with a Mushroom template card using a template of {{ as_datetime(states('sensor.washing_machine_remaining_program_time')).strftime('%H:%M') }} or a template sensor helper with the same template.

novel token
#

time_since is also useful for this I find

dusty viper
#

Yeah, but time_since()/time_until() gets weird with displaying multiple portions... so time_since(sensor, 2) could be 12 days 3 hours. Etc.

snow tartan
#

Thanks for the replies!

Like this?

It's showing unknown even though it should say 15:05

dusty viper
#

Yeah, but it looks like the single quote is wrong. Try removing the quotes and readding them. They get wonky coming out of discord sometimes.

#

Ugh. no

#

Remove the timestamp class

#

You just want a string.

novel token
#

yeah i normally only keep it to 1 when doing something like that , if it's at 12 days i don't care about hours ^^

snow tartan
#

Great thanks, but now it's showing the time in UTC (2 hours behind). What's the best way to solve this?

Thanks again

novel token
#

urggghhh timezonesss

dusty viper
#

Crap. That's my bad... change as_datetime to as_local.

#

Sorry about that.

novel token
#

try: {{ as_timestamp(states('sensor.washing_machine_remaining_program_time')) | timestamp_custom('%H:%M') }}

dusty viper
#

I was told as_timestamp is a bad idea and as_local was a better solution.

novel token
#

good to know

dusty viper
#

-# Granted, I have that template ALL OVER THE PLACE...

snow tartan
#

Hmm shows as 'Unavailable'

dusty viper
#

Show a screencap again?

snow tartan
#

Also unavailable if I use strftime instead of timestamp_custom

novel token
#

what if you just strip everything other than the states() bit

snow tartan
#

Like this?

#

Or this

novel token
#

the latter

#

1 sec, brb ^^

#

OH

#

it's because your sensor is not returning a local time

#

it has a timezone of +00:00

snow tartan
#

Yeah, but home assistant seems to be aware somewhere, as the default entity card shows the correct time

(same sensor)

novel token
#

ok, back to testing...

#

{{ as_local(as_datetime(states('sensor.washing_machine_remaining_program_time'))).strftime('%H:%M') }}

snow tartan
#

Waheey, it worked. Thanks!

#

I see why the as_local wasn't working now

#

needed to be parsed to datetime

novel token
#

problem with datetimes, i hate it so much my brain forgets the information i learn every time i struggle with them, which means i hate them even more the next time as i need to remember why it works