Merge branch 'dev2' of https://github.com/proddy/EMS-ESP32 into dev2

This commit is contained in:
MichaelDvP
2023-11-07 07:15:43 +01:00
5 changed files with 43 additions and 43 deletions

View File

@@ -5,6 +5,7 @@
## **IMPORTANT! BREAKING CHANGES** ## **IMPORTANT! BREAKING CHANGES**
- move dhw functions from mixer/solar to water - move dhw functions from mixer/solar to water
Writeable Text entities have moved from type `sensor` to `text` in Home Assistant to make them also editable within an HA dashboard. Examples are `datetime`, `holidays`, `switchtime`, `vacations`, `maintenancedate`...). You will need to manually remove any old discovery topics from your MQTT broker using an application like MQTT Explorer.
## Added ## Added
@@ -13,7 +14,8 @@
- names for BC400, GB192i.2, read temperatures for low loss header and heatblock [#1317](https://github.com/emsesp/EMS-ESP32/discussions/1317) - names for BC400, GB192i.2, read temperatures for low loss header and heatblock [#1317](https://github.com/emsesp/EMS-ESP32/discussions/1317)
- option for `forceheatingoff` [#1262](https://github.com/emsesp/EMS-ESP32/issues/1262) - option for `forceheatingoff` [#1262](https://github.com/emsesp/EMS-ESP32/issues/1262)
- remote thermostat emulation RC100H for RC3xx [#1278](https://github.com/emsesp/EMS-ESP32/discussions/1278) - remote thermostat emulation RC100H for RC3xx [#1278](https://github.com/emsesp/EMS-ESP32/discussions/1278)
- publish time for shower - shower_data MQTT payload contains the timestamp [#1329](https://github.com/emsesp/EMS-ESP32/issues/1329)
- HA discovery for writeable text entities [#1337](https://github.com/emsesp/EMS-ESP32/pull/1377)
- autodetect board_profile, store in nvs, add telnet command option, add E32V2 - autodetect board_profile, store in nvs, add telnet command option, add E32V2
- heatpump high res energy counters [#1348, #1349. #1350](https://github.com/emsesp/EMS-ESP32/issues/1348) - heatpump high res energy counters [#1348, #1349. #1350](https://github.com/emsesp/EMS-ESP32/issues/1348)
- optional bssid in network settings - optional bssid in network settings

View File

@@ -24,7 +24,6 @@ REGISTER_FACTORY(Alert, EMSdevice::DeviceType::ALERT);
Alert::Alert(uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand) Alert::Alert(uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand)
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) { : EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
// EM10, device-id 0x12, listens to error messages, measures voltage input and send 0x1A to the boiler. // EM10, device-id 0x12, listens to error messages, measures voltage input and send 0x1A to the boiler.
// values already shown in boiler // values already shown in boiler
// see https://github.com/emsesp/EMS-ESP32/issues/575 // see https://github.com/emsesp/EMS-ESP32/issues/575
@@ -32,7 +31,6 @@ Alert::Alert(uint8_t device_type, uint8_t device_id, uint8_t product_id, const c
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &setFlowTemp_, DeviceValueType::UINT, FL_(setFlowTemp), DeviceValueUOM::DEGREES); register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &setFlowTemp_, DeviceValueType::UINT, FL_(setFlowTemp), DeviceValueUOM::DEGREES);
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &setBurnPow_, DeviceValueType::UINT, FL_(setBurnPow), DeviceValueUOM::PERCENT); register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &setBurnPow_, DeviceValueType::UINT, FL_(setBurnPow), DeviceValueUOM::PERCENT);
} }
// UBASetPoint 0x1A // UBASetPoint 0x1A
void Alert::process_UBASetPoints(std::shared_ptr<const Telegram> telegram) { void Alert::process_UBASetPoints(std::shared_ptr<const Telegram> telegram) {

View File

@@ -769,7 +769,8 @@ bool Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const
// determine if we're creating the command topics which we use special HA configs // determine if we're creating the command topics which we use special HA configs
// unless the entity has been marked as read-only and so it'll default to using the sensor/ type // unless the entity has been marked as read-only and so it'll default to using the sensor/ type
bool has_cmd = dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY); // or we're dealing with Energy sensors that must have "diagnostic" as an entity category (e.g. negheat & nrgww)
bool has_cmd = dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY) && (dv.uom != DeviceValueUOM::KWH);
return publish_ha_sensor_config(dv.type, return publish_ha_sensor_config(dv.type,
dv.tag, dv.tag,
@@ -862,7 +863,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
char config_topic[70]; char config_topic[70];
snprintf(config_topic, sizeof(config_topic), "%s/%s_%s/config", mqtt_basename_.c_str(), device_name, entity_with_tag); snprintf(config_topic, sizeof(config_topic), "%s/%s_%s/config", mqtt_basename_.c_str(), device_name, entity_with_tag);
bool set_ha_classes = false; // set to true if we want to set the state class and device class bool readonly_sensors = true;
// create the topic // create the topic
// depending on the type and whether the device entity is writable (a command) // depending on the type and whether the device entity is writable (a command)
@@ -875,42 +876,41 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
case DeviceValueType::UINT: case DeviceValueType::UINT:
case DeviceValueType::SHORT: case DeviceValueType::SHORT:
case DeviceValueType::USHORT: case DeviceValueType::USHORT:
if (discovery_type() == discoveryType::HOMEASSISTANT) { case DeviceValueType::ULONG:
// number - https://www.home-assistant.io/integrations/number.mqtt // number - https://www.home-assistant.io/integrations/number.mqtt
snprintf(topic, sizeof(topic), "number/%s", config_topic);
} else {
// Domoticz does not support number, use sensor // Domoticz does not support number, use sensor
if (discovery_type() == discoveryType::HOMEASSISTANT) {
snprintf(topic, sizeof(topic), "number/%s", config_topic);
readonly_sensors = false;
} else {
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
} }
break; break;
case DeviceValueType::BOOL: case DeviceValueType::BOOL:
// switch - https://www.home-assistant.io/integrations/switch.mqtt // switch - https://www.home-assistant.io/integrations/switch.mqtt
snprintf(topic, sizeof(topic), "switch/%s", config_topic); snprintf(topic, sizeof(topic), "switch/%s", config_topic);
readonly_sensors = false;
break; break;
case DeviceValueType::ENUM: case DeviceValueType::ENUM:
// select - https://www.home-assistant.io/integrations/select.mqtt // select - https://www.home-assistant.io/integrations/select.mqtt
snprintf(topic, sizeof(topic), "select/%s", config_topic); snprintf(topic, sizeof(topic), "select/%s", config_topic);
break; readonly_sensors = false;
case DeviceValueType::ULONG:
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
set_ha_classes = true;
break; break;
case DeviceValueType::STRING: case DeviceValueType::STRING:
// text - https://www.home-assistant.io/integrations/text.mqtt
snprintf(topic, sizeof(topic), "text/%s", config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime snprintf(topic, sizeof(topic), "text/%s", config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime
readonly_sensors = false;
break; break;
default: default:
// plain old sensor // plain old sensor, and make read-only
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
break; break;
} }
} else {
set_ha_classes = true; // these are Read only sensors. We can set the device class and state class
// plain old read only device entity
if (type == DeviceValueType::BOOL) {
snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans)
} else {
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
} }
// For read-only sensors there are either sensor or binary_sensor
// for both we also set the device class and state class
if (readonly_sensors) {
snprintf(topic, sizeof(topic), (type == DeviceValueType::BOOL) ? "binary_sensor/%s" : "sensor/%s", config_topic); // binary sensor (for booleans)
} }
// if we're asking to remove this topic, send an empty payload and exit // if we're asking to remove this topic, send an empty payload and exit
@@ -926,13 +926,15 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc["obj_id"] = uniq_id; // same as unique_id doc["obj_id"] = uniq_id; // same as unique_id
const char * ic_ha = "ic"; // icon - only set this if there is no device class const char * ic_ha = "ic"; // icon - only set this if there is no device class
const char * sc_ha = "stat_cla"; // state class
const char * uom_ha = "unit_of_meas"; // unit of measure const char * uom_ha = "unit_of_meas"; // unit of measure
char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet
// we add the command topic parameter for commands // we add the command topic parameter for commands
if (has_cmd) { if (has_cmd) {
// add category
doc["ent_cat"] = "config"; // for writeable entities, like switch, number, text, select
char command_topic[MQTT_TOPIC_MAX_SIZE]; char command_topic[MQTT_TOPIC_MAX_SIZE];
// add command topic // add command topic
if (tag >= DeviceValueTAG::TAG_HC1) { if (tag >= DeviceValueTAG::TAG_HC1) {
@@ -1054,12 +1056,16 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc[uom_ha] = EMSdevice::uom_to_string(uom); // default doc[uom_ha] = EMSdevice::uom_to_string(uom); // default
} }
} }
doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}"; doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
// this next section is adding the state class, device class and sometimes the icon // Add the state class, device class and sometimes the icon. Used only for read-only sensors Sensor and Binary Sensor
// used for Sensor and Binary Sensor Entities in HA if (readonly_sensors) {
if (set_ha_classes) { // first set the catagory
doc["ent_cat"] = "diagnostic";
const char * dc_ha = "dev_cla"; // device class const char * dc_ha = "dev_cla"; // device class
const char * sc_ha = "stat_cla"; // state class
switch (uom) { switch (uom) {
case DeviceValueUOM::DEGREES: case DeviceValueUOM::DEGREES:
@@ -1095,11 +1101,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
} else { } else {
doc[sc_ha] = F_(measurement); doc[sc_ha] = F_(measurement);
} }
doc[dc_ha] = "energy"; // no icon needed doc[dc_ha] = "energy";
break; break;
case DeviceValueUOM::KWH: case DeviceValueUOM::KWH:
doc[sc_ha] = F_(total_increasing); doc[sc_ha] = F_(total_increasing);
doc[dc_ha] = "energy"; // no icon needed doc[dc_ha] = "energy";
break; break;
case DeviceValueUOM::UA: case DeviceValueUOM::UA:
doc[ic_ha] = F_(iconua); doc[ic_ha] = F_(iconua);
@@ -1143,15 +1149,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
} }
} }
// add category "diagnostic" for system entities doc["dev"] = dev_json; // add the dev json object to the end
// config for writeable entities, like switches. diagnostic for read only sensors. add_avty_to_doc(stat_t, doc.as<JsonObject>(), val_cond); // add "availability" section
doc["ent_cat"] = (has_cmd && !set_ha_classes) ? "config" : "diagnostic";
// add the dev json object to the end
doc["dev"] = dev_json;
// add "availability" section
add_avty_to_doc(stat_t, doc.as<JsonObject>(), val_cond);
return queue_ha(topic, doc.as<JsonObject>()); return queue_ha(topic, doc.as<JsonObject>());
} }
@@ -1325,5 +1324,4 @@ void Mqtt::add_avty_to_doc(const char * state_t, const JsonObject & doc, const c
doc["avty_mode"] = "all"; doc["avty_mode"] = "all";
} }
} // namespace emsesp } // namespace emsesp

View File

@@ -36,7 +36,9 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) { switch (event) {
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
EMSESP::logger().warning("WiFi disconnected. Reason: %s (%d)", disconnectReason(info.wifi_sta_disconnected.reason), info.wifi_sta_disconnected.reason); // IDF 4.0 EMSESP::logger().warning("WiFi disconnected. Reason: %s (%d)",
disconnectReason(info.wifi_sta_disconnected.reason),
info.wifi_sta_disconnected.reason); // IDF 4.0
EMSESP::system_.has_ipv6(false); EMSESP::system_.has_ipv6(false);
break; break;