mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
don't use ems-esp-system for HA
This commit is contained in:
18
src/mqtt.cpp
18
src/mqtt.cpp
@@ -372,7 +372,7 @@ void Mqtt::start() {
|
|||||||
// fetch MQTT settings, to see if MQTT is enabled
|
// fetch MQTT settings, to see if MQTT is enabled
|
||||||
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & mqttSettings) {
|
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & mqttSettings) {
|
||||||
mqtt_enabled_ = mqttSettings.enabled;
|
mqtt_enabled_ = mqttSettings.enabled;
|
||||||
mqtt_base_ = mqttSettings.base.c_str();
|
mqtt_base_ = mqttSettings.base.c_str(); // Convert String to std::string
|
||||||
if (!mqtt_enabled_) {
|
if (!mqtt_enabled_) {
|
||||||
return; // quit, not using MQTT
|
return; // quit, not using MQTT
|
||||||
}
|
}
|
||||||
@@ -577,7 +577,7 @@ void Mqtt::ha_status() {
|
|||||||
dev["mf"] = FJSON("proddy");
|
dev["mf"] = FJSON("proddy");
|
||||||
dev["mdl"] = F_(EMSESP); // "EMS-ESP"
|
dev["mdl"] = F_(EMSESP); // "EMS-ESP"
|
||||||
JsonArray ids = dev.createNestedArray("ids");
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
ids.add("ems-esp-system");
|
ids.add("ems-esp");
|
||||||
|
|
||||||
char topic[MQTT_TOPIC_MAX_SIZE];
|
char topic[MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/system/config"), mqtt_base_.c_str());
|
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(), '.', '_');
|
std::replace(uniq.begin(), uniq.end(), '.', '_');
|
||||||
doc["uniq_id"] = uniq;
|
doc["uniq_id"] = uniq;
|
||||||
|
|
||||||
|
doc["~"] = mqtt_base_;
|
||||||
|
|
||||||
// state topic
|
// state topic
|
||||||
// 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/%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) {
|
} 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 {
|
} 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;
|
doc["stat_t"] = stat_t;
|
||||||
|
|
||||||
@@ -889,9 +891,15 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
|
|||||||
JsonObject dev = doc.createNestedObject("dev");
|
JsonObject dev = doc.createNestedObject("dev");
|
||||||
|
|
||||||
JsonArray ids = dev.createNestedArray("ids");
|
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];
|
char ha_device[40];
|
||||||
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
|
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
|
||||||
ids.add(ha_device);
|
ids.add(ha_device);
|
||||||
|
}
|
||||||
|
|
||||||
publish_ha(topic, doc.as<JsonObject>());
|
publish_ha(topic, doc.as<JsonObject>());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user