Waze Arrival Time - (add "duration" to sensor.time) Help please....?

Hi fellow Home Assistant wizards,

I’d like to display the arrival time by adding the WAZE sensor “duration” to the current time.
eg. (duration sensor) 31 min + (sensor.time) 09:00am = arrival time 09:31am

EXAMPLE:
image

I’m guessing this can be done by “templating” but I am having no luck - I’ve searched through all the forums that I could find on the topic, but not having any luck finding an answer that I can work with.

I also want to use this “arrival time sensor” to create triggers etc for other automations. :slight_smile:

Any assistance will be greatly appreciated.

Thanks in advance

Paul.

I do it this way (in a Telegram notification):

          message: >
            {% set minutes = states('sensor.xxx_to_home') | int %}
              xxx should be home in about {{ minutes }} minutes at {{ (as_timestamp(now()) + (minutes * 60)) | timestamp_custom('%H:%M') }}.
            {% endif %}

Hi @klogg

Many thanks for contributing, but unfortunately (due to my lack of skills and or understanding) I’m not sure how to work with your code and I don’t think it’s quite what I’m after.
I need to be able to add minutes/hours to the current time and store the result in a “sensor” so I can display it in LoveLace UI and use it for other automations.

Thanks anyway :slight_smile:

Ok, this is the bit you need

{{ (as_timestamp(now()) + (minutes * 60)) | timestamp_custom('%H:%M') }}

where minutes is the waze travel time sensor.

  - platform: waze_travel_time
    name: Me To Home
    origin: device_tracker.me
    destination: zone.home
    region: 'EU'

and then something like

  - platform: template
    sensors:
      me_home_time_of_arrival:
        friendly_name: Time I get home
        value_template: >
          {% set minutes = states('sensor.me_to_home') | int %}
          {{ (as_timestamp(now()) + (minutes * 60)) | timestamp_custom('%H:%M') }}

I think that should work (or be close :slight_smile: )

as_timestamp(now()) is the time now in the number of seconds since the beginning of time (1st Jan 1970 I think but it doesn’t actually matter in this case).
(minutes * 60) is the minutes Waze is reporting converted to seconds and
| timestamp_custom('%H:%M') reformats it to hours and minutes.

I hope that is more helpful.

1 Like

G’day @klogg!

You are a superstar!!
Thank you very much!!
This worked… almost - The only question… due to the delay in when WAZE updates it’s sensor ( refresh is >10mins I think) This also means that this sensor doesn’t update and do it’s calculation until WAZE updates…

image

meaning…

  • if WAZE sensor was 30min to destination + current time 9:00am, arrival sensor would say 9:30am
  • if another 10 mins goes past and the WAZE sensor has not updated, the arrival sensor will still say 9:30am even though 10 mins has passed…

I’d like to be able to “refresh” the arrive sensor every 30sec/1min if possible?

Any thoughts?

Would using ‘sensor.time’ increase refresh frequency? (as I believe this refreshes at least every minute)

Yes, HA tries to work out when it should update the sensor by looking at what entities are defined. In this case as it is written it will happen on a change in sensor.me_to_home.

If you add something else explicitly it can (as you say) force an update e.g.

  - platform: template
    sensors:
      me_home_time_of_arrival:
        friendly_name: Time I get home
        entity_id: sensor.time
        value_template: >
          {% set minutes = states('sensor.me_to_home') | int %}
          {{ (as_timestamp(now()) + (minutes * 60)) | timestamp_custom('%H:%M') }}

I am not sure if time updates every minute or every second.

4 Likes

That fixed it!! :smiley:
By adding the sensor.time entitiy, it now updates every minute even if the WAZE entity hasn’t updated, therefore “arrival time” is accurate!

image

Thanks again @klogg you’ve been a great help and you’ve taught me a thing or two as well.
Very much appreciated!

@klogg…Legend!

1 Like

Hi,
trying to do the same, can you please share your part of the code (sensors/template) for the waze card?
Thanks !

Hi @itayr,
Apologies for the delay. Please see below:

The following sets up the WAZE sensor:

sensor:
    # WAZE Travel Times
    - platform: waze_travel_time
      name: Paul - Time to work
      origin: "insert home address here"
      destination: "insert work address here"
      region: 'AU'
      

The following is a template sensor to calculate the “arrival time” of when I would get to work

  - platform: template
    sensors:
      paul_work_time_of_arrival:
        friendly_name: Paul arrive time
        entity_id: sensor.time
        value_template: >
          {% set minutes = states('sensor.paul_time_to_work') | int %}
          {{ (as_timestamp(now()) + (minutes * 60)) | timestamp_custom('%H:%M') }}  
         

Results:
current time= 11:44am
time to work = 30 min
arrival at work = 12:14pm

image

Hope this helps :slight_smile:

1 Like