Help with states - only display date and convert seconds to minutes/hours

Hi

I’ve got a sensor which gives me the last date I went for a walk.

Activitity - {{ states('sensor.strava_0_0') }}

the result: 2021-09-22 15:21:39

But I only want to display the date. I don’t need timestamps. Can someone help with this?
image

/

Beside I’ve got another sensor which gives me the time elapsed of the activity.
The unit_of_measurement is saved in seconds but I want to see the minutes so for example: 45min
and if it is longer than an hour: 1:45 minutes
image

When I try this:

{{ states('sensor.strava_0_1') }}
I gives me the total of seconds like seen in the picture above.

Can someone help?

Thanks in advance!

You could write template sensor that will convert data from one sensor to the other sensor. For example display running time in hours, minutes and seconds.
The same is with first sensor. I would like to write you sensors for it but unfortunately I don’t know how.

1 Like

I think I managed to answer my second question. (not sure if another solution fit better though)

{{ states('sensor.strava_0_10') | int(0) | timestamp_custom('%H:%M', false) }}

gives me: 00:46 minutes

still looking for an answer for the first question…

Nope,

{{ (states('sensor.strava_0_10') | as_datetime | as_local).strftime("%H:%M") }}

hm strange because that gives me 01:46
I would expect 0:46:
image

where did he get the 1 from?

I made a mistake, I thought he was talking about this timestamp sensor, not the duration sensor. (question 1)

That template will work for his timestamp.

{{ (states('sensor.strava_0_0') | as_datetime | as_local).strftime("%H:%M") }}

For his duration, his template works as long as it doesn’t go over 24 hours.

EDIT: Apparently he is you. :rofl: I should pay attention more to who I’m replying to.

haha :smile:
I’ve got the sensor like I wanted, thanks for the input!