From db928e6735c6f2ac1074253081dba9c74850729a Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 14 May 2023 17:04:41 -0500 Subject: [PATCH] Update powerwall.sh --- powerwall.sh | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/powerwall.sh b/powerwall.sh index 52822a11..ab2c4d50 100755 --- a/powerwall.sh +++ b/powerwall.sh @@ -16,31 +16,33 @@ VERBOSE=false #ssh root@10.5.10.35 '/vmfs/volumes/NFS_ESXi-Vault/esxi-shutdown.sh > /dev/null 2>&1' & > /dev/null 2>&1 CHECKTEMP(){ - [ "${1}" != "" ] && SENSORS=("${1}") || SENSORS=SENSOR_ID[@] - for x in "${!SENSOR_ID[@]}"; do printf "[%s]=%s\n" "$x" "${SENSOR_ID[$x]}" ; done - for x in "${!SENSORS[@]}"; do printf "[%s]=%s\n" "$x" "${SENSORS[$x]}" ; done + if [ "${1}" != "" ]; then + CHECKTEMPSENSOR ${1} + else + for SENSOR in ${!SENSOR_ID[@]}; do + echo "HERE: ${SENSOR}-${SENSORS[${SENSOR}]}" + done + fi - for SENSOR in ${!SENSORS}; do - echo "HERE: ${SENSOR}-${SENSORS[${SENSOR}]}" - done - - # mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` - # echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c - # if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then - # temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc` - # #echo "$temp_c -> $temp_f" - # - # echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn - # echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit - # - # if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then - # echo "WARNING: $temp_f°F" - # elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then - # echo "CRITICAL: $temp_f°F" - # else - # echo "normal: $temp_f°F" - # fi - # fi +} +CHECKTEMPSENSOR()}{ + mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` + echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c + if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then + temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc` + #echo "$temp_c -> $temp_f" + + echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn + echo ${TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit + + if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then + echo "WARNING: $temp_f°F" + elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then + echo "CRITICAL: $temp_f°F" + else + echo "normal: $temp_f°F" + fi + fi } CHECKTEMP_SERVICE(){