Time since template sensor

I have a sensor showing the last time my Neato bot cleaned:

states.vacuum.alecs_neato.attributes.clean_start

It gives a value such as:

2018-09-14 13:56:52

I’d like to display this in a more useful format, such as:

14th Sep at 13:56 (2 days ago)

Any suggestions?

A template like this might be close to what you’re looking for:

{% set last = strptime(
     state_attr('vacuum.alecs_neato', 'clean_start'), '%Y-%m-%d %H:%M:%S') %}
{{ last.strftime('%d %b')
}} at {{ last.strftime('%H:%M')
}} ({{ now().replace(microsecond=0, tzinfo=None) - last }} ago)
1 Like

Works great, thank you!