Update powerwall.sh
This commit is contained in:
18
powerwall.sh
18
powerwall.sh
@@ -45,6 +45,10 @@ CHECKTEMP_SERVICE(){
|
|||||||
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
|
||||||
echo $mqtt_message | cut -d'T' -f 2 | cut -d"\"" -f 3 | read temp_d
|
echo $mqtt_message | cut -d'T' -f 2 | cut -d"\"" -f 3 | read temp_d
|
||||||
echo $mqtt_message | cut -d'T' -f 3 | cut -d"\"" -f 1 | read temp_t
|
echo $mqtt_message | cut -d'T' -f 3 | cut -d"\"" -f 1 | read temp_t
|
||||||
|
datetime="${temp_d} ${temp_t}"
|
||||||
|
datetime=$(TZ=America/Chicago date -d "datetime" +%s)
|
||||||
|
datetime=`date -d @datetime +'%Y-%m-%d %H:%M:%S'`
|
||||||
|
|
||||||
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
|
if [ "$temp_c" != "null" ] && [ "$temp_c" != "" ]; then
|
||||||
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
|
temp_f=`echo "scale=2; $temp_c*1.8 + 32" | bc`
|
||||||
|
|
||||||
@@ -58,28 +62,28 @@ CHECKTEMP_SERVICE(){
|
|||||||
|
|
||||||
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then
|
if [ $(bc -l <<< "$temp_f >= $temp_warn") -eq 1 ] && [ $(bc -l <<< "$temp_f < $temp_crit") -eq 1 ]; then
|
||||||
if [ $temp_diff -gt 1 ] || [ "$last_temp" == "0" ]; then
|
if [ $temp_diff -gt 1 ] || [ "$last_temp" == "0" ]; then
|
||||||
echo "($temp_d @ $temp_t) WARNING TEMP: $temp_f°F - (Difference of $temp_diff°)" | mail -s "${1} TEMP WARNING" $email_alert
|
echo "($datetime) WARNING TEMP: $temp_f°F - (Difference of $temp_diff°)" | mail -s "${1} TEMP WARNING" $email_alert
|
||||||
last_temp=$temp_f
|
last_temp=$temp_f
|
||||||
fi
|
fi
|
||||||
echo "($temp_d @ $temp_t) WARNING: $temp_f°F - (Difference of $temp_diff°)"
|
echo "($datetime) WARNING: $temp_f°F - (Difference of $temp_diff°)"
|
||||||
|
|
||||||
elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then
|
elif [ $(bc -l <<< "$temp_f >= $temp_crit") -eq 1 ]; then
|
||||||
if [ $temp_diff -gt 1 ] || [ "$last_temp" == "0" ]; then
|
if [ $temp_diff -gt 1 ] || [ "$last_temp" == "0" ]; then
|
||||||
echo "($temp_d @ $temp_t) CRITICAL TEMP: $temp_f°F - (Difference of $temp_diff°)" | mail -s "${1} TEMP CRITICAL" $email_alert
|
echo "($datetime) CRITICAL TEMP: $temp_f°F - (Difference of $temp_diff°)" | mail -s "${1} TEMP CRITICAL" $email_alert
|
||||||
last_temp=$temp_f
|
last_temp=$temp_f
|
||||||
fi
|
fi
|
||||||
echo "($temp_d @ $temp_t) CRITICAL: $temp_f°F - (Difference of $temp_diff°)"
|
echo "($datetime) CRITICAL: $temp_f°F - (Difference of $temp_diff°)"
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ "$last_temp" != "1" ]; then
|
if [ "$last_temp" != "1" ]; then
|
||||||
echo "NORMAL TEMP: $temp_f°F" | mail -s "${1} BACK TO NORMAL" $email_alert
|
echo "($datetime) NORMAL TEMP: $temp_f°F" | mail -s "${1} BACK TO NORMAL" $email_alert
|
||||||
last_temp=1
|
last_temp=1
|
||||||
fi
|
fi
|
||||||
# echo "NORMAL TEMP: $temp_f°F" | mail -s "${1} TEMP NORMAL" $email_alert
|
# echo "NORMAL TEMP: $temp_f°F" | mail -s "${1} TEMP NORMAL" $email_alert
|
||||||
echo "($temp_d @ $temp_t) normal: $temp_f°F"
|
echo "($datetime) normal: $temp_f°F"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`, \`hum\`) VALUES ('${SENSOR_ID[$1]}','${temp_d} ${temp_t}','${temp_f}','${temp_h}')"
|
QRY="USE servermonitor; INSERT INTO sensor_data (\`sensorid\`, \`date\`, \`temp\`, \`hum\`) VALUES ('${SENSOR_ID[$1]}','${datetime}','${temp_f}','${temp_h}')"
|
||||||
${mysql_conn} -e "${QRY}"
|
${mysql_conn} -e "${QRY}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user