Update powerwall.sh

This commit is contained in:
2023-08-14 22:57:21 -05:00
parent 4dc6578bfb
commit c77ebcf07d

View File

@@ -163,10 +163,12 @@ CHECKTEMP_SERVICE(){
fi fi
SENSORS_CHECK=(${SENSOR})
if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "mqtt" ]; then if [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "mqtt" ]; then
mqtt_message=`${mqtt_conn} -t tele/${SENSOR}/SENSOR -C 1` mqtt_message=`${mqtt_conn} -t tele/${SENSOR}/SENSOR -C 1`
echo $mqtt_message | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h echo $mqtt_message | cut -d':' -f 7 | cut -d',' -f 1 | read temp_h
echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c echo $mqtt_message | cut -d':' -f 6 | cut -d',' -f 1 | read temp_c
SENSORS_CHECK=(${SENSOR})
elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ]; then elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "system" ]; then
temp_c=$(vcgencmd measure_temp) temp_c=$(vcgencmd measure_temp)
@@ -178,8 +180,12 @@ CHECKTEMP_SERVICE(){
temp_c=${temp_c%\'*}; temp_c=${temp_c#*=} temp_c=${temp_c%\'*}; temp_c=${temp_c#*=}
temp_h='' temp_h=''
# elif [ "${PW_SENSOR_TYPE[${SENSOR}]}" == "esxi" ]; then
fi fi
for SENSOR in ${SENSORS_CHECK[@]}; do
datetime=`date +'%Y-%m-%d %H:%M:%S'` datetime=`date +'%Y-%m-%d %H:%M:%S'`
logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR} logtemp=${PW_LOGFOLDER}/log-temp-${SENSOR}
@@ -258,8 +264,8 @@ CHECKTEMP_SERVICE(){
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.* [ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
elif [ ${last_temp[${SENSOR}]} -eq 0 ]; then elif [ ${last_temp[${SENSOR}]} -eq 0 ]; then
SENDNOTICE "${SENSOR} TEMP NORMAL" "($datetime) Service Startup # SENDNOTICE "${SENSOR} TEMP NORMAL" "($datetime) Service Startup
NORMAL TEMP: ${temp_f}'F" # NORMAL TEMP: ${temp_f}'F"
echo -e "($datetime) - ${temp_f}'F - Service Startup - NORMAL TEMP" >> ${logtemp} echo -e "($datetime) - ${temp_f}'F - Service Startup - NORMAL TEMP" >> ${logtemp}
echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - Service Startup" >> ${PW_LOGFILE} echo -e "($datetime) - ${temp_f}'F - ${SENSOR} - Service Startup" >> ${PW_LOGFILE}
[ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.* [ "$(compgen -G "${PW_FOLDER}/shutdown.*")" != "" ] && rm -f ${PW_FOLDER}/shutdown.*
@@ -284,8 +290,8 @@ CHECKTEMP_SERVICE(){
else else
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}')" QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`) VALUES ('${PW_SENSOR_ID[${SENSOR}]}','${datetime}','${temp_f}')"
fi fi
${mysql_conn} -e "${QRY}" # ${mysql_conn} -e "${QRY}"
touch ${PW_TMPFOLDER}/${SENSOR}.insert # touch ${PW_TMPFOLDER}/${SENSOR}.insert
fi fi
else else
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 1800 ]; then if [ ! -f ${PW_TMPFOLDER}/${SENSOR}-error.reading ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}-error.reading)) -ge 1800 ]; then
@@ -296,6 +302,8 @@ CHECKTEMP_SERVICE(){
fi fi
done
else #sensor down else #sensor down
if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then if [ ! -f ${PW_TMPFOLDER}/${SENSOR}.down ] || [ $(expr `date +%s` - $(stat -c %Y ${PW_TMPFOLDER}/${SENSOR}.down)) -ge 1800 ]; then
SENDNOTICE "${SENSOR} ERROR" "${SENSOR} Sensor is down" 1 SENDNOTICE "${SENSOR} ERROR" "${SENSOR} Sensor is down" 1