From 7b51e1afa477df9552de03fe15dabf05199f8cd0 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 10 Oct 2020 23:04:28 +0200 Subject: [PATCH] ensure heating_active and tapwater_active MQTT topics are sent on cold start --- src/devices/boiler.cpp | 10 +++++----- src/devices/boiler.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 0d7c862b7..3a6d8b4d2 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -97,8 +97,8 @@ void Boiler::register_mqtt_ha_config() { ids.add("ems-esp-boiler"); Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/boiler/config"), doc.as(), true); // publish the config payload with retain flag - Mqtt::register_mqtt_ha_binary_sensor(F_(tapwaterActive), this->device_type(), "tapwaterActive"); - Mqtt::register_mqtt_ha_binary_sensor(F_(heatingActive), this->device_type(), "heatingActive"); + Mqtt::register_mqtt_ha_binary_sensor(F_(tapwaterActive), this->device_type(), "tapwater_active"); + Mqtt::register_mqtt_ha_binary_sensor(F_(heatingActive), this->device_type(), "heating_active"); Mqtt::register_mqtt_ha_sensor(nullptr, F_(serviceCodeNumber), this->device_type(), "serviceCodeNumber", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWSelTemp), this->device_type(), "wWSelTemp", F_(degrees), F_(icontemperature)); @@ -604,7 +604,7 @@ void Boiler::publish_values() { Mqtt::publish(F("boiler_data"), doc.as()); } - // send out heating and tapwater status - even if there is no change (force = true) + // send out heating and tapwater status check_active(); } @@ -711,14 +711,14 @@ void Boiler::show_values(uuid::console::Shell & shell) { * If a value has changed, post it immediately to MQTT so we get real time data */ void Boiler::check_active() { - if ((boilerState_ & 0x09) != (last_boilerState & 0x09)) { + if ((boilerState_ == EMS_VALUE_UINT_NOTSET) || ((boilerState_ & 0x09) != (last_boilerState & 0x09))) { char s[7]; bool b = ((boilerState_ & 0x09) == 0x09); Mqtt::publish(F("heating_active"), Helpers::render_boolean(s, b)); heatingActive_ = b ? EMS_VALUE_BOOL_ON : EMS_VALUE_BOOL_OFF; } - if ((boilerState_ & 0x0A) != (last_boilerState & 0x0A)) { + if ((boilerState_ == EMS_VALUE_UINT_NOTSET) || ((boilerState_ & 0x0A) != (last_boilerState & 0x0A))) { char s[7]; bool b = ((boilerState_ & 0x0A) == 0x0A); Mqtt::publish(F("tapwater_active"), Helpers::render_boolean(s, b)); diff --git a/src/devices/boiler.h b/src/devices/boiler.h index ccc1e7f35..b46e5bc24 100644 --- a/src/devices/boiler.h +++ b/src/devices/boiler.h @@ -52,7 +52,7 @@ class Boiler : public EMSdevice { void print_value2(uuid::console::Shell & shell, const char * param, const __FlashStringHelper * name, const __FlashStringHelper * suffix, JsonObject & json); - uint8_t last_boilerState = 0xFF; // remember last state of heating and warm water on/off + uint8_t last_boilerState = EMS_VALUE_UINT_NOTSET; // remember last state of heating and warm water on/off bool changed_ = false; bool mqtt_ha_config_ = false; // HA MQTT Discovery @@ -97,7 +97,7 @@ class Boiler : public EMSdevice { uint8_t sysPress_ = EMS_VALUE_UINT_NOTSET; // System pressure char serviceCode_[3] = {'\0'}; // 2 character status/service code uint16_t serviceCodeNumber_ = EMS_VALUE_USHORT_NOTSET; // error/service code - uint8_t boilerState_ = EMS_VALUE_BOOL_NOTSET; // State flag, used on HT3 + uint8_t boilerState_ = EMS_VALUE_UINT_NOTSET; // Boiler state flag // UBAMonitorSlow - 0x19 on EMS1 int16_t outdoorTemp_ = EMS_VALUE_SHORT_NOTSET; // Outside temperature