thermferm/thermferm.c

changeset 525
5855abe0e82c
parent 524
bd1ea64ae484
child 526
2f75f94d471b
--- a/thermferm/thermferm.c	Mon Jul 24 22:55:28 2017 +0200
+++ b/thermferm/thermferm.c	Tue Jul 25 11:43:35 2017 +0200
@@ -1065,7 +1065,7 @@
 	/*
 	 * Safety, turn everything off
 	 */
-	unit->mqtt_flag = 0;
+	unit->mqtt_flag = unit->alarm_flag = unit->alarm_last = 0;
 	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
 	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 	if (unit->mode == UNITMODE_PROFILE) {
@@ -1217,7 +1217,7 @@
 	    LCDunit = 0;
 	    for (unit = Config.units; unit; unit = unit->next) {
 		LCDunit++;
-		unit->mqtt_flag = 0;
+		unit->mqtt_flag = unit->alarm_flag = 0;
 
 		if (unit->air_address) {
 		    rc = device_in(unit->air_address, &temp);
@@ -1313,6 +1313,12 @@
 				pub_domoticz_output(unit->door_idx, unit->door_state);
 				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
+			    /*
+			     * If unit is active and the door is open
+			     */
+			    if (unit->mode != UNITMODE_NONE) {
+				unit->alarm_flag |= ALARM_FLAG_DOOR;
+			    }
 			}
 		    } else {
 			unit->door_state = 1;
@@ -1341,6 +1347,7 @@
 				pub_domoticz_output(unit->psu_idx, unit->psu_state);
 				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
+			    unit->alarm_flag |= ALARM_FLAG_PSU;
 			}
 		    } else {
 			unit->psu_state = 1;
@@ -1657,6 +1664,7 @@
 			if (unit->chiller_address && (unit->chiller_state == 0)) {
 			    if ((unit->chiller_temperature / 1000.0) > (unit->PID_cool->Input - 1)) {
 			    	unit->PID_cool->OutP = 0.0;
+				unit->alarm_flag |= ALARM_FLAG_CHILLER;
 			    }
 			}
 		    	if (debug)
@@ -1840,6 +1848,14 @@
 		if (unit->mqtt_flag) {
 		    publishDData(unit);
 		}
+
+		/*
+		 * Handle changed alarms
+		 */
+		if (unit->alarm_flag != unit->alarm_last) {
+		    syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->name, unit->alarm_last, unit->alarm_flag);
+		    unit->alarm_last = unit->alarm_flag;
+		}
 	    } /* for units */
 
 #ifdef HAVE_WIRINGPI_H

mercurial