feat: publish MQTT field changes with periodic refresh

Track 89 settings and state fields with partial structure snapshots and a
fixed-capacity map of publication timestamps. Publish changed or expired
values in bounded passes, updating snapshots only after successful queue
acceptance and keeping failed fields eligible for retry.

Refresh fields after reconnecting and affected temperatures after unit or
Equitherm mode changes. Keep the status heartbeat independent, cache DHW
limits for MQTT and API consumers, and clear non-finite retained readings.

Default the forced publication interval to 60 seconds and accept 15 to
3600 seconds in the API and UI. Set Home Assistant state expiration to
twice this interval and refresh discovery when the interval changes.

Remove network connection and dedicated fault/diagnostic availability
publications. Use existing active states and RSSI for HA availability.
This commit is contained in:
Yurii committed 2026-11-29 05:43:52 +03:00
1 parent a629589122
commit d40b7cb85a
8 files changed
+1056 -192

No files matched your search

+3 -3
View File
@@ -1303,7 +1303,7 @@ SettingResult fromJson(JsonVariantConst src, MqttSettings& dst) {
if (src[S_INTERVAL].is<unsigned short>()) {
const auto value = src[S_INTERVAL].as<unsigned short>();
if (value >= 3 && value <= 60) {
if (value >= 15 && value <= 3600) {
result.accepted = true;
if (value != dst.interval) {
dst.interval = value;
@@ -3566,8 +3566,8 @@ JsonVariant toJson(const Variables& src, JsonVariant dst) {
mDhw[S_TARGET_TEMP] = roundf((src.master.dhw.targetTemp == 0 ? 0 : convertTemp(src.master.dhw.targetTemp, UnitSystem::METRIC, settings.system.unitSystem)), 2);
mDhw[S_CURRENT_TEMP] = roundf(convertTemp(src.master.dhw.currentTemp, UnitSystem::METRIC, settings.system.unitSystem), 2);
mDhw[S_RETURN_TEMP] = roundf(convertTemp(src.master.dhw.returnTemp, UnitSystem::METRIC, settings.system.unitSystem), 2);
mDhw[S_MIN_TEMP] = convertTemp(settings.dhw.minTemp, UnitSystem::METRIC, settings.system.unitSystem);
mDhw[S_MAX_TEMP] = convertTemp(settings.dhw.maxTemp, UnitSystem::METRIC, settings.system.unitSystem);
mDhw[S_MIN_TEMP] = convertTemp(src.master.dhw.minTemp, UnitSystem::METRIC, settings.system.unitSystem);
mDhw[S_MAX_TEMP] = convertTemp(src.master.dhw.maxTemp, UnitSystem::METRIC, settings.system.unitSystem);
master[S_NETWORK][S_CONNECTED] = isNetworkConnected();
master[S_NETWORK][S_RSSI] = src.network.rssi;
+5 -7
View File
@@ -1,13 +1,11 @@
#include <app.h>
#include <algorithm>
std::unique_ptr<HA::Discovery> haDiscovery;
bool publishHaEntity(HaEntity entityId, bool remove) {
std::unique_ptr<HA::Component> entity;
const UnitSystem unit = settings.system.unitSystem;
const uint32_t stateExpiration = std::max<uint32_t>(60u, 2u * settings.mqtt.interval);
const uint32_t stateExpiration = 2u * settings.mqtt.interval;
switch (entityId) {
case HA_ENTITY_HEATING_TURBO: {
@@ -498,7 +496,7 @@ bool publishHaEntity(HaEntity entityId, bool remove) {
auto value = std::make_unique<HA::Value>("fault_code", "Fault code");
if (!remove) {
value->stateTopic = "~/state/slave/fault/code";
value->availabilityTopic = "~/state/slave/fault/available";
value->availabilityTopic = "~/state/slave/fault/active";
value->category = HA::Category::DIAGNOSTIC;
value->icon = "mdi:cog-box";
value->valueTemplate = "{{ '%02d (0x%02X)' | format(value | int, value | int) }}";
@@ -515,7 +513,7 @@ bool publishHaEntity(HaEntity entityId, bool remove) {
auto value = std::make_unique<HA::Value>("diagnostic_code", "Diagnostic code");
if (!remove) {
value->stateTopic = "~/state/slave/diag/code";
value->availabilityTopic = "~/state/slave/diag/available";
value->availabilityTopic = "~/state/slave/diag/active";
value->category = HA::Category::DIAGNOSTIC;
value->icon = "mdi:information-box";
value->valueTemplate = "{{ '%02d (0x%02X)' | format(value | int, value | int) }}";
@@ -532,8 +530,8 @@ bool publishHaEntity(HaEntity entityId, bool remove) {
auto gauge = std::make_unique<HA::Gauge>("rssi", "RSSI");
if (!remove) {
gauge->stateTopic = "~/state/master/network/rssi";
gauge->availabilityTopic = "~/state/master/network/connection_type";
gauge->availabilityTemplate = "{{ 'online' if value == 'wifi' else 'offline' }}";
gauge->availabilityTopic = gauge->stateTopic;
gauge->availabilityTemplate = "{{ 'online' if value | int(0) < 0 else 'offline' }}";
gauge->category = HA::Category::DIAGNOSTIC;
gauge->deviceClass = "signal_strength";
gauge->icon = "mdi:signal";
+924 -180
View File
File diff suppressed because it is too large. Load diff
+2
View File
@@ -342,6 +342,8 @@ static void updateMasterState() {
settings.dhw.enabled &&
!vars.master.dhw.overheat;
vars.master.dhw.targetTemp = settings.dhw.target;
vars.master.dhw.minTemp = settings.dhw.minTemp;
vars.master.dhw.maxTemp = settings.dhw.maxTemp;
// CH2 settings
vars.master.ch2.enabled =