Configuration file for dwm-bar on macbook air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

  1. #!/bin/bash
  2. # This module can get data from a SMA Inverter.
  3. # Its purpose is to show you how much Watts are being produced
  4. # To make it work change the INVERTER_IP variable and your User password
  5. # Vincenzo Petrolo <vincenzo.petrolo99@gmail.com>
  6. # For infos on how i made it, and help or bugs, you cant contact me or
  7. # open an issue
  8. # GNU GPLv3
  9. # P.s: Be careful when trying to modify urls, as they contains special
  10. # characters that may change the behaviour of the query
  11. dwm_solar_panel () {
  12. INVERTER_IP="INVERTER IP HERE"
  13. PASSWORD="USER GROUP PASSWORD HERE"
  14. if [[ -f ~/.cache/solar_panel.cache ]];
  15. then
  16. read SID < ~/.cache/solar_panel.cache
  17. if [ "$SID" == "null" ];
  18. then
  19. #Getting session id
  20. SID=`curl -s --location --request POST "http://$INVERTER_IP/dyn/login.json" \
  21. --header 'Content-Type: text/plain' \
  22. --data-raw "{"right":"usr","pass":"$PASSWORD"}" | jq .result.sid`
  23. SID=${SID//\"}
  24. fi
  25. #checks if it got a session token
  26. if [ "$SID" != "" ];
  27. then
  28. echo $SID > ~/.cache/solar_panel.cache
  29. WATTS=$(curl -s --location --request POST "http://$INVERTER_IP/dyn/getValues.json?sid=$SID" \
  30. --header 'Content-Type: text/plain' \
  31. --data-raw '{"destDev":[],"keys":["6100_00543100","6800_008AA200","6100_40263F00","6800_00832A00","6180_08214800","6180_08414900","6180_08522F00","6400_00543A00","6400_00260100","6800_08811F00","6400_00462E00"]}' | jq '.result."0156-76BC3EC6"."6100_40263F00"."1"[0].val')
  32. if [ "$WATTS" == "" ];
  33. then
  34. echo "null" > ~/.cache/solar_panel.cache
  35. else
  36. if [ "$WATTS" == "null" ];
  37. then
  38. $WATTS=0
  39. fi
  40. WATTC=`bc <<< "scale=3; $WATTS / 1000"`
  41. printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2"
  42. fi
  43. fi
  44. else
  45. touch ~/.cache/solar_panel.cache
  46. echo "null" > ~/.cache/solar_panel.cache
  47. fi
  48. }
  49. dwm_solar_panel