Timedelta for EV Arrival Time to Household Members

In order to send a notification to my household members when I’ll arrive, I was hoping to be able to send them a notification as to how long it’ll take until the EV would arrive back home. The Tesla Integration has a sensor for that, but I can’t seem to wrap my head around how to make it work. From what I understand I should be using as_timedelta here, but I appear to be doing something wrong:

service: notify.notification_devices_household_primary
data:
  title: EV is coming home
  message: "Arrival in {{ as_timedelta(states('sensor.ev_arrival_time')) }}. "

Which prints:

Arrival in 2023-07-02T17:13:34+00:00

Previously, I’ve used the following but that appeared to give very mixed results:

service: notify.notification_devices_household_primary
data:
  title: EV is coming home
  message: "Arrival in {{ (as_timestamp(states('sensor.ev_arrival_time')) - as_timestamp(utcnow())) | timestamp_custom('%Hh %Mm %Ss',false) }}. "

The idea is to show the value as is shown in my dashboard (which will also show future time in this format):

image

I’d like to use this “relative” formatting also in my message (so in x time and x time ago) as the polling-nature of the Tesla integration could, theoretically, imply that the message is (was) sent at the moment that another poll would mark the arrival time as in the past.

Would anyone be able to help, guide, to what I am so obviously missing here?

EDIT: I found this Relative_time for the future - Development - Home Assistant Community (home-assistant.io). Does that mean it’s not there yet? That it is something that can be done in the frontend - but not in the backend/a notification?

relative_time is fairly new but does exist as per the documentation:
https://www.home-assistant.io/docs/configuration/templating/#time

I think you want something like this:

{{ relative_time(as_datetime(states('sensor.ev_arrival_time'))) }}

Relatively, because:

“Note that it only works for dates in the past.”

Doh! You’re right. But in the thread you linked is a solution you can use until the PR is merged:

https://community.home-assistant.io/t/relative-time-for-the-future/509551/11

I just tested it and it seems to work well.

1 Like

Thanks, that works !!!