How to: Solaredge lastUpdateTime as relative_time?

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

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:

because your format is always wrong :wink: 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 :wink:
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

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'))}}

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…

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') }}

gives:

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)}}

?

so that works?

using your code, i was saying do this

{{ update.hour }}

Ah I see sorry.

no doesn’t work:

Does it work with the hard coded value?

What version of HA are you running?

yes!

using HA 106.5

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 !

It’s 100% the format of the states() result because hardcoded works. try stripping whitespace with .strip() on the states() variable.