Page 5 of 6

Traffic with waze in Domoticz

Posted: Wednesday 22 March 2017 7:49
by krizzz
lemassykoi wrote:
krizzz wrote:
lemassykoi wrote:do any of you have a minus sign in one of his coordinates ?
No.

How did you check what were the results over a certain period?


Verzonden vanaf mijn iPhone met Tapatalk
like this : click on "log" on the dummy sensor

Image
Stupid, yes ofcourse. I was thinking a check through the commandline :)

See the picture below, only in the Work to home device I have the drop to 0 minutes

Image

I am actually not running the script 24/7 through crontab because I was scared for the amount of request being send to waze.com and that maybe my ip gets blacklisted for this reason. But I see you do not have any problems. Hoe Manu minutes as an interval do you have?

Re: Traffic with waze in Domoticz

Posted: Wednesday 22 March 2017 7:54
by lemassykoi
krizzz wrote:
Stupid, yes ofcourse. I was thinking a check through the commandline :)

I am actually not running the script 24/7 through crontab because I was scared for the amount of request being send to waze.com and that maybe my ip gets blacklisted for this reason. But I see you do not have any problems. Hoe Manu minutes as an interval do you have?
every 5 minutes, by crontab

maybe you want to try with Google Maps : viewtopic.php?f=61&t=11450

here is my work to home :

Image

Re: Traffic with waze in Domoticz

Posted: Wednesday 22 March 2017 16:18
by Abbadon
here is mine, btw your code is nice piece of work

Re: Traffic with waze in Domoticz

Posted: Wednesday 22 March 2017 16:38
by dervogt
no worries about being BL'ed by Waze: I am running these sensors since last year June every minute for three different location pairs, next to regular 503 errors in the log there is nothing happening in regards to blacklisting on the Waze side....

Re: Traffic with waze in Domoticz

Posted: Wednesday 22 March 2017 18:48
by krizzz
dervogt wrote:no worries about being BL'ed by Waze: I am running these sensors since last year June every minute for three different location pairs, next to regular 503 errors in the log there is nothing happening in regards to blacklisting on the Waze side....

Haha good to know! So I can Also worry about my 100 errors :)

Re: Traffic with waze in Domoticz

Posted: Sunday 26 March 2017 12:03
by Abbadon
anyone know how to get device coordinates? i want to modify that script to get ETA device > home

Re: Traffic with waze in Domoticz

Posted: Sunday 26 March 2017 13:30
by krizzz
Abbadon wrote:anyone know how to get device coordinates? i want to modify that script to get ETA device > home
Just checkout waze.com typ in the adres you are looking for than click on the "permalink" I think it is called and in the url there are the coordinates. Did you mean this?


Verzonden vanaf mijn iPhone met Tapatalk

Re: Traffic with waze in Domoticz

Posted: Monday 27 March 2017 20:38
by Abbadon
krizzz wrote:
Abbadon wrote:anyone know how to get device coordinates? i want to modify that script to get ETA device > home
Just checkout waze.com typ in the adres you are looking for than click on the "permalink" I think it is called and in the url there are the coordinates. Did you mean this?


Verzonden vanaf mijn iPhone met Tapatalk
No, i mean that i want to have updated cordinates for my device automatically

Re: Traffic with waze in Domoticz

Posted: Thursday 30 March 2017 3:01
by lemassykoi
Abbadon wrote:
krizzz wrote:
Abbadon wrote:anyone know how to get device coordinates? i want to modify that script to get ETA device > home
Just checkout waze.com typ in the adres you are looking for than click on the "permalink" I think it is called and in the url there are the coordinates. Did you mean this?
No, i mean that i want to have updated cordinates for my device automatically
look at Owntracks, it works well. It uploads your position to MQTT server (like Mosquitto), then you can transfer data to Domoticz. I wrote a script which translate GPS coords into City Name.
I must use NodeRed to act as a gateway, because I don't want to expose my MQTT server to outside.
So, schema is like this : phone --> CloudMQTT and on my Pi, I have : CloudMQTT --> NodeRed --> Domoticz (2 dummy : 1 for City Name, 1 for Battery level, for fun)

For those who where having problems for Work to Home, I found a solution, I hope :

I had the same problem for a friend of mine, and when I look to the logs, I see :

Code: Select all

503 Service Temporarily Unavailable
so I add :

Code: Select all

sleep 5
between

Code: Select all

curl $urlA
and

Code: Select all

curl $urlR
, and it's ok for the moment.

I edited my post with full script, previous page

Re: Traffic with waze in Domoticz

Posted: Thursday 30 March 2017 7:21
by krizzz
lemassykoi wrote:
Abbadon wrote:
krizzz wrote:
Just checkout waze.com typ in the adres you are looking for than click on the "permalink" I think it is called and in the url there are the coordinates. Did you mean this?
No, i mean that i want to have updated cordinates for my device automatically
look at Owntracks, it works well. It uploads your position to MQTT server (like Mosquitto), then you can transfer data to Domoticz. I wrote a script which translate GPS coords into City Name.
I must use NodeRed to act as a gateway, because I don't want to expose my MQTT server to outside.
So, schema is like this : phone --> CloudMQTT and on my Pi, I have : MQTT --> NodeRed --> Domoticz (2 dummy : 1 for City Name, 1 for Battery level, for fun)

For those who where having problems for Work to Home, I found a solution, I hope :

I had the same problem for a friend of mine, and when I look to the logs, I see :

Code: Select all

503 Service Temporarily Unavailable
so I add :

Code: Select all

sleep 5
between

Code: Select all

curl $urlA
and

Code: Select all

curl $urlR
, and it's ok for the moment.

I edited my post with full script, previous page
Will try! Thanks


Verzonden vanaf mijn iPhone met Tapatalk

Re: Traffic with waze in Domoticz

Posted: Monday 08 May 2017 14:37
by corederoma82
I'm sorry, but I don't understood how configure Waze (in Domoticz running on Windows)

Thanks

Re: Traffic with waze in Domoticz

Posted: Tuesday 04 July 2017 18:27
by multinet
Hello

it seems that waze routingmanger return a 403 forbidden

Do you have the same pb ?

Code: Select all

root@domoticz:/home/pi# curl "https://www.waze.com/row-RoutingManager/routingRequest?from=x:***HERE_MY_X_FROM***+y:***HERE_MY_Y_FROM***&to=x:***HERE_MY_X_TO***+y:***HERE_MY_Y_TO***&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS%3At%2CALLOW_UTURNS"
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

Multinet

Re: Traffic with waze in Domoticz

Posted: Tuesday 04 July 2017 20:10
by Damnet
Yes same here:
html passed to JSON:decode():
403 Forbidden
nginx

Re: Traffic with waze in Domoticz

Posted: Wednesday 05 July 2017 8:01
by bueno79
yes the same :(

Re: Traffic with waze in Domoticz

Posted: Friday 07 July 2017 14:31
by dervogt
the same here, I migrated over to the Google Maps API for calculating my travel times, looks a lot more stable as well, Waze was frequently giving me 503 errors when querying the API

Re: Traffic with waze in Domoticz

Posted: Sunday 09 July 2017 20:49
by Ady92100
@dervogt

hello
For the same reasons as you, I want to migrate to Google api.
I'm able to send the query, to get the answer.
But I'm completey lost with Json.

Can you show us how you get the info from JSon ?

Thanks for your help .
regards

Re: Traffic with waze in Domoticz

Posted: Monday 10 July 2017 0:23
by corederoma82
Why the script is not functioning?

-- script_time_Waze.lua
print('<b style="color:Blue"> >> Monitoring Traveltimes</b>')

------------- Begin time functions -------------
function timedifference_lastupdate_homework (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference_lastupdate_homework = os.difftime (t1, t2)
return difference_lastupdate_homework
end

function timedifference_lastupdate_workhome (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference_lastupdate_workhome = os.difftime (t1, t2)
return difference_lastupdate_workhome
end
------------- End time functions -------------


------------- Begin local variables -------------
-- User variables --
----------------------
-- IP Address and port
IP = '192.168.1.8'
port = '8080'

--idx of devices for capturing the travel time (in minutes) in both direction
idxhomework = '7' -- Home to Work
idxworkhome = '8' -- Work to Home
HomeToWork = 'Home to Work' -- Replace by the name of your dummy sensor
WorkToHome = 'Work to Home' -- Replace by the name of your dummy sensor

--Coordinates Home
-- https://www.waze.com/fr/livemap?zoom=17 ... n=12.52294 -- Ex. : Bagneux, France
departy = '41.96476'
departx = '12.52294'

--Coordinates Work
-- https://www.waze.com/fr/livemap?zoom=17 ... n=12.46096 -- Ex. : La Défense, France
arrivey = '41.9612'
arrivex = '12.46096'

----------------------
-- Debug variables:
----------------------
debug = uservariables["debug_general"]
timeout = uservariables["timeout_general"]
difference_homework = timedifference_lastupdate_homework(otherdevices_lastupdate[HomeToWork])
difference_workhome = timedifference_lastupdate_workhome(otherdevices_lastupdate[WorkToHome])
------------- End local variables -------------


------------- Begin debug statements -------------
if debug=="Y"
then
print('<b style="color:Red"> >> Debug is set to: ' .. debug .. '</b>')
print('<b style="color:Red"> >> Update timeout: ' .. timeout .. '</b>')
print('<b style="color:Red"> >> Lastupdate Home to Work : ' .. difference_homework .. '</b>')
print('<b style="color:Red"> >> Lastupdate Work to Home : ' .. difference_workhome .. '</b>')
end
------------- End debug statements -------------


------------- Begin code -------------
commandArray = {}

if (difference_homework > timeout and difference_workhome > timeout)
then

function traveltime(departx,departy,arrivex,arrivey)
--get route from WAZE--
local waze=assert(io.popen('curl "https://www.waze.com/row-RoutingManager ... LOW_UTURNS"'))
local trajet = waze:read('*all')
waze:close()

if debug=="Y"
then
print("========================================================================================================")
print(trajet)
print("========================================================================================================")
end

local jsonTrajet = json:decode(trajet)

--Get major road from JSON
routeName = jsonTrajet['response']['routeName']
--Get route steps from JSON info
route = jsonTrajet['response']['results']

--Calculate the total time by adding the time of all sections
routeTotalTimeSec = 0
for response,results in pairs(route) do
routeTotalTimeSec = routeTotalTimeSec + results['crossTime']
end

--translate the number of seconds to minutes
routeTotalTimeMin = routeTotalTimeSec/60-((routeTotalTimeSec%60)/60)

return routeTotalTimeMin
end

--import JSON addin (already used with DTGBOT and stored in the standard library)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- check presence of this script if problem

-- get travel time
homework=traveltime(departx,departy,arrivex,arrivey)
workhome=traveltime(arrivex,arrivey,departx,departy)

if debug=="Y"
then
print('Home to Work : ' .. homework .. ' minutes')
print('Work to Home : ' .. workhome .. ' minutes')
end

-- update Domoticz devices
url='http://' .. IP .. ':' .. port .. '/json.htm?type=command&param=udevice&idx=' .. idxhomework .. '&nvalue=0&svalue=' .. homework
read = os.execute('curl -s "'..url..'"')
url='http://' .. IP .. ':' .. port .. '/json.htm?type=command&param=udevice&idx=' .. idxworkhome .. '&nvalue=0&svalue=' .. workhome
read = os.execute('curl -s "'..url..'"')
print('<b style="color:Green"> >> Update OK !</b>')

else
if debug=="Y"
then
print('<b style="color:Red">>> HomeWork lastupdate: ' .. difference_homework .. ' seconds ago. Must be > to '.. timeout ..'</b>')
print('<b style="color:Red">>> WorkHome lastupdate: ' .. difference_workhome .. ' seconds ago. Must be > to '.. timeout ..'</b>')
end

end

------------- End code -------------

return commandArray



Which is the procedure to associate the script to the virtual sensor?

Re: Traffic with waze in Domoticz

Posted: Monday 10 July 2017 15:14
by dervogt
Ady92100 wrote:@dervogt

hello
For the same reasons as you, I want to migrate to Google api.
I'm able to send the query, to get the answer.
But I'm completey lost with Json.

Can you show us how you get the info from JSon ?

Thanks for your help .
regards
I have been using the LUA scripts from this forum thread:
http://domoticz.com/forum/viewtopic.php ... fic+google
Currently, this is my code in Domoticz, I am running each one script per travel direction to then write the value into the already existing custom sensor:

Code: Select all

---------------------------------
-- Script to calculate duration and distance between two points using Google Maps
-- Autor : woody4165 based on Neutrino Traffic with Waze
-- Date : 9 April 2016
-- Need a text device (using duration) or an integer (using mins)
---------------------------------
commandArray={}

time = os.date("*t")
day = tonumber(os.date("%w"))

idx = '108'
-- If a weekday and time between 7AM and 9AM
--if ((day > 0 and day < 6) and (time.hour > 6 and time.hour < 10)) then

-- Every 10 minutes
if((time.min % 10)==0) then

--import JSON.lua library
json = (loadfile "/domoticz/scripts/lua/JSON.lua")()

-- variables --
            fromy="4.96726"
            fromx="52.32254"
            -- Coordinates destination point
            toy="4.44470"
            tox="50.855455"
            -- Google Api Key
            key     = 'AIzaSyAHKVNGHfwoe682IXQtCSVRyxyWYjh0lDQ'

-- get data from Google Maps and decode it in gmaps
local jsondata = assert(io.popen('curl "https://maps.googleapis.com/maps/api/directions/json?origin='..fromx..','..fromy..'&destination='..tox..','..toy..'&departure_time=now&key='..key..'"'))
local jsondevices = jsondata:read('*all')
jsondata:close()
local gmaps = json:decode(jsondevices)

-- Read from the data table, and extract duration and distance in text
local distance = gmaps.routes[1].legs[1].distance.text
local duration = gmaps.routes[1].legs[1].duration_in_traffic.text
local duration_minutes = gmaps.routes[1].legs[1].duration_in_traffic.value/60

-- mins is only the number part of duration (for evaulation purpose or to return a number in a number device)
for minutes in string.gmatch(duration, "%d+") do mins = tonumber(minutes) end

-- send a Telegram message with status update (replace xxxxxxx with chatid and yyyyyyyyy with bot key)
-- In case you don't want to receive Telegram message, just remove or comment next two lines
--message = mins..' mins to go to office at '..time.hour..':'..time.min..' !!!'
--os.execute('curl --data chat_id=xxxxxxxxxx--data-urlencode "text='..message..'" "https://api.telegram.org/botyyyyyyyyyyyyyyyyy/sendMessage" ')


-- return a text to the device (eg. 12 mins)
--commandArray[1]={['UpdateDevice'] =idx..'|0|' .. tostring(duration)}
commandArray[1] = {['OpenURL'] = 'http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=' .. idx .. '&nvalue=0&svalue=' .. tostring(duration_minutes)}
end

return commandArray

Re: Traffic with waze in Domoticz

Posted: Thursday 13 July 2017 14:41
by Ady92100
To @@dervogt

Thanks
It works well.
regards

Re: Traffic with waze in Domoticz

Posted: Sunday 16 July 2017 14:27
by fechp
Hi all,

first of all I wanna thank all of you for getting this programmed (not a big LUA talent), but I got it working :)

But now I face another issue (like above), 403 Forbidden response from the waze url. Probably they do not want me to ask every 10 minutes an update?

Any body else having this issue and got is solved?

Thanks!
Kristof