Waze Travel time - Waze in time Add-on?

Hello,

I’m new here, having looking at different automation softawre the last month and decided to give openhab a try.
It seems everything i need exists or is possible, but i could not find any Waze add-on.

The purpose of this is to have a tile on the dashboard that shows the travetime to work ie.
It uses Waze API, and based on 2 locations (coordinates) is calcutes the travel time.
Hoe assistant and Jeedom have this pugin, it seems very handy…

Is anyone working on this?


screenshot form Jeedom

I know of no one working on this but integration would be very simple. Looking at the Home Assistant code it looks like it depends on WaxeRouteCalculator.

So with a script along the lines of:

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
region = 'EU'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
route.calc_route_info()

NOTE: this is the example from the WazeRouteCalculator github, not my own.

and an Exec Thing along the lines of:

Thing exec:command:b2gcommutetime [command="/full/path/to/b2gcommutetime.py", interval=900, timeout=5, transform="REGEX(.*Time (.*) minutes.*)"]

and an Item along the lines of:

String B2GCommuteTimeMins { channel="exec:command:b2gcommutetime:output" }

you should have about all you need.

You could do it also using the executeCommandLine Action in a Rule but I don’t think that is necessary in this case.

Changing the Thing and the Python script so you can pass in the start and end destination is an exercise left to the student, but it is not challenging.

Someone with some time and ambition could probably look at the Python library code and implement something using just the HTTP binding or create a native binding. It doesn’t look hard.

Rich,

Thank you for your fast reply and detailled information.
Unfortunatly, i just installed Openhab and trying to understand how it works. I’m not a programmer so your post i already a little to complicated for me (at the moment at least).
I think it could be a nice addition to the already large add-on library of Openhab if someone could make a plugin for this.

I hope some experienced people will read this post and try to figure out.
Maybe i will be able to help in the coming weeks/months…

After you get a bit of experience with OH under your belt, come back here and have a new look. It is actually really easy to get working with the above once you know the difference between a Thing and an Item in OH and all the important little details like that.

Ok i’ll come back in a few week an give it a try, thanks for the help.

This script peeked my interest so I wanted to see if I could tie it into my dashboard.

I’m running OH on a Windows Platform and when I save my THINGS file I receive the following errors in the OH log.

018-10-11 15:48:19.584 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while executing 'C://PROGRA~1//Python37//Lib//site-packages//WazeRouteCalculator//BYPRoute.py' : 'Cannot run program "C://PROGRA~1//Python37//Lib//site-packages//WazeRouteCalculator//BYPRoute.py": CreateProcess error=193, %1 is not a valid Win32 application'

I can execute the script if I go to the directory, it will run and report back the correct time and distance of the route.

In trying to debug the issue, I ran across a post on Stack Overflow which seems to offer the answer for the problem…

The file you are attempting to load is not an executable file. CreateProcess requires you to provide an executable file. If you wish to be able to open any file with its associated application then you need ShellExecute rather than CreateProcess .

So the question is…how to I do a ShellExecute in the Exec Thing or do I need to do it another way???

Thanks,

Squid

Don’t you need to use \\ instead of //? Or did you do so already and the binding is converting them for some reason?

I’ve tried it both ways with no luck.

Oh, I bet I know what is wrong. Windows doesn’t understand #! in scripts. You have to actually run Python and pass your BYRoute.py script to Python.

c:\<full path to>\python.exe C:\Progra~1\Python37\Lib\site-packages\WaxeRouteCalculator\BYPRoute.py

@rlkoshak

That did the trick…

I’m trying to format the number to only the digits before the decimal point on my sitemap and HabPanel but am not having any luck…

image

I’ve used the typical [%.2f] in the label with no luck - is this because of the REGEX transform?

Thanks,

Squid

It’s because it is a String Item. %.2f will only work with Numbers.

Aha! - So what might be the best way to format the digits?

Either modify the REGEX to not include the decimal point and parts or use a Number Item.

Duh…should have thought it through a bit more!

So I changed the items type to NUMBER and my items look like this…

Number BYPRoute_Data "Travel Time To BYP [%.0f Minutes]" { channel="exec:command:BYPRoute:output" }
Number HomeRoute_Data "Travel Time Home [%.0f Minutes]" { channel="exec:command:HomeRoute:output" }

If I look at the items in HabPanel they display correctly…

image

Yet I can’t get them to display at all in BasicUI

Am I overlooking something simple??? :thinking:

When I do that the item stays as null. Anything obvious I missed?

Hi very cool can you share the complete code(files)
and what do you have on HO? any addons?

do i need some dev account for waze?

Hi -

I’ll do my best to give you the information to implement this yourself.

You do NOT need a Waze developer account.

To implement this you need the following:

EXEC binding installed

REGEX transformation installed

Python must be installed - I installed the latest version 3.7

You need to install the WAZE script as per the instructions posted on GITHUB

First create your thing(s) I created 2 one for the route to work, the other for the route home:

waze.things

Thing exec:command:BYPRoute [command="C:/PROGRA~1/Python37/python.exe C:/PROGRA~1/Python37/Lib/site-packages/WazeRouteCalculator/BYPRoute.py", interval=300, timeout=5, transform="REGEX(.*Time (.*) minutes.*)"]
Thing exec:command:HomeRoute [command="C:/PROGRA~1/Python37/python.exe C:/PROGRA~1/Python37/Lib/site-packages/WazeRouteCalculator/HomeRoute.py", interval=300, timeout=5, transform="REGEX(.*Time (.*) minutes.*)"]

My OH installation is on Windows so I needed to show a full path to the executable first, depending on your OS you may need to adust.

waze.items

Number BYPRoute_Data "Travel Time To BYP [%.0f Minutes]" { channel="exec:command:BYPRoute:output" }
Number HomeRoute_Data "Travel Time Home [%.0f Minutes]" { channel="exec:command:HomeRoute:output" }

Please note I am still having an issue with the time displaying on my sitemap…it is working fine in HABPabnel.

BYPRoute.py and HomeRoute.py

import WazeRouteCalculator

from_address = 'Your Starting Address Goes Here'
to_address = 'Your Destination Address Goes Here'
region = 'US'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
route.calc_route_info()

And that should do it…

Make sure you have your path’s to the files set correctly.

Good Luck…let me know if I can answer anything else.

Squid

1 Like

Wow thanks just one thing to add
i am also a windows user :slight_smile:
also, need “RegEx Transformation”

and i was able to copy paste the rest :slight_smile:
also, you can see it in paper UI in control tab

@KidSquid - you have Number Items there. Does this work for you? You’re using Windows? I am on RPi and Number Items do not work. String - OK. Numbers - all null.

I’m having an issue with BasicUI, but the data displays in HabPanel. If you look up a couple of posts you’ll see I mentioned this and was wondering why it worked in one and not in the other.

Originally it was a String item, but I wanted more formatting flexibility so Rick suggested that o switch it to a Number item. I’m hoping someone can offer some insight.