From 67435ad478eb1d9c17272b01d9f0d727d6955d89 Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sat, 29 Aug 2020 17:04:30 +0200 Subject: [PATCH 1/6] Add Solar Panels module --- bar-functions/dwm_solar_panel.sh | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 bar-functions/dwm_solar_panel.sh diff --git a/bar-functions/dwm_solar_panel.sh b/bar-functions/dwm_solar_panel.sh new file mode 100755 index 0000000..ba251b8 --- /dev/null +++ b/bar-functions/dwm_solar_panel.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# This module can get data from a SMA Inverter. +# Its purpose is to show you how much Watts are being produced +# To make it work change the INVERTER_IP variable and your User password +# Vincenzo Petrolo +# For infos on how i made it, and help or bugs, you cant contact me or +# open an issue +# GNU GPLv3 + +# P.s: Be careful when trying to modify urls, as they contains special +# characters that may change the behaviour of the query + +dwm_solar_panel () { + + INVERTER_IP="INVERTER IP HERE" + PASSWORD="USER GROUP PASSWORD HERE" + + + if [[ -f ~/.cache/solar_panel.cache ]]; + then + read SID < ~/.cache/solar_panel.cache + if [ "$SID" == "null" ]; + then + #Getting session id + SID=`curl -s --location --request POST "http://$INVERTER_IP/dyn/login.json" \ + --header 'Content-Type: text/plain' \ + --data-raw "{"right":"usr","pass":"$PASSWORD"}" | jq .result.sid` + SID=${SID//\"} + fi + #checks if it got a session token + if [ "$SID" != "" ]; + then + echo $SID > ~/.cache/solar_panel.cache + WATTS=$(curl -s --location --request POST "http://$INVERTER_IP/dyn/getValues.json?sid=$SID" \ + --header 'Content-Type: text/plain' \ + --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') + + if [ "$WATTS" == "" ]; + then + echo "null" > ~/.cache/solar_panel.cache + else + if [ "$WATTS" == "null" ]; + then + $WATTS=0 + fi + WATTC=`bc <<< "scale=3; $WATTS / 1000"` + printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2" + fi + fi + else + touch ~/.cache/solar_panel.cache + + echo "null" > ~/.cache/solar_panel.cache + fi + +} +dwm_solar_panel + From 522663271ede6f3365b57eeba17fbd5fec49aaaa Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sat, 29 Aug 2020 18:05:29 +0200 Subject: [PATCH 2/6] Update README, added solar panels module description --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a5ae7af..e3b460e 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,11 @@ Displays the average system load ``` [⏱ 0.14 0.17 0.18] ``` +### dwm_solar_panels +Displays how much power is being produced from your solar panels +``` +[💡 3.012 W ] +``` ## Installation 1. Clone and enter the repository: ``` From 551daf35e475354a85722d622fea6a9b7bfd8dec Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sat, 29 Aug 2020 19:06:21 +0200 Subject: [PATCH 3/6] Fix typo --- bar-functions/dwm_solar_panel.sh | 24 +++++++-------- bar-functions/dwm_solar_panels_diff.sh | 41 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 13 deletions(-) create mode 100755 bar-functions/dwm_solar_panels_diff.sh diff --git a/bar-functions/dwm_solar_panel.sh b/bar-functions/dwm_solar_panel.sh index ba251b8..a9b6334 100755 --- a/bar-functions/dwm_solar_panel.sh +++ b/bar-functions/dwm_solar_panel.sh @@ -12,8 +12,8 @@ dwm_solar_panel () { - INVERTER_IP="INVERTER IP HERE" - PASSWORD="USER GROUP PASSWORD HERE" + INVERTER_IP="192.168.1.126" + PASSWORD="ciao1234" if [[ -f ~/.cache/solar_panel.cache ]]; @@ -22,30 +22,28 @@ dwm_solar_panel () { if [ "$SID" == "null" ]; then #Getting session id - SID=`curl -s --location --request POST "http://$INVERTER_IP/dyn/login.json" \ - --header 'Content-Type: text/plain' \ - --data-raw "{"right":"usr","pass":"$PASSWORD"}" | jq .result.sid` - SID=${SID//\"} + SID=$( curl -s --location --request POST "http://$INVERTER_IP/dyn/login.json" \ + --header 'Content-Type: text/plain' \ + --data-raw "{\"right\":\"usr\",\"pass\":\""$PASSWORD\""}" | jq .result.sid) + SID=${SID//\"} fi #checks if it got a session token - if [ "$SID" != "" ]; + + if [ "$SID" != "" ] || [ "$SID" != "null" ]; then echo $SID > ~/.cache/solar_panel.cache WATTS=$(curl -s --location --request POST "http://$INVERTER_IP/dyn/getValues.json?sid=$SID" \ --header 'Content-Type: text/plain' \ - --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') + --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') - if [ "$WATTS" == "" ]; + if [ "$WATTS" == "" ] || [ "$WATTS" == "null" ]; then echo "null" > ~/.cache/solar_panel.cache else - if [ "$WATTS" == "null" ]; - then - $WATTS=0 - fi WATTC=`bc <<< "scale=3; $WATTS / 1000"` printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2" fi + fi else touch ~/.cache/solar_panel.cache diff --git a/bar-functions/dwm_solar_panels_diff.sh b/bar-functions/dwm_solar_panels_diff.sh new file mode 100755 index 0000000..0561c08 --- /dev/null +++ b/bar-functions/dwm_solar_panels_diff.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +dwm_solar_panel () { + + if [[ -f ~/.cache/solar_panel.cache ]]; + then + read SID < ~/.cache/solar_panel.cache + if [ "$SID" == "null" ]; + then + #Getting session id + SID=`curl -s --location --request POST 'http://192.168.1.126/dyn/login.json' \ + --header 'Content-Type: text/plain' \ + --data-raw '{"right":"usr","pass":"ciao1234"}' | jq .result.sid` + SID=${SID//\"} + fi + #checks if it got a session token + if [ "$SID" != "" ] || [ "$SID" != "null" ]; + then + echo $SID > ~/.cache/solar_panel.cache + #get data, don't modify a single line of this url,except for the IP(192.168.1.126) + WATTS=$(curl -s --location --request POST "http://192.168.1.126/dyn/getValues.json?sid=$SID" \ + --header 'Content-Type: text/plain' \ + --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') + + if [ "$WATTS" == "" ] || [ "$WATTS" == "null" ]; + then + echo "null" > ~/.cache/solar_panel.cache + else + WATTC=`bc <<< "scale=3; $WATTS / 1000"` + printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2" + fi + fi + else + touch ~/.cache/solar_panel.cache + + echo "null" > ~/.cache/solar_panel.cache + fi + +} +dwm_solar_panel + From 0212c0f07fa293ff4d135fee43d31d0e7d8211f3 Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sat, 29 Aug 2020 19:08:24 +0200 Subject: [PATCH 4/6] Removed test ip and password --- bar-functions/dwm_solar_panel.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bar-functions/dwm_solar_panel.sh b/bar-functions/dwm_solar_panel.sh index a9b6334..20ae7f6 100755 --- a/bar-functions/dwm_solar_panel.sh +++ b/bar-functions/dwm_solar_panel.sh @@ -12,8 +12,8 @@ dwm_solar_panel () { - INVERTER_IP="192.168.1.126" - PASSWORD="ciao1234" + INVERTER_IP="YOUR INVERTER IP" + PASSWORD="YOUR PASSWORD" if [[ -f ~/.cache/solar_panel.cache ]]; From 3d6b2e5131bd73a3a70b66ba13ea4fab6a2e97fe Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sun, 30 Aug 2020 18:58:02 +0200 Subject: [PATCH 5/6] Fixed unit value conversion --- bar-functions/dwm_solar_panel.sh | 3 +- bar-functions/dwm_solar_panels_diff.sh | 41 -------------------------- 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100755 bar-functions/dwm_solar_panels_diff.sh diff --git a/bar-functions/dwm_solar_panel.sh b/bar-functions/dwm_solar_panel.sh index 20ae7f6..b966fae 100755 --- a/bar-functions/dwm_solar_panel.sh +++ b/bar-functions/dwm_solar_panel.sh @@ -40,8 +40,7 @@ dwm_solar_panel () { then echo "null" > ~/.cache/solar_panel.cache else - WATTC=`bc <<< "scale=3; $WATTS / 1000"` - printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2" + printf "%s💡 $WATTS W %s" "$SEP1" "$SEP2" fi fi diff --git a/bar-functions/dwm_solar_panels_diff.sh b/bar-functions/dwm_solar_panels_diff.sh deleted file mode 100755 index 0561c08..0000000 --- a/bar-functions/dwm_solar_panels_diff.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -dwm_solar_panel () { - - if [[ -f ~/.cache/solar_panel.cache ]]; - then - read SID < ~/.cache/solar_panel.cache - if [ "$SID" == "null" ]; - then - #Getting session id - SID=`curl -s --location --request POST 'http://192.168.1.126/dyn/login.json' \ - --header 'Content-Type: text/plain' \ - --data-raw '{"right":"usr","pass":"ciao1234"}' | jq .result.sid` - SID=${SID//\"} - fi - #checks if it got a session token - if [ "$SID" != "" ] || [ "$SID" != "null" ]; - then - echo $SID > ~/.cache/solar_panel.cache - #get data, don't modify a single line of this url,except for the IP(192.168.1.126) - WATTS=$(curl -s --location --request POST "http://192.168.1.126/dyn/getValues.json?sid=$SID" \ - --header 'Content-Type: text/plain' \ - --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') - - if [ "$WATTS" == "" ] || [ "$WATTS" == "null" ]; - then - echo "null" > ~/.cache/solar_panel.cache - else - WATTC=`bc <<< "scale=3; $WATTS / 1000"` - printf "%s💡 $WATTC W %s" "$SEP1" "$SEP2" - fi - fi - else - touch ~/.cache/solar_panel.cache - - echo "null" > ~/.cache/solar_panel.cache - fi - -} -dwm_solar_panel - From 629479ffcde3619b7772d6fcb06f63bb27cd48e7 Mon Sep 17 00:00:00 2001 From: Vincenzo-Petrolo Date: Sun, 30 Aug 2020 20:16:32 +0200 Subject: [PATCH 6/6] Fixed wrong logic statement --- bar-functions/dwm_solar_panel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bar-functions/dwm_solar_panel.sh b/bar-functions/dwm_solar_panel.sh index b966fae..489159f 100755 --- a/bar-functions/dwm_solar_panel.sh +++ b/bar-functions/dwm_solar_panel.sh @@ -29,7 +29,7 @@ dwm_solar_panel () { fi #checks if it got a session token - if [ "$SID" != "" ] || [ "$SID" != "null" ]; + if [ "$SID" != "" ] && [ "$SID" != "null" ]; then echo $SID > ~/.cache/solar_panel.cache WATTS=$(curl -s --location --request POST "http://$INVERTER_IP/dyn/getValues.json?sid=$SID" \