From d53e742feedd686d9a554a215ffdcb997f2c3352 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 11 Mar 2021 11:54:49 +0100 Subject: [PATCH] mqtt_ha_sensor for new tags and nested on/off --- src/mqtt.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 39abf4bf4..bd70ea08c 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -833,11 +833,19 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice // if its a boiler we use the tag char stat_t[MQTT_TOPIC_MAX_SIZE]; if (device_type == EMSdevice::DeviceType::BOILER) { - snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s"), EMSdevice::tag_to_string(tag).c_str()); - } else if (device_type == EMSdevice::DeviceType::SYSTEM) { + if (tag == DeviceValueTAG::TAG_BOILER_DATA) { + snprintf_P(stat_t, sizeof(stat_t), PSTR("~/boiler_data")); + } else if (tag == DeviceValueTAG::TAG_BOILER_DATA_WW) { + snprintf_P(stat_t, sizeof(stat_t), PSTR("~/boiler_data_ww")); + } else { + snprintf_P(stat_t, sizeof(stat_t), PSTR("~/boiler_data_info")); + } + } else if (device_type == EMSdevice::DeviceType::SYSTEM) { snprintf_P(stat_t, sizeof(stat_t), PSTR("~/heartbeat")); - } else { + } else if (nested_format_ || !have_prefix) { snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s_data"), device_name); + } else { + snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s_data_%s"), device_name, EMSdevice::tag_to_string(tag).c_str()); } doc["stat_t"] = stat_t; @@ -853,7 +861,11 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice // value template char val_tpl[50]; - snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), new_entity); + if (nested_format_) { + snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), new_entity); + } else { + snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), uuid::read_flash_string(entity).c_str()); + } doc["val_tpl"] = val_tpl; char topic[MQTT_TOPIC_MAX_SIZE]; // reserved for topic