mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
@@ -667,9 +667,10 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
LOG_DEBUG("Recreating HA config for analog sensor GPIO %02d", sensor.gpio());
|
LOG_DEBUG("Recreating HA config for analog sensor GPIO %02d", sensor.gpio());
|
||||||
|
|
||||||
JsonDocument config;
|
JsonDocument config;
|
||||||
|
config["~"] = Mqtt::base();
|
||||||
|
|
||||||
char stat_t[50];
|
char stat_t[50];
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/%s_data", Mqtt::base().c_str(), F_(analogsensor)); // use base path
|
snprintf(stat_t, sizeof(stat_t), "~/%s_data", F_(analogsensor)); // use base path
|
||||||
config["stat_t"] = stat_t;
|
config["stat_t"] = stat_t;
|
||||||
|
|
||||||
char val_obj[50];
|
char val_obj[50];
|
||||||
@@ -699,6 +700,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
snprintf(uniq_s, sizeof(uniq_s), "%s_%02d", F_(analogsensor), sensor.gpio());
|
snprintf(uniq_s, sizeof(uniq_s), "%s_%02d", F_(analogsensor), sensor.gpio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config["~"] = Mqtt::base();
|
||||||
config["uniq_id"] = uniq_s;
|
config["uniq_id"] = uniq_s;
|
||||||
|
|
||||||
char name[50];
|
char name[50];
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ void Shower::create_ha_discovery() {
|
|||||||
char str[70];
|
char str[70];
|
||||||
char stat_t[50];
|
char stat_t[50];
|
||||||
|
|
||||||
|
doc["~"] = Mqtt::base();
|
||||||
|
|
||||||
// shower active
|
// shower active
|
||||||
doc["name"] = "Shower Active";
|
doc["name"] = "Shower Active";
|
||||||
|
|
||||||
@@ -207,9 +209,7 @@ 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";
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/shower_active", Mqtt::base().c_str());
|
|
||||||
doc["stat_t"] = stat_t;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -225,10 +225,7 @@ 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",
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/shower_data", Mqtt::base().c_str());
|
|
||||||
doc["stat_t"] = stat_t;
|
|
||||||
|
|
||||||
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
|
||||||
@@ -248,29 +245,6 @@ void Shower::create_ha_discovery() {
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
//
|
|
||||||
// shower timestamp
|
|
||||||
//
|
|
||||||
/* commented out as the publish of timestamp
|
|
||||||
doc.clear();
|
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "%s_shower_timestamp", Mqtt::basename().c_str());
|
|
||||||
|
|
||||||
doc["uniq_id"] = str;
|
|
||||||
|
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/shower_data", Mqtt::base().c_str());
|
|
||||||
doc["stat_t"] = stat_t;
|
|
||||||
|
|
||||||
doc["name"] = "Shower Timestamp";
|
|
||||||
doc["val_tpl"] = "{{value_json.timestamp if value_json.timestamp is defined else 0}}";
|
|
||||||
// doc["ent_cat"] = "diagnostic";
|
|
||||||
|
|
||||||
Mqtt::add_ha_sections_to_doc("shower", stat_t, doc, false, "value_json.timestamp is defined");
|
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/shower_timestamp/config", Mqtt::basename().c_str());
|
|
||||||
Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -507,11 +507,12 @@ 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["dev_cla"] = "temperature";
|
config["dev_cla"] = "temperature";
|
||||||
config["stat_cla"] = "measurement";
|
config["stat_cla"] = "measurement";
|
||||||
|
|
||||||
char stat_t[50];
|
char stat_t[50];
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/%s_data", Mqtt::base().c_str(), F_(temperaturesensor)); // use base path
|
snprintf(stat_t, sizeof(stat_t), "~/%s_data", F_(temperaturesensor)); // use base path
|
||||||
config["stat_t"] = stat_t;
|
config["stat_t"] = stat_t;
|
||||||
|
|
||||||
config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
||||||
|
|||||||
@@ -411,8 +411,10 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
// create HA config
|
// create HA config
|
||||||
if (Mqtt::ha_enabled() && !ha_registered_) {
|
if (Mqtt::ha_enabled() && !ha_registered_) {
|
||||||
JsonDocument config;
|
JsonDocument config;
|
||||||
|
config["~"] = Mqtt::base();
|
||||||
|
|
||||||
char stat_t[50];
|
char stat_t[50];
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/%s_data", Mqtt::base().c_str(), F_(custom));
|
snprintf(stat_t, sizeof(stat_t), "~/%s_data", F_(custom));
|
||||||
config["stat_t"] = stat_t;
|
config["stat_t"] = stat_t;
|
||||||
|
|
||||||
char val_obj[50];
|
char val_obj[50];
|
||||||
@@ -445,7 +447,7 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
snprintf(topic, sizeof(topic), "sensor/%s/%s_%s/config", Mqtt::basename().c_str(), F_(custom), entityItem.name.c_str());
|
snprintf(topic, sizeof(topic), "sensor/%s/%s_%s/config", Mqtt::basename().c_str(), F_(custom), entityItem.name.c_str());
|
||||||
}
|
}
|
||||||
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(command_topic, sizeof(command_topic), "%s/%s/%s", Mqtt::base().c_str(), F_(custom), entityItem.name.c_str());
|
snprintf(command_topic, sizeof(command_topic), "~/%s/%s", F_(custom), entityItem.name.c_str());
|
||||||
config["cmd_t"] = command_topic;
|
config["cmd_t"] = command_topic;
|
||||||
} else {
|
} else {
|
||||||
if (entityItem.value_type == DeviceValueType::BOOL) {
|
if (entityItem.value_type == DeviceValueType::BOOL) {
|
||||||
|
|||||||
@@ -263,9 +263,12 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
|
|
||||||
// create HA config
|
// create HA config
|
||||||
if (Mqtt::ha_enabled() && !ha_registered_) {
|
if (Mqtt::ha_enabled() && !ha_registered_) {
|
||||||
|
|
||||||
JsonDocument config;
|
JsonDocument config;
|
||||||
|
config["~"] = Mqtt::base();
|
||||||
|
|
||||||
char stat_t[50];
|
char stat_t[50];
|
||||||
snprintf(stat_t, sizeof(stat_t), "%s/%s_data", Mqtt::base().c_str(), F_(scheduler));
|
snprintf(stat_t, sizeof(stat_t), "~/%s_data", F_(scheduler));
|
||||||
config["stat_t"] = stat_t;
|
config["stat_t"] = stat_t;
|
||||||
|
|
||||||
char val_obj[50];
|
char val_obj[50];
|
||||||
@@ -290,7 +293,7 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "switch/%s/%s_%s/config", Mqtt::basename().c_str(), F_(scheduler), scheduleItem.name.c_str());
|
snprintf(topic, sizeof(topic), "switch/%s/%s_%s/config", Mqtt::basename().c_str(), F_(scheduler), scheduleItem.name.c_str());
|
||||||
snprintf(command_topic, sizeof(command_topic), "%s/%s/%s", Mqtt::base().c_str(), F_(scheduler), scheduleItem.name.c_str());
|
snprintf(command_topic, sizeof(command_topic), "~/%s/%s", F_(scheduler), scheduleItem.name.c_str());
|
||||||
config["cmd_t"] = command_topic;
|
config["cmd_t"] = command_topic;
|
||||||
|
|
||||||
Mqtt::add_ha_bool(config.as<JsonObject>());
|
Mqtt::add_ha_bool(config.as<JsonObject>());
|
||||||
|
|||||||
Reference in New Issue
Block a user