]> git.giorgioravera.it Git - homeassistant.git/commitdiff
Improved shelly bash scripts
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 27 Mar 2021 20:54:24 +0000 (21:54 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 27 Mar 2021 20:54:24 +0000 (21:54 +0100)
shell_scripts/shelly_reboot.sh
shell_scripts/shelly_upgrade.sh
shell_scripts/shelly_uptime.sh [new file with mode: 0755]
shell_scripts/shelly_version.sh

index 3a7be61f680c29f538d0c934ddcb696102f27ae3..e920683104c2341992c5916b413ae0c76db40008 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
-HASS_HOME="/config"
+if [ -f /.dockerenv ]; then
+       HASS_HOME="/config"
+else
+       HASS_HOME="../"
+fi
 USER=$(awk '/shelly_user/ { print  $2 }' $HASS_HOME/secrets.yaml)
 PASSWORD=$(awk '/shelly_password/ { print  $2 }' $HASS_HOME/secrets.yaml)
 SHELLY_ID=(
@@ -26,8 +30,8 @@ for i in "${SHELLY_ID[@]}"
 do
        ALIVE=$(ping -c 1 $i |grep ttl)
        if [ ! -z "$ALIVE" ]; then
-               STATUS=$(curl -s --user $USER:$PASSWORD http://$i/reboot | sed -e "s/{"ok"}://g")
-               echo $STATUS
+               STATUS=$(curl -s --user $USER:$PASSWORD http://$i/reboot | jq -r .ok)
+               echo $i: $STATUS
        fi
 done
 
index 3a1c1d6b9d12e10aeb58b9af78fc7be2ba0458e9..1de2f651d289a56f94d51235a15f8175cff77f6a 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
-HASS_HOME="/config"
+if [ -f /.dockerenv ]; then
+       HASS_HOME="/config"
+else
+       HASS_HOME="../"
+fi
 HOST=$(awk '/mqtt_host/ { print  $2 }' $HASS_HOME/secrets.yaml)
 USER=$(awk '/mqtt_user/ { print  $2 }' $HASS_HOME/secrets.yaml)
 PASSWORD=$(awk '/mqtt_password/ { print  $2 }' $HASS_HOME/secrets.yaml)
diff --git a/shell_scripts/shelly_uptime.sh b/shell_scripts/shelly_uptime.sh
new file mode 100755 (executable)
index 0000000..fcf33cd
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+if [ -f /.dockerenv ]; then
+       HASS_HOME="/config"
+else
+       HASS_HOME="../"
+fi
+USER=$(awk '/shelly_user/ { print  $2 }' $HASS_HOME/secrets.yaml)
+PASSWORD=$(awk '/shelly_password/ { print  $2 }' $HASS_HOME/secrets.yaml)
+SHELLY_ID=(
+       shelly1.giorgioravera.it
+       shelly2.giorgioravera.it
+       shelly3.giorgioravera.it
+       shelly4.giorgioravera.it
+       shelly5.giorgioravera.it
+       shelly6.giorgioravera.it
+       shelly7.giorgioravera.it
+       shelly8.giorgioravera.it
+       shelly9.giorgioravera.it
+       shelly10.giorgioravera.it
+       shelly11.giorgioravera.it
+       shellybulb.giorgioravera.it
+       shellyem.giorgioravera.it
+       shellyplugs.giorgioravera.it
+)
+
+echo "Check Shelly Firmware"
+
+for i in "${SHELLY_ID[@]}"
+do
+       ALIVE=$(ping -c 1 $i |grep ttl)
+       if [ ! -z "$ALIVE" ]; then
+               UPTIME=$(curl -s --user $USER:$PASSWORD http://$i/status | jq -r .uptime)
+               echo $i: $UPTIME
+       fi
+done
+
+echo "Done"
index b1d2c2efd875f0432fa93d01f7b0f8a66578221f..0e64d479b40f6533e60d8255665786b7e84e594b 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
-HASS_HOME="/config"
+if [ -f /.dockerenv ]; then
+       HASS_HOME="/config"
+else
+       HASS_HOME="../"
+fi
 USER=$(awk '/shelly_user/ { print  $2 }' $HASS_HOME/secrets.yaml)
 PASSWORD=$(awk '/shelly_password/ { print  $2 }' $HASS_HOME/secrets.yaml)
 SHELLY_ID=(
@@ -26,10 +30,14 @@ for i in "${SHELLY_ID[@]}"
 do
        ALIVE=$(ping -c 1 $i |grep ttl)
        if [ ! -z "$ALIVE" ]; then
-               VERSION=$(curl -s --user $USER:$PASSWORD http://$i/status | sed -e "s/},/}\n/g" |grep \"update\" | sed -e "s/,/\n/g" | sed -e "s/:/:\t/g" | awk '/has_update/ { print $2 }')
-               NEW=$(curl -s --user $USER:$PASSWORD http://$i/status | sed -e "s/},/}\n/g" |grep \"update\" | sed -e "s/,/\n/g" | sed -e "s/:/:\t/g" | awk '/new_version/ { print $2 }')
-               OLD=$(curl -s --user $USER:$PASSWORD http://$i/status | sed -e "s/},/}\n/g" |grep \"update\" | sed -e "s/,/\n/g" | sed -e "s/:/:\t/g" | awk '/old_version/ { print $2 }')
-               echo $i: $VERSION - $OLD - $NEW
+               HAS_UPDATE=$(curl -s --user $USER:$PASSWORD http://$i/status | jq -r .update.has_update)
+               NEW=$(curl -s --user $USER:$PASSWORD http://$i/status | jq -r .update.new_version)
+               OLD=$(curl -s --user $USER:$PASSWORD http://$i/status | jq -r .update.old_version)
+               if [ $HAS_UPDATE == "true" ]; then
+                       echo $i: version: $OLD - new version: $NEW
+               else
+                       echo $i: version: $OLD - new version: N/A
+               fi
        fi
 done