diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 77b42b6b0..68fc2947e 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -6,6 +6,8 @@ - Translations in Web UI and all device entity names to German. [#22](https://github.com/emsesp/EMS-ESP32/issues/22) - Add support for Lolin C3 mini [#620](https://github.com/emsesp/EMS-ESP32/pull/620) +- Add Greenstar 30Ri boiler +- Add program memory info ## Fixed @@ -13,9 +15,10 @@ ## Changed -- Discovery in HomeAssistant don't work with custom base topic. [#596](https://github.com/emsesp/EMS-ESP32/issues/596) +- Discovery in HomeAssistant don't work with custom base topic. [#596](https://github.com/emsesp/EMS-ESP32/issues/596) Base topic containing `/` are changed to `_` +- RF room temperature sensor are shown as thermostat ## **BREAKING CHANGES:** -- MQTT Discovery (Home Assistant) entity names are now prefixed with the hostname, e.g. `select.thermostat_hc1_mode` becomes `select.emsesp_thermostat_hc1_mode`. You will need to recreate any custom dashboards. + - When upgrading from 3.4.x you may need to erase the flash on the ESP32 before uploading the firmware. Make sure you make a backup of the settings and customizations via the WebUI (System->Upload/Download) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index f7c07b8bd..b9624ca9c 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -581,13 +581,7 @@ void Mqtt::on_connect() { publish(F_(info), doc.as()); // topic called "info" if (ha_enabled_) { - LOG_INFO(F("start removing topics %s/+/%s/#"), discovery_prefix_.c_str(), mqtt_basename_.c_str()); - queue_unsubscribe_message(discovery_prefix_ + "/climate/" + mqtt_basename_ + "/#"); - queue_unsubscribe_message(discovery_prefix_ + "/sensor/" + mqtt_basename_ + "/#"); - queue_unsubscribe_message(discovery_prefix_ + "/binary_sensor/" + mqtt_basename_ + "/#"); - queue_unsubscribe_message(discovery_prefix_ + "/number/" + mqtt_basename_ + "/#"); - queue_unsubscribe_message(discovery_prefix_ + "/select/" + mqtt_basename_ + "/#"); - queue_unsubscribe_message(discovery_prefix_ + "/switch/" + mqtt_basename_ + "/#"); + queue_unsubscribe_message(discovery_prefix_ + "/+/" + mqtt_basename_ + "/#"); EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any ha_status(); // create the EMS-ESP device in HA, which is MQTT retained ha_climate_reset(true); @@ -595,13 +589,8 @@ void Mqtt::on_connect() { // with disabled HA we subscribe and the broker sends all stored HA-emsesp-configs. // In line 272 they are removed. If HA is enabled the subscriptions are removed. // As described in the doc (https://emsesp.github.io/docs/#/Troubleshooting?id=home-assistant): - // disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again. - queue_subscribe_message(discovery_prefix_ + "/climate/" + mqtt_basename_ + "/#"); - queue_subscribe_message(discovery_prefix_ + "/sensor/" + mqtt_basename_ + "/#"); - queue_subscribe_message(discovery_prefix_ + "/binary_sensor/" + mqtt_basename_ + "/#"); - queue_subscribe_message(discovery_prefix_ + "/number/" + mqtt_basename_ + "/#"); - queue_subscribe_message(discovery_prefix_ + "/select/" + mqtt_basename_ + "/#"); - queue_subscribe_message(discovery_prefix_ + "/switch/" + mqtt_basename_ + "/#"); + // disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again. + queue_subscribe_message(discovery_prefix_ + "/+/" + mqtt_basename_ + "/#"); } // send initial MQTT messages for some of our services @@ -939,6 +928,7 @@ void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const std::string & model, publish_ha_sensor_config(dv.type, dv.tag, dv.get_fullname(), + dv.fullname[0], dv.device_type, dv.short_name, dv.uom, @@ -961,15 +951,16 @@ void Mqtt::publish_system_ha_sensor_config(uint8_t type, const __FlashStringHelp auto fullname = read_flash_string(name); - publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, fullname, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, dev_json); + publish_ha_sensor_config(type, DeviceValueTAG::TAG_HEARTBEAT, fullname, name, EMSdevice::DeviceType::SYSTEM, entity, uom, false, false, nullptr, 0, 0, 0, dev_json); } // MQTT discovery configs // entity must match the key/value pair in the *_data topic // note: some extra string copying done here, it looks messy but does help with heap fragmentation issues -void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType - uint8_t tag, // EMSdevice::DeviceValueTAG - const std::string & fullname, // fullname, already translated +void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType + uint8_t tag, // EMSdevice::DeviceValueTAG + const std::string & fullname, // fullname, already translated + const __FlashStringHelper * const en_name, const uint8_t device_type, // EMSdevice::DeviceType const __FlashStringHelper * const entity, // same as shortname const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE) @@ -981,7 +972,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, const int16_t dv_set_max, const JsonObject & dev_json) { // ignore if name (fullname) is empty - if (fullname.empty()) { + if (fullname.empty() || en_name == nullptr) { return; } @@ -1115,22 +1106,27 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, doc["stat_t"] = stat_t; // friendly name = - char ha_name[70]; + char ha_name[70]; + char * F_name = strdup(fullname.c_str()); + F_name[0] = toupper(F_name[0]); // capitalize first letter if (have_tag) { - snprintf(ha_name, sizeof(ha_name), "%s %s", EMSdevice::tag_to_string(tag).c_str(), fullname.c_str()); + snprintf(ha_name, sizeof(ha_name), "%s %s", EMSdevice::tag_to_string(tag).c_str(), F_name); } else { - snprintf(ha_name, sizeof(ha_name), "%s", fullname.c_str()); + snprintf(ha_name, sizeof(ha_name), "%s", F_name); } - ha_name[0] = toupper(ha_name[0]); // capitalize first letter + free(F_name); doc["name"] = ha_name; // entity id is generated from the name, see https://www.home-assistant.io/docs/mqtt/discovery/#use-object_id-to-influence-the-entity-id // so we override it to make it unique using entity_id // See https://github.com/emsesp/EMS-ESP32/issues/596 - // "__ " - // with basename a single instance with "/" replaced by "_" + // keep it compatible to v3.4, use english fullname, no prefix char object_id[130]; - snprintf(object_id, sizeof(object_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, ha_name); + if (have_tag) { + snprintf(object_id, sizeof(object_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), read_flash_string(en_name).c_str()); + } else { + snprintf(object_id, sizeof(object_id), "%s_%s", device_name, read_flash_string(en_name).c_str()); + } doc["object_id"] = object_id; // value template diff --git a/src/mqtt.h b/src/mqtt.h index ac463586b..26cfb51dc 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -95,6 +95,7 @@ class Mqtt { static void publish_ha_sensor_config(uint8_t type, uint8_t tag, const std::string & fullname, + const __FlashStringHelper * const en_name, const uint8_t device_type, const __FlashStringHelper * const entity, const uint8_t uom,