mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-12 18:59:51 +03:00
fix #2800
This commit is contained in:
@@ -195,9 +195,8 @@ void Shower::create_ha_discovery() {
|
|||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
char str[70];
|
char str[70];
|
||||||
char stat_t[50];
|
|
||||||
|
|
||||||
doc["~"] = Mqtt::base();
|
doc["~"] = Mqtt::base();
|
||||||
|
|
||||||
// shower active
|
// shower active
|
||||||
doc["name"] = "Shower Active";
|
doc["name"] = "Shower Active";
|
||||||
@@ -209,11 +208,11 @@ void Shower::create_ha_discovery() {
|
|||||||
}
|
}
|
||||||
doc["uniq_id"] = str;
|
doc["uniq_id"] = str;
|
||||||
doc["def_ent_id"] = (std::string) "binary_sensor." + str;
|
doc["def_ent_id"] = (std::string) "binary_sensor." + str;
|
||||||
doc["stat_t"] = "~/shower_active";
|
doc["stat_t"] = "~/shower_active";
|
||||||
|
|
||||||
Mqtt::add_ha_bool(doc.as<JsonObject>());
|
Mqtt::add_ha_bool(doc.as<JsonObject>());
|
||||||
Mqtt::add_ha_dev_section(doc.as<JsonObject>(), "Shower Sensor", nullptr, nullptr, nullptr, false);
|
Mqtt::add_ha_dev_section(doc.as<JsonObject>(), "Shower Sensor", nullptr, nullptr, nullptr, false);
|
||||||
Mqtt::add_ha_avail_section(doc.as<JsonObject>(), stat_t, true); // no conditions
|
Mqtt::add_ha_avail_section(doc.as<JsonObject>(), "~/shower_active", true); // no conditions
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str());
|
snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str());
|
||||||
ha_configdone_ = Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
ha_configdone_ = Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
||||||
@@ -225,8 +224,8 @@ void Shower::create_ha_discovery() {
|
|||||||
|
|
||||||
doc["uniq_id"] = str;
|
doc["uniq_id"] = str;
|
||||||
doc["def_ent_id"] = (std::string) "sensor." + str;
|
doc["def_ent_id"] = (std::string) "sensor." + str;
|
||||||
doc["stat_t"] = "~/shower_data",
|
doc["stat_t"] = "~/shower_data";
|
||||||
doc["name"] = "Shower Duration";
|
doc["name"] = "Shower Duration";
|
||||||
|
|
||||||
// don't bother with value template conditions if using Domoticz which doesn't fully support MQTT Discovery
|
// don't bother with value template conditions if using Domoticz which doesn't fully support MQTT Discovery
|
||||||
if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) {
|
if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) {
|
||||||
@@ -241,7 +240,7 @@ void Shower::create_ha_discovery() {
|
|||||||
// doc["ent_cat"] = "diagnostic";
|
// doc["ent_cat"] = "diagnostic";
|
||||||
|
|
||||||
Mqtt::add_ha_dev_section(doc.as<JsonObject>(), "Shower Sensor", nullptr, nullptr, nullptr, false);
|
Mqtt::add_ha_dev_section(doc.as<JsonObject>(), "Shower Sensor", nullptr, nullptr, nullptr, false);
|
||||||
Mqtt::add_ha_avail_section(doc.as<JsonObject>(), stat_t, false, "value_json.duration is defined");
|
Mqtt::add_ha_avail_section(doc.as<JsonObject>(), "~/shower_data", false, "value_json.duration is defined");
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/shower_duration/config", Mqtt::basename().c_str());
|
snprintf(topic, sizeof(topic), "sensor/%s/shower_duration/config", Mqtt::basename().c_str());
|
||||||
Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ void TemperatureSensor::publish_values(const bool force) {
|
|||||||
LOG_DEBUG("Recreating HA config for sensor ID %s", sensor.id().c_str());
|
LOG_DEBUG("Recreating HA config for sensor ID %s", sensor.id().c_str());
|
||||||
|
|
||||||
JsonDocument config;
|
JsonDocument config;
|
||||||
config["~"] = Mqtt::base();
|
config["~"] = Mqtt::base();
|
||||||
config["dev_cla"] = "temperature";
|
config["dev_cla"] = "temperature";
|
||||||
config["stat_cla"] = "measurement";
|
config["stat_cla"] = "measurement";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user