Remove date from sensor


I have a sensor on my washing machine that reports the end time to HA as “2024-02-14T17:28:00+00:00”. How would I go about removing the date and just keeping the time, bonus points for formatting the time in a 12hr format.

So “2024-02-14T17:28:00+00:00” would be reported as “5.28pm”

Thanks all :pray:

{{ (states('sensor.example_washing_machine_complete')|as_datetime|as_local).strftime('%-I:%M%p') }}

Template sensor with state template:

{{ states('sensor.why_does_noone_ever_supply_this')
   |regex_replace("^0","") }}

Edit: Ninja’d by Drew, and learned about %-I in the process, although 12-hour clock is objectively wrong.

1 Like
{{ states('sensor.washing') | as_timestamp | timestamp_custom('%-I.%M%p') }}

I normally use a colon to separate hours and minutes but if you want a period, the template uses a period.

1 Like

Amazing will try these tonight.
Thanks all much appreciated.