Page 1 of 1

Travel time plugin

Posted: Monday 17 October 2022 23:06
by zabinskiwojciech
Hello everyone, I had a script that determined the time of travel from home to work and the second one from work to home stopped working from August 6th. You don't know what could have happened. I am running on the last stable release of Domoticz and Ubuntu 20.04LTS. Ubuntu constantly updated. The script was based on Google Map and API.

Re: Travel time plugin

Posted: Tuesday 18 October 2022 7:45
by gizmocuz
Well it could be that you need to reauthenticate yourself via the Google API, but if someone could help you, I'm sure they would like to see your script here

Re: Travel time plugin

Posted: Tuesday 18 October 2022 12:20
by zabinskiwojciech

Code: Select all

#!/bin/bash
KEY=xxxxxxxxxxAPIxxxxxxxx
FROM=Marki+Skorupki+22
TO=Warszawa+Dobosza+1
CZAS=`curl -s "https://maps.googleapis.com/maps/api/directions/json?origin=$FROM&destination=$TO&transit_mode=driving&departure_time=now&key=$KEY" | jq '.routes[0].legs[0].duration_in_traffic.value'`
WYNIK=$(($CZAS/60))
DOMO=192.168.1.223:8084
IDX=158
wget -O - "$DOMO/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=$WYNIK" > /dev/null 2>&1

Re: Travel time plugin

Posted: Tuesday 18 October 2022 13:10
by waltervl
Perhaps related to google not accepting normal user/password anymore? You need to make a specific app login on your google account.
See viewtopic.php?p=290975#p290975

Additional: is the link in a browser with filled in parameters for FROM, TO and KEY giving the expected result?

Code: Select all

"https://maps.googleapis.com/maps/api/directions/json?origin=$FROM&destination=$TO&transit_mode=driving&departure_time=now&key=$KEY"

Re: Travel time plugin

Posted: Tuesday 18 October 2022 22:08
by FireWizard
Hi, @zabinskiwojciech

Is this something, that might be of interest?

viewtopic.php?p=280642&hilit=OSRM#p280642

Regards

Re: Travel time plugin

Posted: Wednesday 19 October 2022 19:13
by zabinskiwojciech
FireWizard wrote: Tuesday 18 October 2022 22:08 Hi, @zabinskiwojciech

Is this something, that might be of interest?

viewtopic.php?p=280642&hilit=OSRM#p280642

Regards
Your idea is very cool but very advanced, I wanted it to tell me the time of commuting to work at a specific time and returning. I have created two buttons that are triggered at given times and the result is shown on other tiles.

Re: Travel time plugin

Posted: Wednesday 19 October 2022 19:39
by zabinskiwojciech
waltervl wrote: Tuesday 18 October 2022 13:10 Perhaps related to google not accepting normal user/password anymore? You need to make a specific app login on your google account.
See viewtopic.php?p=290975#p290975

Additional: is the link in a browser with filled in parameters for FROM, TO and KEY giving the expected result?

Code: Select all

"https://maps.googleapis.com/maps/api/directions/json?origin=$FROM&destination=$TO&transit_mode=driving&departure_time=now&key=$KEY"
after filling in the data, he gets a reply

geocoded_waypoints
0
geocoder_status "ZERO_RESULTS"
1
geocoder_status "OK"
place_id "ChIJJQ6uPq_MHkcRgxEC0lAD2ck"
types
0 "premise"
routes []
status "NOT_FOUND"

Re: Travel time plugin

Posted: Wednesday 19 October 2022 20:32
by waltervl
Based on the result of the link it seems that the Google api changed or that one of the adresses cannot be found. There should be a JSON with a duration_in_traffic.value.

Re: Travel time plugin

Posted: Wednesday 19 October 2022 20:44
by waltervl
What happens if you use an example url from the documentation, only change the API key.

Code: Select all

https://maps.googleapis.com/maps/api/distancematrix/json?origins=Boston%2CMA%7CCharlestown%2CMA&destinations=Lexington%2CMA%7CConcord%2CMA&departure_time=now&key=YOUR_API_KEY
If you get an error you probably will need to update the API Key as Gizmocuz already mentioned.
If you get a good result something in your FROM or TO attributes is wrong.

Check the Google api documentation: https://developers.google.com/maps/docu ... ematrix-sh

Re: Travel time plugin

Posted: Monday 24 October 2022 6:40
by zabinskiwojciech
It seems to me that the API key is ok because on the Google website it shows the query in the statistics and the result after loading the link is as if the data were bad ... I don't know I have to do more.

Re: Travel time plugin

Posted: Monday 24 October 2022 11:12
by waltervl
You have to play a little bit with the URL to see if it still works. It seems that the first address probably in Warszawa cannot be resolved (ZERO_RESULTS), the second address (in Marki) is OK.

What if you make the FROM and TO really simple like only Warszawa and Marki ?

Re: Travel time plugin

Posted: Monday 24 October 2022 13:09
by K0enH
maybe useless to mention but you can also create a developer account with Here365 and use their API's.
I moved to that last year or something ago If I recall correctly they also have a higher limit of number of requests you can make for free...

Re: Travel time plugin

Posted: Thursday 27 October 2022 13:23
by zabinskiwojciech
Notifications from the forum do not work for me, I do not receive an email that someone replied. Today I will come back from work and play with simplifying the address.

Re: Travel time plugin

Posted: Thursday 03 November 2022 9:39
by zabinskiwojciech
https://maps.googleapis.com/maps/api/di ... xxxxxxxxxx

When entering your journey data:

Code: Select all

geocoded_waypoints	
0	
geocoder_status	"ZERO_RESULTS"
1	
geocoder_status	"OK"
place_id	"ChIJQ-_mNa_MHkcRFtTargPWVsA"
types	
0	"route"
routes	[]
status	"NOT_FOUND"

Something's wrong with me, my address would disappear from my house



I don't get any notifications from this forum, I don't know what's going on.

Re: Travel time plugin

Posted: Thursday 03 November 2022 18:04
by zabinskiwojciech
you won't believe Google changed my address in its maps and that's why I couldn't refresh the page after changing to the new address provided by Google script works great thank you for helping everyone

Re: Travel time plugin

Posted: Friday 04 November 2022 0:03
by waltervl
Glad it works now!