Create relative time template sensor from timestamp entity

I have a sensor entity ‘sensor.wasmachine_remaining_program_time’ with entity-type ‘timestamp’ which displays correctly in an entities card, but doesn’t display correctly in other places like an Android Widget, or in a custom theme I use (Dwains Dashboard).

Within the entities card the timestamp gets the proper/desired ‘relative time’ formatting, like ‘In 2 hours’, or ‘5 minutes ago’:

good

In the widget or in ‘Dwains Dashboard’, the actual timestamp value is shown:

bad

I’ve tried getting it to work by creating a template sensor which outputs the relative time as a string, but haven’t been very successful. Can anyone help me with this?

Nobody? Does someone know if this is even possible?

I have the same question. Did you find a solution?

Nope, unfortunately…

me too:

I tried this but no luck… maybe you can spot what I did wrong?

value_template: '{{ (((as_timestamp(now()) - as_timestamp(states("sensor.cert_expiry_timestamp_com_8123")) | int /60/1440) | round(0) }}'

The …_8123 sensor contains a timestamp (i believe) as it displays this on the overview:

2021-04-08T08:52:05+00:00

All I would like to do is to display the number of days between that date and now()

Cheers

SOLVED

cert_expiry_days:
        value_template: '{{ ((as_timestamp(states("sensor.cert_expiry_timestamp_8123")) | int /60/1440) - (as_timestamp(now()) | int /60/1440)) | round(0) }}'
        friendly_name: "Days till cert expiry"