mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
@@ -137,7 +137,7 @@ void MqttSettingsService::configureMqtt() {
|
|||||||
_mqttClient.setClientId(retainCstr(_state.clientId.c_str(), &_retainedClientId));
|
_mqttClient.setClientId(retainCstr(_state.clientId.c_str(), &_retainedClientId));
|
||||||
_mqttClient.setKeepAlive(_state.keepAlive);
|
_mqttClient.setKeepAlive(_state.keepAlive);
|
||||||
_mqttClient.setCleanSession(_state.cleanSession);
|
_mqttClient.setCleanSession(_state.cleanSession);
|
||||||
_mqttClient.setMaxTopicLength(_state.maxTopicLength);
|
_mqttClient.setMaxTopicLength(FACTORY_MQTT_MAX_TOPIC_LENGTH); // hardcode. We don't take this from the settings anymore.
|
||||||
_mqttClient.connect();
|
_mqttClient.connect();
|
||||||
// } else {
|
// } else {
|
||||||
// emsesp::EMSESP::logger().info("Error configuring Mqtt client");
|
// emsesp::EMSESP::logger().info("Error configuring Mqtt client");
|
||||||
@@ -188,8 +188,6 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
|
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
|
||||||
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
|
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
|
||||||
|
|
||||||
newSettings.maxTopicLength = FACTORY_MQTT_MAX_TOPIC_LENGTH; // hardcode. We don't take this from the settings anymore.
|
|
||||||
|
|
||||||
newSettings.publish_time_boiler = root["publish_time_boiler"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_boiler = root["publish_time_boiler"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
newSettings.publish_time_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
newSettings.publish_time_solar = root["publish_time_solar"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_solar = root["publish_time_solar"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ class MqttSettings {
|
|||||||
// connection settings
|
// connection settings
|
||||||
uint16_t keepAlive;
|
uint16_t keepAlive;
|
||||||
bool cleanSession;
|
bool cleanSession;
|
||||||
uint16_t maxTopicLength;
|
|
||||||
|
|
||||||
// proddy EMS-ESP specific
|
// proddy EMS-ESP specific
|
||||||
String base;
|
String base;
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
}
|
}
|
||||||
config["val_tpl"] = str;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "%s_analog_sensor_%s", Mqtt::basename().c_str(), sensor.name().c_str());
|
snprintf(str, sizeof(str), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
|
||||||
config["object_id"] = str;
|
config["object_id"] = str;
|
||||||
config["uniq_id"] = str; // same as object_id
|
config["uniq_id"] = str; // same as object_id
|
||||||
|
|
||||||
|
|||||||
@@ -284,12 +284,12 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
|||||||
std::string ro = EMSESP::system_.readonly_mode() ? "[readonly] " : "";
|
std::string ro = EMSESP::system_.readonly_mode() ? "[readonly] " : "";
|
||||||
|
|
||||||
if ((value == nullptr) || (strlen(value) == 0)) {
|
if ((value == nullptr) || (strlen(value) == 0)) {
|
||||||
LOG_INFO(("%sCalling command %s"), ro.c_str(), info_s);
|
LOG_DEBUG(("%sCalling command %s"), ro.c_str(), info_s);
|
||||||
} else {
|
} else {
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
LOG_INFO(("%sCalling command %s with value %s and id %d"), ro.c_str(), info_s, value, id);
|
LOG_DEBUG(("%sCalling command %s with value %s and id %d"), ro.c_str(), info_s, value, id);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(("%sCalling command %s with value %s"), ro.c_str(), info_s, value);
|
LOG_DEBUG(("%sCalling command %s with value %s"), ro.c_str(), info_s, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -518,7 +518,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
}
|
}
|
||||||
config["val_tpl"] = str;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "%s_temperature_sensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
snprintf(str, sizeof(str), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
||||||
config["object_id"] = str;
|
config["object_id"] = str;
|
||||||
config["uniq_id"] = str; // same as object_id
|
config["uniq_id"] = str; // same as object_id
|
||||||
|
|
||||||
|
|||||||
@@ -593,8 +593,10 @@ void Mqtt::on_connect() {
|
|||||||
void Mqtt::ha_status() {
|
void Mqtt::ha_status() {
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
|
||||||
|
|
||||||
doc["uniq_id"] = "ems-esp-system";
|
char uniq[70];
|
||||||
doc["object_id"] = "ems_esp_status";
|
snprintf(uniq, sizeof(uniq), "%s_status", mqtt_basename_.c_str());
|
||||||
|
doc["uniq_id"] = uniq;
|
||||||
|
doc["object_id"] = uniq;
|
||||||
doc["~"] = mqtt_base_; // default ems-esp
|
doc["~"] = mqtt_base_; // default ems-esp
|
||||||
// doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes
|
// doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes
|
||||||
// doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes
|
// doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes
|
||||||
@@ -614,7 +616,7 @@ void Mqtt::ha_status() {
|
|||||||
ids.add("ems-esp");
|
ids.add("ems-esp");
|
||||||
|
|
||||||
char topic[MQTT_TOPIC_MAX_SIZE];
|
char topic[MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s/system/config", mqtt_basename_.c_str());
|
snprintf(topic, sizeof(topic), "binary_sensor/%s/status/config", mqtt_basename_.c_str());
|
||||||
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
||||||
|
|
||||||
// create the sensors - must match the MQTT payload keys
|
// create the sensors - must match the MQTT payload keys
|
||||||
|
|||||||
Reference in New Issue
Block a user