diff --git a/interface/src/framework/mqtt/MqttSettings.tsx b/interface/src/framework/mqtt/MqttSettings.tsx index 7ecc33ee7..ce59362c5 100644 --- a/interface/src/framework/mqtt/MqttSettings.tsx +++ b/interface/src/framework/mqtt/MqttSettings.tsx @@ -374,7 +374,12 @@ const MqttSettings: FC = () => { select > {LL.MQTT_ENTITY_FORMAT_0()} - {LL.MQTT_ENTITY_FORMAT_1()} (v3.6) + + {LL.MQTT_ENTITY_FORMAT_1()} (v3.6) + + + {LL.MQTT_ENTITY_FORMAT_2()} (v3.6) + {LL.MQTT_ENTITY_FORMAT_1()} {LL.MQTT_ENTITY_FORMAT_2()} diff --git a/src/mqtt.cpp b/src/mqtt.cpp index aa37d5453..e8f54b662 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -849,7 +849,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag); } else if (Mqtt::entity_format() == entityFormat::SINGLE_OLD) { // shortname, remap to 3.6. - if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) { + if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) + && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) { snprintf(uniq_id, sizeof(uniq_id), "%s_ww%s", device_name, entity); if (strcmp(entity, "nrgdhw") == 0) { // special case for tp1de #1714 strcpy(uniq_id, "boiler_nrgww"); @@ -861,6 +862,21 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } else { snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag); } + } else if (Mqtt::entity_format() == entityFormat::MULTI_OLD) { + // shortname, remap to 3.6. + if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) + && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) { + snprintf(uniq_id, sizeof(uniq_id), "%s_%s_ww%s", mqtt_basename_.c_str(), device_name, entity); + if (strcmp(entity, "nrgdhw") == 0) { // special case for tp1de #1714 + snprintf(uniq_id, sizeof(uniq_id), "%s_boiler_nrgww", mqtt_basename_.c_str()); + } + } else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW3) { + snprintf(uniq_id, sizeof(uniq_id), "%s_solar_wwc%d_%s", mqtt_basename_.c_str(), tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, entity); + } else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW1) { + snprintf(uniq_id, sizeof(uniq_id), "%s_mixer_wwc%d_%s", mqtt_basename_.c_str(), tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, entity); + } else { + snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag); + } } else { // entity_format is 0, the old v3.4 style // take en_name and replace all spaces @@ -868,7 +884,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev strlcpy(uniq_s, en_name, sizeof(uniq_s)); Helpers::replace_char(uniq_s, ' ', '_'); Helpers::replace_char(uniq_s, '+', '2'); //changes 'eco+_switch_off' to 'eco2_switch_off' (HA ignores '+') - if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) { + if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) + && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) { snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str()); } else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW3) { snprintf(uniq_id, sizeof(uniq_id), "solar_wwc%d_%s", tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, Helpers::toLower(uniq_s).c_str()); diff --git a/src/mqtt.h b/src/mqtt.h index dca935d8c..6ea9c4c9e 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -36,7 +36,7 @@ using mqtt_sub_function_p = std::function; class Mqtt { public: enum discoveryType : uint8_t { HOMEASSISTANT, DOMOTICZ, DOMOTICZ_LATEST }; - enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT, SINGLE_OLD }; + enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT, SINGLE_OLD, MULTI_OLD }; void loop(); void start(); diff --git a/src/system.cpp b/src/system.cpp index 3279adfee..17ddf77ef 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1154,13 +1154,18 @@ bool System::check_upgrade(bool factory_settings) { mqttSettings.entity_format = 0; // use old Entity ID format from v3.4 return StateUpdateResult::CHANGED; }); - } else if (settings_version.major()== 3 && settings_version.minor() <= 6) { + } else if (settings_version.major() == 3 && settings_version.minor() <= 6) { LOG_INFO("Setting MQTT Entity ID format to v3.6 format"); EMSESP::esp8266React.getMqttSettingsService()->update([&](MqttSettings & mqttSettings) { - mqttSettings.entity_format = 3; // use old Entity ID format from v3.6 - return StateUpdateResult::CHANGED; + if (mqttSettings.entity_format == 1) { + mqttSettings.entity_format = 3; // use old Entity ID format from v3.6 + return StateUpdateResult::CHANGED; + } else if (mqttSettings.entity_format == 2) { + mqttSettings.entity_format = 4; // use old Entity ID format from v3.6 + return StateUpdateResult::CHANGED; + } + return StateUpdateResult::UNCHANGED; }); - } // Network Settings Wifi tx_power is now using the value * 4.