Truncate sensors value

Hi,

i’ve got this sensor:
{{states('sensor.last_fuel_top_up_ryd'}}
which gives me that value:
2021-09-13 10:43:20.296000

I’d like to truncate or crop the last 9 digits to show only date, hours and minutes. “round” doesn’t work since it’s not a number and “truncate” also doesn’t help.
Is there any other function I could use?

Best

Hello,

I think you can use this:

{{ as_timestamp(states('sensor.last_fuel_top_up_ryd')) | timestamp_custom('%Y-%m-%d %H:%M') }}

not sure if this works, don’t have anything to test right now.

1 Like

Works like charm! thx :+1:

1 Like

Last ten characters.

{{ states('sensor.last_fuel_top_up_ryd')[:-10] }}
3 Likes