Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Domoticz server
- SERVER="127.0.0.1:8080"
- USERNAME=
- PASSWORD=
- CRGIDX="0" # Charge percentage.
- STSIDX="0" # Charging status, fex: "Normal Charging"
- DSTIDX="0" # Range with AC off, will be given in km (but value in Domoticz might be different)
- # Get data
- INPUT=`/usr/bin/python /home/domo/pycarwings/test.py $USERNAME $PASSWORD > /tmp/pycarwings`
- BAT_TOTAL=`cat /tmp/pycarwings | grep battery_capacity | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
- BAT_CUR=`cat /tmp/pycarwings | grep battery_remaining_amount | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
- BAT_STS=`cat /tmp/pycarwings | grep battery_charging_status | head -n 1 | cut -f2 -d \' | sed "s/_/%20/g" | tr [:upper:] [:lower:]`
- BAT_RNG_MTR=`cat /tmp/pycarwings | grep cruising_range_ac_off | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
- BAT=`echo "$BAT_CUR * 100 / $BAT_TOTAL" | bc`
- BAT_RNG=`echo "$BAT_RNG_MTR/10000" | bc -l`
- # If BAT contains value then send it to Domoticz
- if [ -z "$BAT" ] ; then
- echo "Error: Battery percentage value variable empty"
- elif [ $CRGIDX != "0" ] ; then
- echo "I will output something"
- curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command¶m=udevice&idx=$CRGIDX&nvalue=$NVALUE&svalue=$BAT"
- else
- echo "CRGIDX is set to 0"
- fi
- # If BAT_STS contains value then send it to Domoticz
- if [ -z "$BAT_STS" ];
- then
- echo "Error: Battery status value variable empty"
- elif [ $STSIDX != "0" ] ; then
- echo "I will output something"
- curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command¶m=udevice&idx=$STSIDX&nvalue=LEVEL&svalue=$BAT_STS"
- else
- echo "STSIDX is set to 0"
- fi
- # If BAT_RNG contains value then send it to Domoticz
- if [ -z "$BAT_RNG" ];
- then
- echo "Error: Battery range value variable empty"
- elif [ $DSTIDX != "0" ] ; then
- curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command¶m=udevice&idx=$DSTIDX&nvalue=0&svalue=$BAT_RNG"
- else
- echo "DSTIDX is set to 0"
- fi
- rm /tmp/pycarwings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement