How to convert a "time"-string to a timestamp with today date

Hello,

i need some help. I got a time string from an mqtt device. It looks like 7:8 for 07:08 oclock.
I got to convert it via:

{{ strptime(states('sensor.b2500_time_2_end'), "%H:%M") }}

so i got: 1900-01-01 07:08:00
now i want to get this value to today at 07:08:00 when i want to add a today timestamp, this is from 1970 and i got a date around 1955.

{{ as_datetime((now().date() | as_timestamp) + (strptime(states('sensor.b2500_time_2_end'), "%H:%M") | as_timestamp)) }}

I got: 1955-02-23 05:08:00+01:00

when i add timezone()

{{ as_datetime((now().date() | as_timestamp) + (strptime(states('sensor.b2500_time_2_end'), "%H:%M") | as_timestamp)).astimezone() }}

i got 1955-02-23 06:40:00+01:00

is there a simple trick to get the right day to this time field. I used it for a start time my batterie begins to discharge on this day and i want to use this date for automatitions.

thanks for your help

Best Regards

strauch

{{ today_at(states('sensor.b2500_time_2_end')) }}

or if you prefer

{{ states('sensor.b2500_time_2_end') | today_at }}
1 Like

Wow this is too easy :slight_smile: thank you very much this works