Add Time from sensor to Time now

Hello all, I’m trying to create an automation that adds the time from a sensor to the current time.

I currently have a waze sensor that calculates the time it will take me to reach home which gets triggered once I leave work - I’m struggling to figure out how to format this in yaml and have the following:

message: Chris will be home around {{ ( as_timestamp(now()) + (15 * ( {{ states (‘sensor.chris_time_from_work’) }} ) ) | timestamp_custom(‘%I:%M %p’) }}

Any ideas what’s wrong with this format?

Don’t know if it will help you but this give the current time in that format 00:00 PM

{{ now().strftime(’%I:%M %p’) }}

Don’t have the code for you in detail, but I’d probably do it this way

  1. Create an input_datetime for the time you leave the office, e.g. input_datetime.chris_has_left_the_building
  2. When you leave the office have the current time pushed to the input_datetime by an automation and add 15 x 60 seconds, e.g.
    - service: input_datetime.set_datetime
      data_template:
        entity_id: input_datetime.chris_has_left_the_building
        time: '{{ (as_timestamp(now() + 15*60) | timestamp_custom("%H:%M:%S", true)) }}'
  1. Display this value in your frontend and set it to nothing or a very specific value once you arrive home.
  2. Use a filter_entity card to only show the value after you leave the office and before you arrive at home.

EDIT:
Ooops - might have misunderstood your post.
Not sure where your 15x comes from, though.

I might have used the 15 by accident - I had a partial response from someone else.

But you’re idea might be the way to go. Make a input_datetime, and add the sensor travel time to the current datetime when the automation runs, then print that value to a message?

Yes, you are using templates inside tempaltes. A template does not need to be recursive. It’s flat code. I.E. Don’t put {{}} inside {{}}.

Chris will be home around {{ (as_timestamp(now()) + 15 * states ('sensor.chris_time_from_work') | float) | timestamp_custom('%I:%M %p') }}
1 Like

Ah I see, I thought it might be something like that - that thank you!