Liese
(Jörg)
April 26, 2020, 9:21am
1
Continuing the discussion from
Help Formatting Sun Events :
Hi,
I have got a custom component which provides an attribute ‘last_update’.
Time format (like in a.m. topic)
2020-04-26T11:00:00
YYYY-MM-DDThh:mm:ss
My template sensor definition works fine:
custom:
friendly_name: "Last Update"
unit_of_measurement: 'time'
value_template: "{{ state_attr('sensor.custom', 'last_updated') }}"
Can someone please give me a hint, how to adapt the code for the sun with timestamp command
(as in a.m. topic) for the above custom sensor?
I get stuck …
value_template: "{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom('%d.%m.%Y %-H:%M') }}"
Best regards,
Jörg
eggman
(bertie basset)
April 26, 2020, 9:44am
2
Not sure I understand the ask here. If you’re looking for a 12 hr clock with AM/PM then replace %H with %I to move from 24hr to 12 and add %p for AM/PM.
Liese
(Jörg)
April 26, 2020, 9:54am
3
The adaption of the expression is my problem.
I tried i.e. following to get the time available in Lovelace as
DD.MM.YYYY HH:mm
value_template: "{{ state_attr('sensor.custom', 'last_updated') | timestamp_custom('%d.%m.%Y % H:%M') }}"
but the Template checker returns:
“2020-04-26T11:00:00”
So it seems , that my approach is not correct.
The format I want to have finally is not of any importance - it is more a syntax question…
Regards
Joerg
eggman
(bertie basset)
April 26, 2020, 10:23am
4
Ah, OK - you need to convert the attribute to a timestamp first.
{{ as_timestamp(state_attr('sensor.custom', 'last_updated')) | timestamp_custom('%d.%m.%Y %H:%M') }}
You also have a space between the % and the H, but I expect you’d have noticed that.
5 Likes
Liese
(Jörg)
April 26, 2020, 10:34am
5
Perfect, thanks! That’s working.
1 Like