don't use ems-esp-system for HA

This commit is contained in:
proddy
2021-03-06 16:12:21 +01:00
parent 8d327ba540
commit acd678d30c

View File

@@ -372,7 +372,7 @@ void Mqtt::start() {
// fetch MQTT settings, to see if MQTT is enabled
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & mqttSettings) {
mqtt_enabled_ = mqttSettings.enabled;
mqtt_base_ = mqttSettings.base.c_str();
mqtt_base_ = mqttSettings.base.c_str(); // Convert String to std::string
if (!mqtt_enabled_) {
return; // quit, not using MQTT
}
@@ -577,7 +577,7 @@ void Mqtt::ha_status() {
dev["mf"] = FJSON("proddy");
dev["mdl"] = F_(EMSESP); // "EMS-ESP"
JsonArray ids = dev.createNestedArray("ids");
ids.add("ems-esp-system");
ids.add("ems-esp");
char topic[MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/system/config"), mqtt_base_.c_str());
@@ -822,15 +822,17 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
std::replace(uniq.begin(), uniq.end(), '.', '_');
doc["uniq_id"] = uniq;
doc["~"] = mqtt_base_;
// state topic
// 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/%s"), mqtt_base_.c_str(), EMSdevice::tag_to_string(tag).c_str());
snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s"), EMSdevice::tag_to_string(tag).c_str());
} else if (device_type == EMSdevice::DeviceType::SYSTEM) {
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/heartbeat"), mqtt_base_.c_str());
snprintf_P(stat_t, sizeof(stat_t), PSTR("~/heartbeat"));
} else {
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s_data"), mqtt_base_.c_str(), device_name);
snprintf_P(stat_t, sizeof(stat_t), PSTR("~/%s_data"), device_name);
}
doc["stat_t"] = stat_t;
@@ -889,9 +891,15 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
JsonObject dev = doc.createNestedObject("dev");
JsonArray ids = dev.createNestedArray("ids");
// for System commands we'll use the ID EMS-ESP
if (device_type == EMSdevice::DeviceType::SYSTEM) {
ids.add("ems-esp");
} else {
char ha_device[40];
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
ids.add(ha_device);
}
publish_ha(topic, doc.as<JsonObject>());
}