diff -r 34bf9f389749 -r 49580ca85ab7 thermferm/thermferm.c --- a/thermferm/thermferm.c Fri Aug 18 17:45:14 2017 +0200 +++ b/thermferm/thermferm.c Sat Jul 14 17:21:25 2018 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2017 + * Copyright (C) 2014-2018 * * Michiel Broek * @@ -391,11 +391,15 @@ */ void change_mode(int mode) { - if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) + current_unit->mqtt_flag |= MQTT_FLAG_DATA; + if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) { initlog(current_unit->name); + current_unit->mqtt_flag |= MQTT_FLAG_BIRTH; + } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) { + current_unit->mqtt_flag |= MQTT_FLAG_DEATH; + } syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); current_unit->mode = mode; - current_unit->mqtt_flag |= MQTT_FLAG_DATA; /* Allways turn everything off after a mode change */ current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0; current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE; @@ -1217,7 +1221,8 @@ LCDunit = 0; for (unit = Config.units; unit; unit = unit->next) { LCDunit++; - unit->mqtt_flag = unit->alarm_flag = 0; + unit->mqtt_flag &= ~MQTT_FLAG_DATA; + unit->alarm_flag = 0; if (unit->air_address) { rc = device_in(unit->air_address, &temp); @@ -1850,7 +1855,17 @@ * Publish MQTT messages set in flag */ if (unit->mqtt_flag) { - publishDData(unit); + if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { + publishDBirth(unit); + unit->mqtt_flag &= ~MQTT_FLAG_BIRTH; + } else { + publishDData(unit); + unit->mqtt_flag &= ~MQTT_FLAG_DATA; + } + if (unit->mqtt_flag & MQTT_FLAG_DEATH) { + publishDDeath(unit); + unit->mqtt_flag &= ~MQTT_FLAG_DEATH; + } } /* @@ -1984,8 +1999,14 @@ device_out(unit->fan_address, unit->fan_state); pub_domoticz_output(unit->fan_idx, unit->fan_state); device_out(unit->light_address, unit->light_state); - unit->mqtt_flag = MQTT_FLAG_DATA; - publishDData(unit); + if (unit->mode != UNITMODE_OFF) { + /* + * If unit ia active, publish we are dying. + */ + unit->mqtt_flag = MQTT_FLAG_DATA; + publishDData(unit); + publishDDeath(unit); + } syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]); }