mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
use old HA object_id, #636, HA (un)subscribes with wildcard
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
- Translations in Web UI and all device entity names to German. [#22](https://github.com/emsesp/EMS-ESP32/issues/22)
|
- 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 support for Lolin C3 mini [#620](https://github.com/emsesp/EMS-ESP32/pull/620)
|
||||||
|
- Add Greenstar 30Ri boiler
|
||||||
|
- Add program memory info
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
@@ -13,9 +15,10 @@
|
|||||||
|
|
||||||
## Changed
|
## 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:**
|
## **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)
|
- 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)
|
||||||
|
|||||||
48
src/mqtt.cpp
48
src/mqtt.cpp
@@ -581,13 +581,7 @@ void Mqtt::on_connect() {
|
|||||||
publish(F_(info), doc.as<JsonObject>()); // topic called "info"
|
publish(F_(info), doc.as<JsonObject>()); // topic called "info"
|
||||||
|
|
||||||
if (ha_enabled_) {
|
if (ha_enabled_) {
|
||||||
LOG_INFO(F("start removing topics %s/+/%s/#"), discovery_prefix_.c_str(), mqtt_basename_.c_str());
|
queue_unsubscribe_message(discovery_prefix_ + "/+/" + mqtt_basename_ + "/#");
|
||||||
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_ + "/#");
|
|
||||||
EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any
|
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_status(); // create the EMS-ESP device in HA, which is MQTT retained
|
||||||
ha_climate_reset(true);
|
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.
|
// 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.
|
// 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):
|
// 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.
|
// 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_ + "/+/" + 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_ + "/#");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send initial MQTT messages for some of our services
|
// 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,
|
publish_ha_sensor_config(dv.type,
|
||||||
dv.tag,
|
dv.tag,
|
||||||
dv.get_fullname(),
|
dv.get_fullname(),
|
||||||
|
dv.fullname[0],
|
||||||
dv.device_type,
|
dv.device_type,
|
||||||
dv.short_name,
|
dv.short_name,
|
||||||
dv.uom,
|
dv.uom,
|
||||||
@@ -961,15 +951,16 @@ void Mqtt::publish_system_ha_sensor_config(uint8_t type, const __FlashStringHelp
|
|||||||
|
|
||||||
auto fullname = read_flash_string(name);
|
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
|
// MQTT discovery configs
|
||||||
// entity must match the key/value pair in the *_data topic
|
// 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
|
// 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
|
void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType
|
||||||
uint8_t tag, // EMSdevice::DeviceValueTAG
|
uint8_t tag, // EMSdevice::DeviceValueTAG
|
||||||
const std::string & fullname, // fullname, already translated
|
const std::string & fullname, // fullname, already translated
|
||||||
|
const __FlashStringHelper * const en_name,
|
||||||
const uint8_t device_type, // EMSdevice::DeviceType
|
const uint8_t device_type, // EMSdevice::DeviceType
|
||||||
const __FlashStringHelper * const entity, // same as shortname
|
const __FlashStringHelper * const entity, // same as shortname
|
||||||
const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE)
|
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 int16_t dv_set_max,
|
||||||
const JsonObject & dev_json) {
|
const JsonObject & dev_json) {
|
||||||
// ignore if name (fullname) is empty
|
// ignore if name (fullname) is empty
|
||||||
if (fullname.empty()) {
|
if (fullname.empty() || en_name == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1115,22 +1106,27 @@ void Mqtt::publish_ha_sensor_config(uint8_t type,
|
|||||||
doc["stat_t"] = stat_t;
|
doc["stat_t"] = stat_t;
|
||||||
|
|
||||||
// friendly name = <tag> <name>
|
// friendly name = <tag> <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) {
|
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 {
|
} 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;
|
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
|
// 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
|
// so we override it to make it unique using entity_id
|
||||||
// See https://github.com/emsesp/EMS-ESP32/issues/596
|
// See https://github.com/emsesp/EMS-ESP32/issues/596
|
||||||
// "<basename>_<device>_<tag> <name>"
|
// keep it compatible to v3.4, use english fullname, no prefix
|
||||||
// with basename a single instance with "/" replaced by "_"
|
|
||||||
char object_id[130];
|
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;
|
doc["object_id"] = object_id;
|
||||||
|
|
||||||
// value template
|
// value template
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ class Mqtt {
|
|||||||
static void publish_ha_sensor_config(uint8_t type,
|
static void publish_ha_sensor_config(uint8_t type,
|
||||||
uint8_t tag,
|
uint8_t tag,
|
||||||
const std::string & fullname,
|
const std::string & fullname,
|
||||||
|
const __FlashStringHelper * const en_name,
|
||||||
const uint8_t device_type,
|
const uint8_t device_type,
|
||||||
const __FlashStringHelper * const entity,
|
const __FlashStringHelper * const entity,
|
||||||
const uint8_t uom,
|
const uint8_t uom,
|
||||||
|
|||||||
Reference in New Issue
Block a user