Travel time plugin

Python and python framework

Moderator: leecollings

Post Reply
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Travel time plugin

Post 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.
User avatar
gizmocuz
Posts: 2491
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Travel time plugin

Post 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
Quality outlives Quantity!
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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
User avatar
waltervl
Posts: 5761
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Travel time plugin

Post 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"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1868
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Travel time plugin

Post by FireWizard »

Hi, @zabinskiwojciech

Is this something, that might be of interest?

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

Regards
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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.
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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"
User avatar
waltervl
Posts: 5761
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Travel time plugin

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5761
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Travel time plugin

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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.
Attachments
api.jpg
api.jpg (24 KiB) Viewed 785 times
User avatar
waltervl
Posts: 5761
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Travel time plugin

Post 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 ?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
K0enH
Posts: 32
Joined: Monday 20 March 2017 14:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Travel time plugin

Post 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...
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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.
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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.
zabinskiwojciech
Posts: 79
Joined: Thursday 16 May 2019 16:23
Target OS: Linux
Domoticz version: 4.10776
Location: Warszawa
Contact:

Re: Travel time plugin

Post 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
User avatar
waltervl
Posts: 5761
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Travel time plugin

Post by waltervl »

Glad it works now!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest