Advertisement
Guest User

leafcharge.sh

a guest
Jan 7th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.07 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Domoticz server
  4. SERVER="127.0.0.1:8080"
  5. USERNAME=
  6. PASSWORD=
  7. CRGIDX="0"    # Charge percentage.
  8. STSIDX="0"      # Charging status, fex: "Normal Charging"
  9. DSTIDX="0"      # Range with AC off, will be given in km (but value in Domoticz might be different)
  10.  
  11. # Get data
  12. INPUT=`/usr/bin/python /home/domo/pycarwings/test.py $USERNAME $PASSWORD > /tmp/pycarwings`
  13.  
  14. BAT_TOTAL=`cat /tmp/pycarwings | grep battery_capacity | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
  15. BAT_CUR=`cat /tmp/pycarwings | grep battery_remaining_amount | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
  16. BAT_STS=`cat /tmp/pycarwings | grep battery_charging_status | head -n 1 | cut -f2 -d \' | sed "s/_/%20/g" | tr [:upper:] [:lower:]`
  17. BAT_RNG_MTR=`cat /tmp/pycarwings | grep cruising_range_ac_off | head -n 1 | cut -f1 -d , | sed s/[^0-9]//g`
  18. BAT=`echo "$BAT_CUR * 100 / $BAT_TOTAL" | bc`
  19. BAT_RNG=`echo "$BAT_RNG_MTR/10000" | bc -l`
  20.  
  21.  
  22.  
  23. # If BAT contains value then send it to Domoticz
  24. if [ -z "$BAT" ] ; then
  25.         echo "Error: Battery percentage value variable empty"
  26. elif [ $CRGIDX != "0" ] ; then
  27.         echo "I will output something"
  28.         curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$CRGIDX&nvalue=$NVALUE&svalue=$BAT"
  29. else
  30.         echo "CRGIDX is set to 0"
  31. fi
  32.  
  33. # If BAT_STS contains value then send it to Domoticz
  34. if [ -z "$BAT_STS" ];
  35. then
  36.         echo "Error: Battery status value variable empty"
  37. elif [ $STSIDX != "0" ] ; then
  38.         echo "I will output something"
  39.         curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$STSIDX&nvalue=LEVEL&svalue=$BAT_STS"
  40. else
  41.         echo "STSIDX is set to 0"
  42. fi
  43.  
  44. # If BAT_RNG contains value then send it to Domoticz
  45. if [ -z "$BAT_RNG" ];
  46. then
  47.         echo "Error: Battery range value variable empty"
  48. elif [ $DSTIDX != "0" ] ; then
  49.         curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DSTIDX&nvalue=0&svalue=$BAT_RNG"
  50. else
  51.         echo "DSTIDX is set to 0"
  52. fi
  53.  
  54. rm /tmp/pycarwings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement