Waze travel time update

with this you mean a sensor with a zone or an entity_id as its state? Because the way it is written in the docs, I dont think anyone can blame a user to think this is what was prescribed.

Would be really nice if it could be PR’d like that @eifinger, because otherwise we would need to hardcode all of those lat/lon coordinates in the sensor…

unless there is another way for the sensor build of course, must have a look at that yet.

Thanks for the PR! I’ll check it as soon as I hit ← reply :wink:

I like the changes and the base class looks good. I honestly don’t care about the attributes that the base class has either, so what you have is good in my book. Ijmerza was very particular about that though because he makes the ‘travel time card’ for lovelace.

No… change your sensor template…

        value_template: >
          {% set entity_id = states('input_select.waze_destination') %}
          {% set lat = state_attr(entity_id, 'latitude') %}
          {% set lon = state_attr(entity_id, 'longitude') %}
          {{ lat }}, {{ lon }}
1 Like

@petro @Mariusthvdb what are your thoughts on my latest idea on this, using templates:

https://github.com/home-assistant/home-assistant/pull/28716#issuecomment-565068399

while I was posting some other issues, you beat me to even start thinking about it :wink: Thanks!

update:

working perfectly!
too bad it shows the lat/lon now in the Lovelace card also, but all travel times appear nicely.
Ive added an update script so I don’t have to wait for the Waze update…

Looks good. Is the get_coordinates_from_entity a new method in templates?

Exactly, it would be if I implement it this way. I just came up with this solution proposal a few minutes ago.

EDIT: If the two of you want to discuss this further I invite you to do so directly on my PR to keep this thread here clean.

1 Like

@sd_dracula its been some time since you asked but here is my config using https://github.com/thomasloven/lovelace-card-mod:

- entity: sensor.travel_time_home_from_work_here
    style: |
      :host {
        --paper-item-icon-color:
          {% if states(config.entity) | float < state_attr(config.entity, 'duration') | float * 1.1 %}
            green;
          {% elif states(config.entity) | float < state_attr(config.entity, 'duration') | float * 1.3 %}
            orange;
          {% else %}
            red;
          {% endif %}
          }

I would like to be able to determine what the travel time is from a device_tracker to zone.home such that I can create an automation that fires off when the device_tracker is 30 minutes away. Do you have any suggestions on how to accomplish this?

Couldn’t be any easier than:

sensor:
  - platform: waze_travel_time
    name: To Zone
    origin: device_tracker.<name>
    destination: zone.home

use this automation trigger to get what you want. But be warned, this only updates every 5 minutes and it won’t know if the device_tracker is actually heading in the direction of zone.home. You could be going to the gym or something and it would trigger because you happen to be < 30 minutes away.

trigger:
  - platform: numeric_state
    entity_id: sensor.waze_travel_time
    below: 30

using this myself:

  - alias: 'Marijn bijna thuis'
    id: 'Marijn bijna thuis'
#    initial_state: 'on'
    trigger:
      platform: numeric_state
      entity_id: sensor.waze_marijn_home
      below: 15
      above: 5
    condition:
      - condition: template
        value_template: >
          {{ state_attr('proximity.marijn_home', 'dir_of_travel') == 'towards' and
             states('device_tracker.life360_marijn') != 'home' }}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_presence', 'on')}}
    action:
      service: notify.marijn
      data_template:
        message: >-
          Marijn is op {{states('proximity.marijn_home')}} kilometer van huis,
          en is over {{states('sensor.waze_marijn_home')}} minuten thuis!

or a bit more complex, but more fun too:

  - alias: 'IOS - Espresso actions when near home'
    id: 'IOS - Espresso actions when near home'
    trigger:
      - platform: template
        value_template: >
          {{ state_attr('proximity.marijn_home', 'dir_of_travel') == 'towards'}}
      - platform: template
        value_template: >
          {{ 1 < states('sensor.waze_marijn_home')|float < 15 and
             states('device_tracker.life360_marijn') != 'home' }}
    condition:
      - condition: template
        value_template: >
          {{ state_attr('proximity.marijn_home', 'dir_of_travel') == 'towards'}}
      - condition: template
        value_template: >
          {{ 1 < states('sensor.waze_marijn_home')|float < 15 and
             states('device_tracker.life360_marijn') != 'home' }}
      - condition: template
        value_template: >
          {{ is_state('switch.sw_espresso_keuken_template','off')}}
      - condition: time
        after: '06:00:00'
        before: '22:00:00'
    action:
      service: notify.mobile_app_calltheboss
      data:
        title: iOS alt
        message: 'Wil je vast de Espresso aanzetten?'
        data:
          push:
            badge: 2
            sound: US-EN-Morgan-Freeman-Motion-In-Kitchen.wav
            category: 'espresso'
          action_data:
            entity_id: switch.sw_espresso_keuken_template

both need proximity sensors

1 Like

Im trying to accomplish a dynamic waze time updater ,
I have in zone.yaml several zones .
i separate waze to waze,yaml
where i try to implement @petro suggestion for the templates
and also @Mariusthvdb for the sensors .

Im not sure i define the the input_select correctly as actually they are duplicated,
with just different name.
What is the automation that calculate the origin to destination ?

Is that correct if I want to use the zones i have in zone.yaml?
How
second, I’m working on some telegram actionable notifications
which later i want add the option to get the expected arrival time
from the current location to desire destination ,
is some1 done something similar?

my waze.yaml

sensor:
  - platform: template
    sensors:
      destination_address:
        friendly_name: Destination
        value_template: >
          {% set entity_id = states('input_select.waze_destination') %}
          {% set lat = state_attr(entity_id, 'latitude') %}
          {% set lon = state_attr(entity_id, 'longitude') %}
          {{ lat }}, {{ lon }}
        icon_template: mdi:map-marker-path

      origin_address:
        friendly_name: Origin
        value_template: >
          {% set entity_id = states('input_select.waze_origin') %}
          {% set lat = state_attr(entity_id, 'latitude') %}
          {% set lon = state_attr(entity_id, 'longitude') %}
          {{ lat }}, {{ lon }}
        icon_template: mdi:map-marker

  - platform: waze_travel_time
    name: 'Select Origin Destination'
    origin: sensor.origin_address
    destination: sensor.destination_address
    region: 'IL'
         
         
            
input_select:
  waze_origin:
    name: waze_origin
    options:
      - Home
      - Avi Work
      - Karin Work
      
  waze_destination:
    name: waze_destination
    options:
      - Home
      - Avi Work
      - Karin Work      


I check the code:

Imitate available variables:
 {% set entity_id = states('zone.karin_Work') %}
          {% set lat = state_attr('zone.karin_Work', 'latitude') %}
          {% set lon = state_attr('zone.karin_Work', 'longitude') %}
          {{ lat }}, {{ lon }}

The lan and lon are {{ lat }} {{ lon }}

return:
"The lan and lon are xx.82405 yy.081299"

so it does work with zone correctly
The problem from some reason the sensor don’t get this values

sensor:

      origin_address:
        friendly_name: Origin
        value_template: >
          {% set entity_id = states('input_select.waze_origin') %}
          {% set lat = state_attr('entity_id', 'latitude') %}
          {% set lon = state_attr('entity_id', 'longitude') %}
          {{ lat }}, {{ lon }}
        icon_template: mdi:map-marker

It’s look in the developer states as “none,none”

Any idea?

You have to use entity_id’s in your input_selects. You can’t use friendly names. That’s your problem.

1 Like

Thanks @petro - nice catch !

now both sensors destination and origin holds the lan,lon values,
and select_origin_destination - return the time and destination.
But it’s not being refresh in reasonable time (about ~3-4 minute),
is there an way get trigger it faster?

I want to create automation which send notification automatically when i leave predefined zone.

You can try to call the service homeassistant.update_entity.

yep, that’s what I use:

script:
  update_waze_dynamic:
    alias: Update Waze dynamic
    icon: mdi:update
    sequence:
      - service: homeassistant.update_entity
        entity_id: sensor.select_origin_destination

and sensors:

  - platform: template
    sensors:
      destination_address:
        friendly_name: Destination
        value_template: >
          {% set destination = states('input_select.waze_destination') %}
          {% set lat = state_attr(destination, 'latitude') %}
          {% set lon = state_attr(destination, 'longitude') %}
          {{ lat }}, {{ lon }}
        icon_template: mdi:map-marker-path

      origin_address:
        friendly_name: Origin
        value_template: >
          {% set origin = states('input_select.waze_origin') %}
          {% set lat = state_attr(origin, 'latitude') %}
          {% set lon = state_attr(origin, 'longitude') %}
          {{ lat }}, {{ lon }}
        icon_template: mdi:map-marker


  - platform: waze_travel_time
    name: 'Select Origin Destination'
    origin: sensor.origin_address
    destination: sensor.destination_address
    region: 'EU'

Lovelace:

  - type: entities
    title: Dynamic Waze travels
    show_header_toggle: false
    entities:
      - input_select.waze_origin
      - input_select.waze_destination
      - sensor.origin_address
      - sensor.destination_address
      - entity: script.update_waze_dynamic
        action_name: Update
      - type: custom:waze-card
        title: Travel time
        entities:
          - entity: sensor.select_origin_destination

note the elevated Travel time Waze card. I purposely didn’t style it, because I kind of like the effect right now.

5 Likes

Thanks @Mariusthvdb , @eifinger ,@petro
I added the homeassistant.update_entity and it works perfectly ,

@Mariusthvdb
for the UI part, I see u are using some custom card,
is it possible to install it via hacks?

probably, but I don’t use HACS, sorry