mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -411,10 +411,10 @@ void AnalogSensor::publish_values(const bool force) {
|
||||
|
||||
snprintf(str, sizeof(str), "analogsensor_%d", sensor.gpio());
|
||||
config["uniq_id"] = str;
|
||||
|
||||
|
||||
if (sensor.uom() != DeviceValueUOM::NONE) {
|
||||
config["unit_of_meas"] = EMSdevice::uom_to_string(sensor.uom());
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
|
||||
38
src/mqtt.cpp
38
src/mqtt.cpp
@@ -445,19 +445,17 @@ void Mqtt::start() {
|
||||
}
|
||||
connecting_ = false;
|
||||
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
|
||||
LOG_INFO(F("MQTT disconnected: TCP"));
|
||||
}
|
||||
if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) {
|
||||
LOG_INFO(F("MQTT disconnected: Identifier Rejected"));
|
||||
}
|
||||
if (reason == AsyncMqttClientDisconnectReason::MQTT_SERVER_UNAVAILABLE) {
|
||||
LOG_INFO(F("MQTT disconnected: Server unavailable"));
|
||||
}
|
||||
if (reason == AsyncMqttClientDisconnectReason::MQTT_MALFORMED_CREDENTIALS) {
|
||||
LOG_INFO(F("MQTT disconnected: Malformed credentials"));
|
||||
}
|
||||
if (reason == AsyncMqttClientDisconnectReason::MQTT_NOT_AUTHORIZED) {
|
||||
LOG_INFO(F("MQTT disconnected: Not authorized"));
|
||||
LOG_WARNING(F("MQTT disconnected: TCP"));
|
||||
} else if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) {
|
||||
LOG_WARNING(F("MQTT disconnected: Identifier Rejected"));
|
||||
} else if (reason == AsyncMqttClientDisconnectReason::MQTT_SERVER_UNAVAILABLE) {
|
||||
LOG_WARNING(F("MQTT disconnected: Server unavailable"));
|
||||
} else if (reason == AsyncMqttClientDisconnectReason::MQTT_MALFORMED_CREDENTIALS) {
|
||||
LOG_WARNING(F("MQTT disconnected: Malformed credentials"));
|
||||
} else if (reason == AsyncMqttClientDisconnectReason::MQTT_NOT_AUTHORIZED) {
|
||||
LOG_WARNING(F("MQTT disconnected: Not authorized"));
|
||||
} else {
|
||||
LOG_WARNING(F("MQTT disconnected: code %d"), reason);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -628,11 +626,11 @@ void Mqtt::ha_status() {
|
||||
doc["~"] = mqtt_base_; // default ems-esp
|
||||
// doc["avty_t"] = FJSON("~/status"); // commented out, as it causes errors in HA sometimes
|
||||
// doc["json_attr_t"] = FJSON("~/heartbeat"); // store also as HA attributes
|
||||
doc["stat_t"] = FJSON("~/heartbeat");
|
||||
doc["stat_t"] = FJSON("~/heartbeat");
|
||||
doc["object_id"] = FJSON("ems_esp_status");
|
||||
doc["name"] = FJSON("EMS-ESP status");
|
||||
doc["ic"] = F_(icondevice);
|
||||
doc["val_tpl"] = FJSON("{{value_json['bus_status']}}");
|
||||
doc["name"] = FJSON("EMS-ESP status");
|
||||
doc["ic"] = F_(icondevice);
|
||||
doc["val_tpl"] = FJSON("{{value_json['bus_status']}}");
|
||||
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
dev["name"] = F_(EMSESP); // "EMS-ESP"
|
||||
@@ -1117,11 +1115,11 @@ void Mqtt::publish_ha_sensor_config(uint8_t type,
|
||||
char long_name[130];
|
||||
snprintf(long_name, sizeof(long_name), "%s_%s", device_name, short_name);
|
||||
// snprintf(long_name, sizeof(long_name), "emsesp_%s_%s", device_name, short_name); //wouldn't it be better?
|
||||
doc["object_id"] = long_name;
|
||||
|
||||
doc["object_id"] = long_name;
|
||||
|
||||
// name (friendly name) = <tag> <name>
|
||||
short_name[0] = toupper(short_name[0]); // capitalize first letter
|
||||
doc["name"] = short_name;
|
||||
doc["name"] = short_name;
|
||||
|
||||
// value template
|
||||
// if its nested mqtt format then use the appended entity name, otherwise take the original
|
||||
|
||||
@@ -57,7 +57,6 @@ void Shower::loop() {
|
||||
// first check to see if hot water has been on long enough to be recognized as a Shower/Bath
|
||||
if (!shower_state_ && (time_now - timer_start_) > SHOWER_MIN_DURATION) {
|
||||
set_shower_state(true);
|
||||
publish_shower_data();
|
||||
LOG_DEBUG(F("[Shower] hot water still running, starting shower timer"));
|
||||
}
|
||||
// check if the shower has been on too long
|
||||
@@ -78,7 +77,12 @@ void Shower::loop() {
|
||||
if ((timer_pause_ - timer_start_) > SHOWER_OFFSET_TIME) {
|
||||
duration_ = (timer_pause_ - timer_start_ - SHOWER_OFFSET_TIME);
|
||||
if (duration_ > SHOWER_MIN_DURATION) {
|
||||
publish_shower_data();
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
||||
|
||||
char s[50];
|
||||
snprintf(s, 50, "%d minutes and %d seconds", (uint8_t)(duration_ / 60000), (uint8_t)((duration_ / 1000) % 60));
|
||||
doc["duration"] = s;
|
||||
Mqtt::publish(F("shower_data"), doc.as<JsonObject>());
|
||||
LOG_DEBUG(F("[Shower] finished with duration %d"), duration_);
|
||||
}
|
||||
}
|
||||
@@ -120,34 +124,6 @@ void Shower::shower_alert_start() {
|
||||
}
|
||||
}
|
||||
|
||||
// Publish to the shower_data topic
|
||||
// showing whether the shower timer and alert are enabled or disabled
|
||||
// and the duration of the last shower
|
||||
void Shower::publish_shower_data() const {
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
||||
|
||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||
doc["shower_timer"] = shower_timer_;
|
||||
doc["shower_alert"] = shower_alert_;
|
||||
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||
doc["shower_timer"] = shower_timer_ ? 1 : 0;
|
||||
doc["shower_alert"] = shower_alert_ ? 1 : 0;
|
||||
} else {
|
||||
char result[10];
|
||||
doc["shower_timer"] = Helpers::render_boolean(result, shower_timer_);
|
||||
doc["shower_alert"] = Helpers::render_boolean(result, shower_alert_);
|
||||
}
|
||||
|
||||
// only publish shower duration if there is a value
|
||||
if (duration_ > SHOWER_MIN_DURATION) {
|
||||
char s[50];
|
||||
snprintf(s, 50, "%d minutes and %d seconds", (uint8_t)(duration_ / 60000), (uint8_t)((duration_ / 1000) % 60));
|
||||
doc["duration"] = s;
|
||||
}
|
||||
|
||||
Mqtt::publish(F("shower_data"), doc.as<JsonObject>());
|
||||
}
|
||||
|
||||
// send status of shower to MQTT topic called shower_active - which is determined by the state parameter
|
||||
// and creates the HA config topic if HA enabled
|
||||
// force is used by EMSESP::publish_all_loop()
|
||||
|
||||
20
src/shower.h
20
src/shower.h
@@ -30,25 +30,6 @@ class Shower {
|
||||
|
||||
void set_shower_state(bool state, bool force = false);
|
||||
|
||||
/* unused header
|
||||
*
|
||||
bool shower_alert() const {
|
||||
return shower_alert_;
|
||||
}
|
||||
|
||||
void shower_alert(const bool shower_alert) {
|
||||
shower_alert_ = shower_alert;
|
||||
}
|
||||
|
||||
bool shower_timer() const {
|
||||
return shower_timer_;
|
||||
}
|
||||
|
||||
void shower_timer(const bool shower_timer) {
|
||||
shower_timer_ = shower_timer;
|
||||
}
|
||||
*/
|
||||
|
||||
private:
|
||||
static uuid::log::Logger logger_;
|
||||
|
||||
@@ -56,7 +37,6 @@ class Shower {
|
||||
static constexpr uint32_t SHOWER_MIN_DURATION = 120000; // in ms. 2 minutes, before recognizing its a shower
|
||||
static constexpr uint32_t SHOWER_OFFSET_TIME = 5000; // in ms. 5 seconds grace time, to calibrate actual time under the shower
|
||||
|
||||
void publish_shower_data() const;
|
||||
void shower_alert_start();
|
||||
void shower_alert_stop();
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.4.2b3"
|
||||
#define EMSESP_APP_VERSION "3.4.2b4"
|
||||
|
||||
Reference in New Issue
Block a user