Template adjust datetime

Hi Guys,
we are using BabyBuddy to automate our child :slight_smile: so one thin we would like to know is the time he is awake, therefore I use a attribute of the “lastsleepsensor” in an template:

- sensor:
  Baby_wach_seit
    value_template: "{{( now()- as_datetime(state_attr('sensor.baby_last_sleep', 'end'))) }}"

which returns something like:

1:06:07.691303

what is a good way to get this nicer like:

1:06

or is there a better way altogether?

Thanks!

{{ (now() - state_attr( 'sensor.baby_last_sleep', 'end')).total_seconds() | timestamp_custom('%H:%M', false) }}

This produces an approximation:

{{ relative_time(state_attr('sensor.baby_last_sleep', 'end')) }}

thanks a lot!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

You marked your own post with the Solution tag. The tag’s purpose is to identify the post containing the solution, which is actually in my reply to your first post. Please consider marking my post above with the Solution tag.