using
solaredge_last_updatetime:
friendly_name: 'SolarEdge last update'
value_template: >
{{state_attr('sensor.solaredge_overview','lastUpdateTime')}}
yields:
which I would like to show with relative_time.
{{relative_time('sensor.solaredge_last_updatetime')}}
doesn’t work though.
Nor does:
{{relative_time(strptime(states('sensor.solaredge_last_updatetime'), '%d-%m-%Y'))}}
How should I format this sensor to be able to use the relative_time?
thanks for having a look
petro
(Petro)
March 10, 2020, 11:22am
2
it’s gotta be a datetime object. Says so in the documentation.
So convert it using the proper strptime format (you should know how to do this by now…). The use that inside relative_time. You’re close on your second result but your format is wrong. Use strftime.org to figure it out.
yes, hence the strptime template.
and of course I use the strftime.org source…
thing is, no matter what I try in the format, it always gives the same result:
petro
(Petro)
March 10, 2020, 11:42am
4
because your format is always wrong so it just passes what string it has through
Also, it’s possible it’s already a datetime object. Meaning you might not have to convert it.
haha yes probably
only other example I have in my setup is:
{{ relative_time(states.binary_sensor.hassio_rpi4.last_changed) }}
But that’s what I tried in the top template first post isn’t it?
see this:
I can get it to show relative time on last_changed, but not on the state of the sensor…whihc is actually another time
petro
(Petro)
March 10, 2020, 11:53am
6
So it’s definitely not a datetime, it’s a string. So your format is wrong.
So please, using strftime.org tell me what the format for just year is?
What’s the format for just month?
What’s the format for just day?
What’s the format for just hour?
what’s the format for just minute?
what’s the format for just second?
had tried this before, taking all those ‘just’ formats and collecting them like the sensor does:
{{relative_time(strptime(states('sensor.solaredge_last_updatetime'), '%Y-%m-%d %H:%M:%S'))}}
petro
(Petro)
March 10, 2020, 12:02pm
8
Mariusthvdb:
‘%Y-%m-%d %H:%M:%S’
That’s the correct format. So is it still not working?
no, main template still showing what is does with any code:
and trying relative_time on that:
sorry but the template editor is too wide for the screen…
petro
(Petro)
March 10, 2020, 12:10pm
10
just try this
{{ strptime(states('sensor.solaredge_last_updatetime'), '%Y-%m-%d %H:%M:%S') }}
{{ strptime('2020-03-10 12:53:14', '%Y-%m-%d %H:%M:%S') }}
petro
(Petro)
March 10, 2020, 12:36pm
12
try setting them both to a variable and get out the .hour
sorry Petro, but I don’t follow…
setting a variable is ok, but do you want me to do this:
{% set update = strptime(states('sensor.solaredge_last_updatetime'), '%Y-%m-%d %M:%S') %}
{{relative_time(update)}}
?
petro
(Petro)
March 10, 2020, 1:37pm
14
so that works?
using your code, i was saying do this
{{ update.hour }}
petro
(Petro)
March 10, 2020, 1:45pm
16
Does it work with the hard coded value?
What version of HA are you running?
petro
(Petro)
March 10, 2020, 1:57pm
18
try separating the states() into it’s own variable then.
keep getting the identical results
fear I must let it go, frustrating as it is…thanks for you relentless help !
petro
(Petro)
March 10, 2020, 3:28pm
20
It’s 100% the format of the states() result because hardcoded works. try stripping whitespace with .strip() on the states() variable.