Traffic with waze in Domoticz

Moderator: leecollings

krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Traffic with waze in Domoticz

Post 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?
User avatar
lemassykoi
Posts: 15
Joined: Saturday 11 March 2017 23:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: France
Contact:

Re: Traffic with waze in Domoticz

Post 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
Abbadon
Posts: 40
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Traffic with waze in Domoticz

Post by Abbadon »

here is mine, btw your code is nice piece of work
Attachments
chart.png
chart.png (67.05 KiB) Viewed 4202 times
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

Re: Traffic with waze in Domoticz

Post 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....
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Traffic with waze in Domoticz

Post 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 :)
Abbadon
Posts: 40
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Traffic with waze in Domoticz

Post by Abbadon »

anyone know how to get device coordinates? i want to modify that script to get ETA device > home
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Traffic with waze in Domoticz

Post 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
Abbadon
Posts: 40
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Traffic with waze in Domoticz

Post 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
User avatar
lemassykoi
Posts: 15
Joined: Saturday 11 March 2017 23:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: France
Contact:

Re: Traffic with waze in Domoticz

Post 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
Last edited by lemassykoi on Thursday 30 March 2017 7:44, edited 1 time in total.
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Traffic with waze in Domoticz

Post 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
corederoma82
Posts: 85
Joined: Saturday 14 January 2017 21:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Traffic with waze in Domoticz

Post by corederoma82 »

I'm sorry, but I don't understood how configure Waze (in Domoticz running on Windows)

Thanks
Raspberry PI 3, 3x Yeelight bulbs, 1x Yeeligh led strip, 1x Sonoff with ESP826, Controlicz, Kodi
multinet
Posts: 97
Joined: Friday 05 December 2014 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Traffic with waze in Domoticz

Post 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
PI 2 - Domoticz 2021.1
RFXCOM - RFXtrx433 USB 433.92MHz Transceiver (5 DIO 54755 + 2 DIO 54756 + 3 DIO 54798)
Z-Wave.Me ZME_UZB1 USB Stick (6 FGSD002 + 2 FGRM222 + 1 FGS223 + 1 FGMS001-ZW5 + 1 FGRGBWM441 + 1 FGBS001 + 2 FGFS101)
6 sondes DS18B20
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Traffic with waze in Domoticz

Post by Damnet »

Yes same here:
html passed to JSON:decode():
403 Forbidden
nginx
User avatar
bueno79
Posts: 83
Joined: Wednesday 08 March 2017 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: France
Contact:

Re: Traffic with waze in Domoticz

Post by bueno79 »

yes the same :(
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

Re: Traffic with waze in Domoticz

Post 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
Ady92100
Posts: 24
Joined: Thursday 22 January 2015 10:58
Target OS: NAS (Synology & others)
Domoticz version: >V3.6796
Location: Fr
Contact:

Re: Traffic with waze in Domoticz

Post 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
Synology DS212 + RFXTrx433 + AEon Stick S2
Oregon - Thgr122Nx / Chacon - module 1000w - détecteur de fumée 34131 / OWL -CM180 / Greenwave Multiprise
corederoma82
Posts: 85
Joined: Saturday 14 January 2017 21:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Traffic with waze in Domoticz

Post 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?
Attachments
Immagine.png
Immagine.png (30.78 KiB) Viewed 3582 times
Raspberry PI 3, 3x Yeelight bulbs, 1x Yeeligh led strip, 1x Sonoff with ESP826, Controlicz, Kodi
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

Re: Traffic with waze in Domoticz

Post 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
Ady92100
Posts: 24
Joined: Thursday 22 January 2015 10:58
Target OS: NAS (Synology & others)
Domoticz version: >V3.6796
Location: Fr
Contact:

Re: Traffic with waze in Domoticz

Post by Ady92100 »

To @@dervogt

Thanks
It works well.
regards
Synology DS212 + RFXTrx433 + AEon Stick S2
Oregon - Thgr122Nx / Chacon - module 1000w - détecteur de fumée 34131 / OWL -CM180 / Greenwave Multiprise
fechp
Posts: 4
Joined: Tuesday 24 May 2016 13:27
Target OS: -
Domoticz version:
Contact:

Re: Traffic with waze in Domoticz

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest