From a0e59ca00cace16ee05b8d4a948309e597caa816 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 30 Oct 2023 14:00:15 -0500 Subject: [PATCH] Update powerwall.sh --- powerwall.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/powerwall.sh b/powerwall.sh index 8c230714..5885db7b 100755 --- a/powerwall.sh +++ b/powerwall.sh @@ -60,7 +60,7 @@ CHECKTEMP(){ # echo "HERE: ${SENSOR} (${PW_SENSOR_ID[${SENSOR}]}) - ${vSENSOR// /_}" - reading=$(CHECKTEMPSENSOR ${SENSOR} ${temp_c} ${temp_warn} ${temp_crit} ${vSENSOR// /_}) + reading=$(CHECKTEMPSENSOR ${SENSOR} ${temp_c} ${temp_warn} ${temp_crit} ${vSENSOR// /_} ${1}) c=0; spc=''; spc1=`expr ${cw} - ${#vSENSOR} - 1`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -e "${idsCL[LightCyan]} ${vSENSOR}${spc}${idsCL[Default]}: ${reading}" @@ -81,7 +81,7 @@ CHECKTEMP(){ else echo -en "${idsCL[Yellow]}Pulling data and calculating averages for '${SENSOR}' ..." - reading=$(CHECKTEMPSENSOR ${SENSOR}) + reading=$(CHECKTEMPSENSOR ${SENSOR} . . . . ${1}) c=0; spc=''; spc1=`expr ${cw} - ${#SENSOR}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -e "\r\033[K${idsCL[LightCyan]}${idsST[Bold]}${SENSOR}${idsST[Reset]}${spc}${idsCL[Default]}: ${reading}" fi @@ -95,7 +95,7 @@ CHECKTEMP(){ CHECKTEMPSENSOR(){ echo ${PW_TEMP_THRESHOLDS[${1}]} | cut -d',' -f 1 | read temp_warn echo ${PW_TEMP_THRESHOLDS[${1}]} | cut -d',' -f 2 | read temp_crit - # [ "${PW_SENSOR_TYPE[${1}]}" != "esxi" ] && average=$(AVERAGETEMP ${PW_SENSOR_ID[${1}]} 3) || average=$(AVERAGETEMP ${PW_SENSOR_ID[${1}]} 3 ${5}) + [ "${1}" != "noavg" ] && ([ "${PW_SENSOR_TYPE[${1}]}" != "esxi" ] && average=$(AVERAGETEMP ${PW_SENSOR_ID[${1}]} 3) || average=$(AVERAGETEMP ${PW_SENSOR_ID[${1}]} 3 ${5})) if [ "${PW_SENSOR_TYPE[${1}]}" == "mqtt" ]; then mqtt_message=`${mqtt_conn} -t tele/${1}/SENSOR -C 1` @@ -123,17 +123,20 @@ CHECKTEMPSENSOR(){ #echo "$temp_c -> $temp_f" c=0; spct=''; spc1=`expr 6 - ${#temp_f}`; until [ $c = ${spc1} ]; do spct="${spct} "; c=`expr ${c} + 1`; done - # c=0; spca=''; spc1=`expr 6 - ${#average}`; until [ $c = ${spc1} ]; do spca="${spca} "; c=`expr ${c} + 1`; done - # if [ "${average}" == "" ]; then - # averagedisp="${idsCL[Green]}" - # elif [ $(bc -l <<< "${average} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${average} < ${temp_crit}") -eq 1 ]; then - # averagedisp="${idsCL[Yellow]}${average}'F" - # elif [ $(bc -l <<< "${average} >= ${temp_crit}") -eq 1 ]; then - # averagedisp="${idsCL[Red]}${average}'F" - # else - # averagedisp="${idsCL[Green]}${average}'F" - # fi - averagedisp=' ' + if [ "${1}" != "noavg" ]; then + c=0; spca=''; spc1=`expr 6 - ${#average}`; until [ $c = ${spc1} ]; do spca="${spca} "; c=`expr ${c} + 1`; done + if [ "${average}" == "" ]; then + averagedisp="${idsCL[Green]}" + elif [ $(bc -l <<< "${average} >= ${temp_warn}") -eq 1 ] && [ $(bc -l <<< "${average} < ${temp_crit}") -eq 1 ]; then + averagedisp="${idsCL[Yellow]}${average}'F" + elif [ $(bc -l <<< "${average} >= ${temp_crit}") -eq 1 ]; then + averagedisp="${idsCL[Red]}${average}'F" + else + averagedisp="${idsCL[Green]}${average}'F" + fi + else + averagedisp=' ' + fi if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then echo -en "${idsCL[Yellow]}WARNING (${spct}${temp_f}'F / ${spca}${averagedisp}${idsCL[Yellow]})${idsCL[Default]}"