# HG changeset patch # User Michiel Broek # Date 1500975815 -7200 # Node ID 5855abe0e82c68a626256d5c297a59307c827707 # Parent bd1ea64ae484b375ab85fbf336ffc0ecdfc1566a Added unit alarm flag diff -r bd1ea64ae484 -r 5855abe0e82c thermferm/thermferm.c --- 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 diff -r bd1ea64ae484 -r 5855abe0e82c thermferm/thermferm.h --- a/thermferm/thermferm.h Mon Jul 24 22:55:28 2017 +0200 +++ b/thermferm/thermferm.h Tue Jul 25 11:43:35 2017 +0200 @@ -195,6 +195,8 @@ pid_var *PID_cool; /* PID cooler */ pid_var *PID_heat; /* PID heater */ int mqtt_flag; /* MQTT print values flag */ + int alarm_flag; /* Alarm flag */ + int alarm_last; /* Last alarm state */ } units_list; #define UNITMODE_OFF 0 /* Unit turned off */ @@ -207,6 +209,10 @@ #define MQTT_NODE_CONTROL 0x0001 /* Show node control */ +#define ALARM_FLAG_DOOR 0x0001 /* Door open */ +#define ALARM_FLAG_PSU 0x0002 /* PSU problem */ +#define ALARM_FLAG_CHILLER 0x0004 /* Chiller too warm */ + /*