Setting up sensor with as_timestamp

I i am trying to add a sensor that only shows the hour and minute my train leave, this is my sensor.

I have set this up as a sensor, with this value_template

{{ as_timestamp(strptime(states.sensor.hadsten_ekspressen.attributes['due_at'], "'%Y.%m.%d H:%M'")) | timestamp_custom("%H:%M") }}

But it keeps getting “None” as its output

remove the extra quotes. "'%Y.%m.%d H:%M'" -> "%Y.%m.%d H:%M"

Hi, i tried removing quotes, and fixed a mistake with a missing “%” in front of the “H” in "%Y.%m.%d H:%M" but the template still outputs None

well, then just split it

{{ state_attr('sensor.hadsten_ekspressen', 'due_at').split(' ')[-1] }}
1 Like

Thank you so much, it is working now

you had your strptime syntax wrong.

It should have been like this:

{{ as_timestamp(strptime(states.sensor.hadsten_ekspressen.attributes['due_at'], '%d.%m.%y %H:%M')) | timestamp_custom("%H:%M") }}

that’s assuming of course that your “due_at” attribute gets returned in the correct matching format.

you didn’t post it in the correct json text format so I couldn’t easily copy into my template editor to test it but I think it looks OK.

1 Like

Thank you is working perfectly now