From 70d6bfe218aadc355ed7bb12a5e19562de07abb9 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Tue, 3 Sep 2019 21:52:26 +0200 Subject: [PATCH] added shell script to track shelly version --- shell_scripts/shelly_upgrade.sh | 6 +++--- shell_scripts/shelly_version.sh | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 shell_scripts/shelly_version.sh diff --git a/shell_scripts/shelly_upgrade.sh b/shell_scripts/shelly_upgrade.sh index 7e879a7e..644afa9b 100755 --- a/shell_scripts/shelly_upgrade.sh +++ b/shell_scripts/shelly_upgrade.sh @@ -15,15 +15,15 @@ SHELLY_ID=( shelly1-59E18C shelly1-24D1A8 shellybulb-BC8610 - shellyem-B9E1A0 - shellyplug-s-7A31CB + shellyem-B9E1A0 + shellyplug-s-7A31CB ) echo "Upgrade Shelly Firmware" for i in "${SHELLY_ID[@]}" do - echo mosquitto_pub -h $HOST -d -u $USER -P $PASSWORD -t shellies/$i/command -m update_fw + mosquitto_pub -h $HOST -d -u $USER -P $PASSWORD -t shellies/$i/command -m update_fw done echo "Done" diff --git a/shell_scripts/shelly_version.sh b/shell_scripts/shelly_version.sh new file mode 100755 index 00000000..0eaa0b7c --- /dev/null +++ b/shell_scripts/shelly_version.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +HASS_HOME="/var/lib/homeassistant/.homeassistant" +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 + 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 + 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 + fi +done + +echo "Done" -- 2.47.3