mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
mqtt_ha_sensor for new tags and nested on/off
This commit is contained in:
20
src/mqtt.cpp
20
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
|
// if its a boiler we use the tag
|
||||||
char stat_t[MQTT_TOPIC_MAX_SIZE];
|
char stat_t[MQTT_TOPIC_MAX_SIZE];
|
||||||
if (device_type == EMSdevice::DeviceType::BOILER) {
|
if (device_type == EMSdevice::DeviceType::BOILER) {
|
||||||
snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s"), EMSdevice::tag_to_string(tag).c_str());
|
if (tag == DeviceValueTAG::TAG_BOILER_DATA) {
|
||||||
} else if (device_type == EMSdevice::DeviceType::SYSTEM) {
|
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"));
|
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);
|
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;
|
doc["stat_t"] = stat_t;
|
||||||
|
|
||||||
@@ -853,7 +861,11 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
|
|||||||
|
|
||||||
// value template
|
// value template
|
||||||
char val_tpl[50];
|
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;
|
doc["val_tpl"] = val_tpl;
|
||||||
|
|
||||||
char topic[MQTT_TOPIC_MAX_SIZE]; // reserved for topic
|
char topic[MQTT_TOPIC_MAX_SIZE]; // reserved for topic
|
||||||
|
|||||||
Reference in New Issue
Block a user