Change dummy switch based on waze

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Lebo2d9
Posts: 139
Joined: Tuesday 06 September 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: L stab
Location: Belgium
Contact:

Change dummy switch based on waze

Post 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
Domoicz on RPI3 (wifi) directly connected 3x ds18b20 for CV temp, Evohome (9 zone), 1 remote 220V switch based on ESP-12. RFXtrx433E, 16x AMST-606, 5 Somfy RTS motors
Domoticz on RPI3(wifi) as slave for terraruim control
More to come
Lebo2d9
Posts: 139
Joined: Tuesday 06 September 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: L stab
Location: Belgium
Contact:

Re: Change dummy switch based on waze

Post 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
Domoicz on RPI3 (wifi) directly connected 3x ds18b20 for CV temp, Evohome (9 zone), 1 remote 220V switch based on ESP-12. RFXtrx433E, 16x AMST-606, 5 Somfy RTS motors
Domoticz on RPI3(wifi) as slave for terraruim control
More to come
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest