diff --git a/interface/src/mqtt/MqttSettingsForm.tsx b/interface/src/mqtt/MqttSettingsForm.tsx index 26b0f3779..bb9e5a8d5 100644 --- a/interface/src/mqtt/MqttSettingsForm.tsx +++ b/interface/src/mqtt/MqttSettingsForm.tsx @@ -141,6 +141,16 @@ class MqttSettingsForm extends React.Component { Formatting + + } + label="Nested format (Thermostat & Mixer only)" + /> telegram) { // do we have a mixed circuit if (ismixed == 2) { has_update(telegram->read_value(flowTempHc_, 3)); // is * 10 - has_update(telegram->read_value(status_, 2)); // valve status + has_update(telegram->read_value(status_, 2)); // valve status } has_update(telegram->read_bitvalue(pumpStatus_, 1, 0)); // pump is also in unmixed circuits @@ -164,7 +164,7 @@ void Mixer::process_MMStatusMessage(std::shared_ptr telegram) { // 0x21 is position 2. 0x20 is typically reserved for the WM10 switch module // see https://github.com/proddy/EMS-ESP/issues/270 and https://github.com/proddy/EMS-ESP/issues/386#issuecomment-629610918 - has_update(telegram->read_value(flowTempHc_, 1)); // is * 10 + has_update(telegram->read_value(flowTempHc_, 1)); // is * 10 has_update(telegram->read_bitvalue(pumpStatus_, 3, 2)); // is 0 or 0x64 (100%), check only bit 2 has_update(telegram->read_value(flowSetTemp_, 0)); has_update(telegram->read_value(status_, 4)); // valve status -100 to 100 diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 8054a1834..39abf4bf4 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -39,6 +39,7 @@ uint8_t Mqtt::dallas_format_; uint8_t Mqtt::bool_format_; uint8_t Mqtt::ha_climate_format_; bool Mqtt::ha_enabled_; +bool Mqtt::nested_format_; std::deque Mqtt::mqtt_messages_; std::vector Mqtt::mqtt_subfunctions_; @@ -512,6 +513,7 @@ void Mqtt::on_connect() { ha_climate_format_ = mqttSettings.ha_climate_format; dallas_format_ = mqttSettings.dallas_format; bool_format_ = mqttSettings.bool_format; + nested_format_ = mqttSettings.nested_format; }); // send info topic appended with the version information as JSON @@ -862,19 +864,10 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice snprintf_P(topic, sizeof(topic), PSTR("homeassistant/binary_sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic // how to render boolean - if (bool_format_ == BOOL_FORMAT_ONOFF) { - doc[F("payload_on")] = FJSON("on"); - doc[F("payload_off")] = FJSON("off"); - } else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) { - doc[F("payload_on")] = FJSON("ON"); - doc[F("payload_off")] = FJSON("OFF"); - } else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) { - doc[F("payload_on")] = true; - doc[F("payload_off")] = false; - } else { - doc[F("payload_on")] = 1; - doc[F("payload_off")] = 0; - } + // HA only accepts String values + char result[10]; + doc[F("payload_on")] = Helpers::render_boolean(result, true); + doc[F("payload_off")] = Helpers::render_boolean(result, false); } else { // normal HA sensor, not a boolean one snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic diff --git a/src/mqtt.h b/src/mqtt.h index 079a7dbd1..faee4d9d6 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -156,6 +156,10 @@ class Mqtt { return bool_format_; } + static bool nested_format() { + return nested_format_; + } + static bool ha_enabled() { return ha_enabled_; } @@ -181,18 +185,9 @@ class Mqtt { } static bool is_empty() { - return mqtt_messages_.empty(); + return mqtt_messages_.empty(); } - /* - struct QueuedMqttMessage { - uint16_t id_; - std::shared_ptr content_; - uint8_t retry_count_; - uint16_t packet_id_; - }; - */ - struct QueuedMqttMessage { const uint16_t id_; const std::shared_ptr content_; @@ -270,6 +265,7 @@ class Mqtt { static uint8_t bool_format_; static uint8_t ha_climate_format_; static bool ha_enabled_; + static bool nested_format_; }; } // namespace emsesp