Page 1 of 1

Change dummy switch based on waze

Posted: Wednesday 03 May 2017 20:40
by Lebo2d9
Hi,

I want to implement a switch that i want to turn on when my drive time in Waze to home is 30 minutes or less.
Does someone know if this is possible?

I know there is already a lot concerning waze on this forum but I didn't start reading it yet ;)


Kind regards

Re: Change dummy switch based on waze

Posted: Friday 05 May 2017 10:04
by Lebo2d9
Hi,

this what i have for the moment.

A script that does the calculation for the drive time. But with fixed value's.

Now i want to extract koenx, koeny, luciex and luciey from mosquito_sub but I don't know how to do this.

Cam someone help me ?

Code: Select all

#!/bin/bash

## user variables
DOMOTICZ_SERVER="127.0.0.1:8080"
IDXK="356"      ## IDX dummy Drive time Koen
IDXL="357"      ## IDX dummy Driver time Lucie
homex="4.XXXX"     ## Home
homey="50.XXX"
koenx=""    ## Koen  MQTT lat
koeny=""    ## Koen MQTT lon
luciex=""  ## Lucie
lucieY=""
tmpfileK="/tmp/wazeKoen.txt"
tmpfileL="/tmp/wazeLucie.txt"
log="/tmp/wazelog.txt"
rm -rf $log
rm -rf $tmpfileK
rm -rf $tmpfileL
#echo "Start." > $log


##MQTT location koen


## CURL route Koen 
urlK='https://www.waze.com/row-RoutingManager/routingRequest?from=x%3A'$koenx'+y%3A'$koeny'&to=x%3A'$homex'+y%3A'$homey'&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS%3At%2CALLOW_UTURNS'
/usr/bin/curl -s -o $tmpfileK $urlK
#echo "urlK : "$urlK >> $log

## Sleep to avoid 503 errors
sleep 5

## CURL route Lucie
urlL='https://www.waze.com/row-RoutingManager/routingRequest?from=x%3A'$luciex'+y%3A'$luciey'&to=x%3A'$homex'+y%3A'$homey'&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS%3At%2CALLOW_UTURNS'
/usr/bin/curl -s -o $tmpfileL $urlL
#echo "urlL : "$urlL >> $log

## calc Koen
tempstrajetminsK=$(/usr/bin/jq -r .response.results[].crossTime $tmpfileK | /usr/bin/awk '{s+=$1} END {print s}' | /usr/bin/awk '{sum = $1 / 60 ; print sum }' | /usr/bin/cut -f1 -d\. )
#echo "Drive time Koen : "$tempstrajetminsK >> $log

## calc Lucie
tempstrajetminsL=$(/usr/bin/jq -r .response.results[].crossTime $tmpfileL | /usr/bin/awk '{s+=$1} END {print s}' | /usr/bin/awk '{sum = $1 / 60 ; print sum }' | /usr/bin/cut -f1 -d\. )
#echo "Drive time Lucie: "$tempstrajetminsL >> $log

## Results
echo "Drive time Koen  : $tempstrajetminsK min"
echo "Drive Time Lucie : $tempstrajetminsL min"

## updating dummy sensors
updateK='http://'$DOMOTICZ_SERVER'/json.htm?type=command&param=udevice&idx='$IDXK'&nvalue=0&svalue='$tempstrajetminsK
updateL='http://'$DOMOTICZ_SERVER'/json.htm?type=command&param=udevice&idx='$IDXL'&nvalue=0&svalue='$tempstrajetminsL

#echo "URL Update K : "$updateK >> $log
#echo "URL Update L : "$updateL >> $log

/usr/bin/curl -s $updateK &
/usr/bin/curl -s $updateL

exit 0