ha optimistic, cs6800 changes, custom entity hide

This commit is contained in:
MichaelDvP
2025-05-10 13:38:19 +02:00
parent dc1094b6ba
commit b3320c3e48
26 changed files with 320 additions and 166 deletions

View File

@@ -682,6 +682,9 @@ void AnalogSensor::publish_values(const bool force) {
Mqtt::add_ha_sections_to_doc("analog", stat_t, config, !is_ha_device_created, val_cond);
if (Mqtt::ha_optimistic()) {
config["optimistic"] = true;
}
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
}
}

View File

@@ -185,6 +185,10 @@
#define EMSESP_DEFAULT_HA_ENABLED false
#endif
#ifndef EMSESP_DEFAULT_HA_OPTIMISTIC
#define EMSESP_DEFAULT_HA_OPTIMISTIC false
#endif
#ifndef EMSESP_DEFAULT_PUBLISH_TIME
#define EMSESP_DEFAULT_PUBLISH_TIME 10
#endif

View File

@@ -24,7 +24,7 @@
*/
// Boilers - 0x08
{ 8, DeviceType::BOILER, "CS*800i, Logatherm WLW*", DeviceFlags::EMS_DEVICE_FLAG_HEATPUMP},
{ 8, DeviceType::BOILER, "CS5800i, CS6800i, WLW176i, WLW186i", DeviceFlags::EMS_DEVICE_FLAG_CS6800},
{ 12, DeviceType::BOILER, "C1200W", DeviceFlags::EMS_DEVICE_FLAG_NONE},
{ 64, DeviceType::BOILER, "BK13/BK15, Smartline, GB1*2", DeviceFlags::EMS_DEVICE_FLAG_NONE},
{ 72, DeviceType::BOILER, "Logano GB1*5, Logamatic MC10", DeviceFlags::EMS_DEVICE_FLAG_EMS},

View File

@@ -197,6 +197,19 @@ class EMSdevice {
}
}
void has_enumupdate(std::shared_ptr<const Telegram> telegram,
uint8_t & value,
const uint8_t index,
const std::vector<uint8_t> & maskIn,
const std::vector<uint8_t> & maskOut) {
uint8_t val = value < maskIn.size() ? maskIn[value] : EMS_VALUE_UINT8_NOTSET;
if (telegram->read_value(val, index)) {
value = val < maskOut.size() ? maskOut[val] : EMS_VALUE_UINT8_NOTSET;
has_update_ = true;
publish_value((void *)&value);
}
}
template <typename Value>
void has_update(std::shared_ptr<const Telegram> telegram, Value & value, const uint8_t index, uint8_t s = 0) {
if (telegram->read_value(value, index, s)) {
@@ -434,9 +447,10 @@ class EMSdevice {
static constexpr uint8_t EMS_DEVICE_FLAG_EMS = 1;
static constexpr uint8_t EMS_DEVICE_FLAG_EMSPLUS = 2;
static constexpr uint8_t EMS_DEVICE_FLAG_HT3 = 3;
static constexpr uint8_t EMS_DEVICE_FLAG_HEATPUMP = 4;
static constexpr uint8_t EMS_DEVICE_FLAG_HYBRID = 5;
static constexpr uint8_t EMS_DEVICE_FLAG_HIU = 6;
static constexpr uint8_t EMS_DEVICE_FLAG_HYBRID = 4;
static constexpr uint8_t EMS_DEVICE_FLAG_HIU = 5;
static constexpr uint8_t EMS_DEVICE_FLAG_HEATPUMP = 8; // use bit for subtypes
static constexpr uint8_t EMS_DEVICE_FLAG_CS6800 = 9; // subtype of heatpump
// Solar Module
static constexpr uint8_t EMS_DEVICE_FLAG_SM10 = 1;

View File

@@ -627,10 +627,18 @@ bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * co
}
}
value_ui = 0;
return false;
}
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * const ** strs, const std::vector<uint8_t> & mask) {
uint8_t v = value_ui;
if (!value2enum(value, v, strs) || v >= mask.size()) {
return false;
}
value_ui = mask[v];
return true;
}
// finds the string (value) of a list vector (strs)
// returns true if found, and sets the value_ui to the index, else false
// also allow true/false for on/off
@@ -658,6 +666,15 @@ bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * co
return false;
}
bool Helpers::value2enum(const char * value, uint8_t & value_ui, const char * const * strs, const std::vector<uint8_t> & mask) {
uint8_t v = value_ui;
if (!value2enum(value, v, strs) || v >= mask.size()) {
return false;
}
value_ui = mask[v];
return true;
}
// https://stackoverflow.com/questions/313970/how-to-convert-stdstring-to-lower-case
std::string Helpers::toLower(std::string const & s) {
std::string lc = s;

View File

@@ -72,7 +72,9 @@ class Helpers {
static bool value2bool(const char * value, bool & value_b);
static bool value2string(const char * value, std::string & value_s);
static bool value2enum(const char * value, uint8_t & value_ui, const char * const ** strs);
static bool value2enum(const char * value, uint8_t & value_ui, const char * const ** strs, const std::vector<uint8_t> & mask);
static bool value2enum(const char * value, uint8_t & value_ui, const char * const * strs);
static bool value2enum(const char * value, uint8_t & value_ui, const char * const * strs, const std::vector<uint8_t> & mask);
static bool value2temperature(const char * value, float & value_f, bool relative = false);
static bool value2temperature(const char * value, int & value_i, const bool relative = false, const int min = -2147483648, const int max = 2147483647);

View File

@@ -298,6 +298,8 @@ MAKE_ENUM(enum_comfort2, FL_(eco), FL_(high_comfort))
MAKE_ENUM(enum_flow, FL_(off), FL_(flow), FL_(bufferedflow), FL_(buffer), FL_(layeredbuffer))
MAKE_ENUM(enum_reset, FL_(dash), FL_(maintenance), FL_(error), FL_(history), FL_(message))
MAKE_ENUM(enum_maxHeat, FL_(0kW), FL_(2kW), FL_(3kW), FL_(4kW), FL_(6kW), FL_(9kW))
MAKE_ENUM(enum_maxHeat1, FL_(0kW), FL_(3kW), FL_(6kW), FL_(9kW))
MAKE_ENUM(enum_maxHeat2, FL_(3kW), FL_(6kW), FL_(9kW))
MAKE_ENUM(enum_pumpMode, FL_(proportional), FL_(deltaP1), FL_(deltaP2), FL_(deltaP3), FL_(deltaP4))
MAKE_ENUM(enum_pumpCharacter, FL_(proportional), FL_(pressure1), FL_(pressure2), FL_(pressure3), FL_(pressure4), FL_(pressure5), FL_(pressure6))
MAKE_ENUM(enum_hpPumpMode, FL_(auto), FL_(continuous))

View File

@@ -40,6 +40,7 @@ uint32_t Mqtt::publish_time_heartbeat_;
bool Mqtt::mqtt_enabled_;
uint8_t Mqtt::entity_format_;
bool Mqtt::ha_enabled_;
bool Mqtt::ha_optimistic_;
uint8_t Mqtt::nested_format_;
std::string Mqtt::discovery_prefix_;
uint8_t Mqtt::discovery_type_;
@@ -340,6 +341,7 @@ void Mqtt::load_settings() {
mqtt_retain_ = mqttSettings.mqtt_retain;
mqtt_enabled_ = mqttSettings.enabled;
ha_enabled_ = mqttSettings.ha_enabled;
ha_optimistic_ = mqttSettings.ha_optimistic;
nested_format_ = mqttSettings.nested_format;
publish_single_ = mqttSettings.publish_single;
publish_single2cmd_ = mqttSettings.publish_single2cmd;
@@ -1114,6 +1116,9 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc["dev"] = dev_json;
if (ha_optimistic_) {
doc["optimistic"] = true;
}
return queue_ha(topic, doc.as<JsonObject>());
}
@@ -1343,6 +1348,9 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp,
// device name must be different to the entity name, take the ids value we just created
add_ha_sections_to_doc("thermostat", topic_t, doc, false, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond);
if (ha_optimistic_) {
doc["optimistic"] = true;
}
return queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
}

View File

@@ -206,6 +206,14 @@ class Mqtt {
ha_enabled_ = ha_enabled;
}
static bool ha_optimistic() {
return ha_optimistic_;
}
static void ha_optimistic(bool ha_optimistic) {
ha_optimistic_ = ha_optimistic;
}
static bool ha_climate_reset() {
return ha_climate_reset_;
}
@@ -309,6 +317,7 @@ class Mqtt {
static uint32_t publish_time_heartbeat_;
static bool mqtt_enabled_;
static bool ha_enabled_;
static bool ha_optimistic_;
static uint8_t nested_format_;
static uint8_t entity_format_;
static std::string discovery_prefix_;