Rasmusoeh
(Rasmus Østergaard)
1
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
petro
(Petro)
2
remove the extra quotes. "'%Y.%m.%d H:%M'"
-> "%Y.%m.%d H:%M"
Rasmusoeh
(Rasmus Østergaard)
3
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
petro
(Petro)
4
well, then just split it
{{ state_attr('sensor.hadsten_ekspressen', 'due_at').split(' ')[-1] }}
1 Like
Rasmusoeh
(Rasmus Østergaard)
5
Thank you so much, it is working now
finity
6
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
Rasmusoeh
(Rasmus Østergaard)
7
Thank you is working perfectly now