Waze Travel Time - error

Very happy to see Waze has finally been implemented into Hass.
Can’t get it to work though.

sensors.yaml:

  - platform: waze_travel_time
    name: Waze to Work
    origin: '{{ states.device_tracker.bob_s8.attributes.longitude,states.device_tracker.bob_s8.attributes.latitude }}'
    destination: <My work address here>
    region: 'EU' 

error:

2018-04-14 09:45:56 ERROR (Thread-16) [homeassistant.components.sensor.waze_travel_time] Error on retrieving data: Internal Error
2018-04-14 09:45:56 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 260, in _async_add_entity
    await entity.async_update_ha_state()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 215, in async_update_ha_state
    state = self.state
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/waze_travel_time.py", line 79, in state
    return round(self._state['duration'])
KeyError: 'duration'

Doesn’t look like a config error to me. Anyone got it working?

I have successfully got it to work my config:

  • platform: waze_travel_time
    name: Bla Bla Name
    origin: 31.25405 , 34.79151
    destination: 31.2618 , 34.80911
    region: ‘IL’

i think your problem is with the info you get from
origin: ‘{{ states.device_tracker.bob_s8.attributes.longitude,states.device_tracker.bob_s8.attributes.latitude }}’

make sure the date you get gonna be in this format: LatitudeNUMBER , LongitudeNUMBER
(for instance 31.2618 , 34.80911)

(the same with destination format.)

you can use the livemap on waze to be sure you are in the right place: https://www.waze.com/livemap

@VirtualL Thanks.

Hmm, for some reason the output has parenthesis:

If I hardcode the origin address (as text, so not as coordinates), the component works. However, according to the component the travel time is 40 minutes. If I open Waze, it says 21 minutes (which is correct).
Does your sensor value make any sense?

I think you need to make the info you get from origin: ‘{{ states.device_tracker.bob_s8.attributes.longitude,states.device_tracker.bob_s8.attributes.latitude }}’
Useful by split it and use the right attributes from it. (don’t know how to do it. Sorry)

and my sensor shows the correct time because the origin and destination are relatively an easy way, on highways, not so much of hassle :slight_smile:

i think the difference between the time is because the route the sensor is taking (the fastest or the sorted) but I don’t know which one is chosen. just that you can click on the sensor info and see which route has been using for the calculations of time.

Shouldn’t it work like the google_travel_time component?

origin: device_tracker.<your device>
destination: zone.work

@firstof9 this gives a whole bunch of different errors:

2018-04-14 16:33:44 ERROR (MainThread) [homeassistant.components.sensor] waze_travel_time: Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 326, in connect
    ssl_context=context)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.5/ssl.py", line 385, in wrap_socket
    _context=self)
  File "/usr/lib/python3.5/ssl.py", line 760, in __init__
    self.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 996, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 641, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/connection.py", line 326, in connect
    ssl_context=context)
  File "/srv/homeassistant/lib/python3.5/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.5/ssl.py", line 385, in wrap_socket
    _context=self)
  File "/usr/lib/python3.5/ssl.py", line 760, in __init__
    self.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 996, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 641, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 188, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 327, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/waze_travel_time.py", line 103, in update
    self.waze_data.update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 319, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/waze_travel_time.py", line 126, in update
    self._origin, self._destination, self._region, None)
  File "/srv/homeassistant/lib/python3.5/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 35, in __init__
    self.start_coords = self.address_to_coords(start_address)
  File "/srv/homeassistant/lib/python3.5/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 57, in address_to_coords
    response = requests.get(self.WAZE_URL + get_cords, params=url_options)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Perhaps file a issue/suggestion for the component on Github requesting this type of function?

Also doesn’t work:

"{{ (states.device_tracker.bob_s8.attributes.longitude,states.device_tracker.bob_s8.attributes.latitude)| replace('(', ' ')| replace(')', ' ') }}"

Nope, I checked and it’s using the same route.

Hass:
image

All route options from Android phone:

This is what I get when avoiding freeways:


Time checks out with Hass, distance does not however.
Also, A15 is a freeway so it doesn’t make sense.

I was hoping the same, but having a quick look on GitHub reveals that the code for the Waze component nowhere has a mention of the zone.

What I currenlty do is to use the secrets.yaml file containing all latitude and longitude coordinates as the following snippet shows

sensors.yaml

- platform: waze_travel_time
  name: Work Travel Waze
  origin: !secret gps_coordinates_home
  destination: !secret gps_coordinates_work
  region: EU

secrets.yaml

gps_coordinates_work: 50.9999999, 4.9999999

in my case my waze sensor is reporting correct times and distances, but it randomly alternates between reporting the fastest and 2nd fastest routes (the fastest route in my case is shortest in time and distance).

something funny seems to be going on; i don’t know if it’s because of waze or the hass component.

Hello my friend @Bob_NL i use this configuration

sensor:
  - platform: waze_travel_time
    origin: zone.notrabalho
    destination: zone.home
    region: 'EU'

and i have these errors:

2018-04-17 21:16:57 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.waze_travel_time
2018-04-17 21:16:57 DEBUG (SyncWorker_15) [homeassistant.components.sensor.waze_travel_time] Update in progress...
17T21:16:59.605797+01:00>>
2018-04-17 21:17:00 ERROR (SyncWorker_15) [homeassistant.components.sensor.waze_travel_time] Error on retrieving data: Internal Error
2018-04-17 21:17:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: timestamp=1523996220.1759949, level=ERROR, message=Error on retrieving data: Internal Error, exception=, source=components/sensor/waze_travel_time.py>
2018-04-17 21:17:00 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 260, in _async_add_entity
    await entity.async_update_ha_state()
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 215, in async_update_ha_state
    state = self.state
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/waze_travel_time.py", line 79, in state
    return round(self._state['duration'])
KeyError: 'duration'
2018-04-17 21:17:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: timestamp=1523996220.199122, level=ERROR, message=Error doing job: Task exception was never retrieved, exception=Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 260, in _async_add_entity
    await entity.async_update_ha_state()
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 215, in async_update_ha_state
    state = self.state
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/waze_travel_time.py", line 79, in state
    return round(self._state['duration'])
KeyError: 'duration' 

how can solve it? did you know? Thanks

@Rodolfo_Vieira does it work when you enter the adresses as text?

I’m not sure when waze was added, but it looks like the response from the api does not contain the key ‘duration’. Looking at the source, if the updating the drive time fails with an error, the dictionary could not be completely populated. He should have a try: except KeyError: or he should be pre popluating the dictionary with empty strings.

FYI, it appears that none of these config locations accept templates. So all {{}} will fail. I also don’t think using zones will work either. It appears that it needs to be hard coded gps locations.

If that is the case, than this component is useless for my needs unfortunately. I hope that it will support templating soon!

well, i just confirmed that it requires hard coded strings. Its using cv.string, not cv.template. I don’t even know if templating works during setup. So even if he changed it, it may not work still.

agree. zones don’t work. GPS coords as well as full street addresses do.

That makes sense, the component just passes the undoctored string from your config to the waze API.

yes if i put the cordenates works fine, but zone no.