Time format in a telegram message

I’m trying to format the time that is send in a telegram message to a group.
I’ve searched and tried a few changes but nothing worked.

Currently it ends with:
“back by 2023-04-13 16:30:00”
But I want it to end with:
“back by 16:30”

Basically, formatted with only HH:MM

The code:

service: telegram_bot.send_message
data:
  message: >-
    🔌 - Load shedding currently on {{
    state_attr('calendar.loadshedding_local_events', 'message')}}. Power is
    expected to go off in 10 minutes and should be back by {{
    state_attr('calendar.loadshedding_local_events', 'end_time')}}.
  target: -************
enabled: true
data:
  message: >-
    🔌 - Load shedding currently on {{
    state_attr('calendar.loadshedding_local_events', 'message')}}. Power is
    expected to go off in 10 minutes and should be back by {{
    state_attr('calendar.loadshedding_local_events', 'end_time').strftime('%H:%M') }}.

Found the solution on another post.
“States are always strings”

 Power should be back by {% set dt =
    state_attr('calendar.loadshedding_local_events', 'end_time') | as_datetime |
    as_local %}{{ dt.strftime("%H:%M") }}.

Did my solution not work?

I see an extraneous period at the end of the template I posted.

Hi
No, didn’t work. But used it to search with and came across the solution.
Apparently the field is not formatted as a date but a string.

image

1 Like