Lovelace: Travel Time Card

Okay, I hate doing this, but can someone explain how we pull multiple rows/destinations out of the waze component? the waze sensor only contains a single origin and destination. But this card pulls multiple locations out of the waze component? I’ve spent a while trying figure out exactly how to do this, (and read a ton), but I just can’t wrap my head around how the waze sensor gets to the love-lace ui and populates multiple fields in that card.

So im thinking that the waze platform can’t apply to 2+ routes, because it already has the origin/destination in it. Which would mean that I’d need to create multiple platforms, like _waze_travel_time_home, or something like that? but I thought the platform was somehting called on, not just created out of thin air. I guess i’m just looking for some clarification if possible? I’ve looked through all of the lovelace docs and HA docs I could find, and I honestly just cannot figure out how this works. I’m seriously lost, and this would appreciate any advice/guidance/tips I can get. Thanks!

Waze component template is this:

# Example entry for configuration.yaml
   sensor:
     - platform: waze_travel_time
       origin: Montréal, QC
       destination: Québec, QC
       region: 'US'

And the custom card is this:

views:
  cards:
    - type: custom:waze-card
      entities:
        - entity: sensor.waze_home
          zone: zone.home
          name: Home
        - entity: sensor.waze_work
          zone: zone.work
          name: Work`Preformatted text`


tl;dr I just don’t know how to pull 2 locations out of the waze component, since the waze component already contains an origin and destination

How to get the sensor.waze_xxx ?

You can add multiple waze components to your configuration.yaml file: The sensor name will be “sensor.commute_to_home” and “sensor.commute_to_work” based on the example below. Hope this helps.

sensor:
      - platform: waze_travel_time
        name: Commute to Home
        origin: zone.work
        destination: zone.home
        region: 'US'
      - platform: waze_travel_time
        name: Commute to Work
        origin: zone.home
        destination: zone.work
        region: 'US'

ah thanks! that helps a bit.

What about the “zone” that’s required for each entity in lovelace? It says “The zone to map the route with”. But each entity in the configuration file already has an origin and destination. I don’t understand why anything further in terms of location is needed if we already have a beginning and end-point? What should I put there?

Quick question. I think I know the answer, but should this open waze on an iPhone? It does go to waze on a PC running chrome, when I click on the directions, but not on iPhone.

I’m also a little confused about the zone requirement. My waze sensors have a starting and ending zone already. Actually for me I use a device tracker for the starting zone. I’ve changed the zone a bit, and it does not change the time, route or distance, but it does change where waze map opens up to when I click on the directions link in a browser.

It does for me. Clicking it brings up Waze, works out the route and is ready to go, and if I do nothing it starts navigating.

I have slightly strange request.

I live in the UK and here we are still a little conflicted about units of measurement. Yes we are metric in most things so my config specifies that but for distances or in fact anything to do with our roads we are still stubbornly very much Imperial.

Is it possible to include an option in your card to specify unit of measurement as I’d like the distances in miles?


Secondly, I also wonder what the zone parameter is actually for?

EDIT: Ah! Is it used for when you click a route and go to the Waze app?
This is a great card - thanks.

@ljmerza

I have a couple of suggestions (as well as my one about a units option)

  • Can it optionally use the icon defined in the zone instead of name?
  • Can it not display routes of close to zero* minutes i.e. we are already at the zone?

I say ‘close to zero’ because currently I show as 0.01km from home, which is where I am.

1 Like

Hmm, on Chrome on a PC it opens waze, on my Iphone 8s (current os), it does nothing, well it seems to acknowlede that I clicked, but nothing opens. I even changed the card to just a single route to be sure. Here is my lovelace
I did put the js in a different folder, but have the correct path

  - type: js
    url: /local/custom_lovelace/waze-card/waze-card.js?v=1.1.1

Then the Card

    cards:
      - entities:
          - entity: sensor.time_to_work
            name: work
            zone: zone.work
        title: Current Commute Time
        type: 'custom:waze-card'

Here is my waze sensor

  - platform: waze_travel_time
    name: Time to work
    origin: device_tracker.paul_all
    destination: zone.work
    region: 'US'

Just adding a bit more info. If I open HA in Chrome on my Iphone, it also opens waze. It’s just the HA Iphone App that does not seem to be working.

In the HA iOS app, in settings and General Settings, do you have Open links in a chrome turned on? I just turned it on and the Waze card stop responding. Turning it off and the card started working again opening up the Waze app.

1 Like

That did it! Thanks!

Glad it’s working. I don’t use Chrome much, so I have turned that option off long ago and forgot about it, and for some reason it popped in my head so I thought I’d try and see.

Sometimes it’s the simplest little thing that has you going insane pulling your hair out.

I just noticed that all of my distances are in km, vs miles. The waze sensor shows km too, but I never noticed until I started using this card.

Looking at the java script

    /**
     * computes the distance for a route for metric/imperial system
     * @param  {Object} state the card state
     * @return {string} the formatted distance 
     */
    computeDistance(state){
      let distance = state.attributes && state.attributes.distance || 0;
      if(this._hass.config.unit_system.length !== 'mi') distance = distance * 1.60934;

      distance = parseFloat(Math.round(distance * 100) / 100).toFixed(2);
      distance = `${distance}${this._hass.config.unit_system.length}`;
      return distance;
    } 

It looks like it should have converted to miles, right? I’m no programmer, but the logic seems sound. Am I missing something in my config. I’m set up for imperial

Are you in the US? My best guess is Waze doesn’t always come back in miles depending on where the starting point is. I’ll have to look into this

I am in the US, and I agree, my waze sensor is showing km. It was not until I put this into the waze card where I really noticed. I was going to look at the .js and see if I could just do some math on the distance, but then it looked like it was already going to do that for me, but did not for some reason.

I see some confusion on the zone config option. This is to enable click to open waze functionality as the waze sensor doesn’t give me the coordinates needed to generate the URL to open waze automatically. I updated the card to make zone option optional and updated the read me to make the config clearer.

I also tried updating some distance stuff. I think the waze sensor isn’t giving a consistent measurement unit but I can’t tell what makes the waze sensor change units. I’ve reached out to the developer to see if he knows.

Since the latest version, I get an error:

/local/waze-card/waze-card.js?v=1.2.0:32:40 Uncaught TypeError: Cannot read property 'attributes' of undefined

My settings:

  - url: /local/waze-card/waze-card.js?v=1.2.0
    type: js

lovelace

  - type: vertical-stack
    cards:
      - type: custom:card-modder
        card:
          type: custom:waze-card
          entities:
            - entity: sensor.avi_to_home
              zone: zone.home
              name: Avi
            - entity: sensor.nurit_to_home
              zone: zone.home
              name: Nurit
            - entity: sensor.commute_to_work
              zone: zone.powertec
              name: Work
        style:                 
          background-image: url("/local/lovelace/home/waze_5.png")
          background-repeat: no-repeat
          background-color: rgba(50,50,50,0.3)
          background-size: 100% 300px
          border-radius: 20px
          border: solid 1px rgba(100,100,100,0.3)
          box-shadow: 3px 3px rgba(0,0,0,0.4)

That means the waze card is not finding one of the zones you set in the config. I’ll have to update these error messages so it can be easier to debug. Make sure you have the correct zone name and they are working in the states table.

I am having an odd issue. Im not sure if its related to the card or the component itself, but of the 5 routes I have set up, only one or two will show information at a time. Sometimes one works, and another doesnt, and then it just magically switches to where a different one works and the one that was previously working has stopped. Any ideas?