From e3a1aa78a9b6c9219db63a602efa140cf564cd98 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 2 Oct 2025 13:11:28 +0200 Subject: [PATCH] Added tariff peaks and total month to MQTT JSON payload (#1026) * Added tariff peaks to MQTT JSON payload * Bugfix after testing --- lib/JsonMqttHandler/src/JsonMqttHandler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/JsonMqttHandler/src/JsonMqttHandler.cpp b/lib/JsonMqttHandler/src/JsonMqttHandler.cpp index 1ba9c96b..7154856b 100644 --- a/lib/JsonMqttHandler/src/JsonMqttHandler.cpp +++ b/lib/JsonMqttHandler/src/JsonMqttHandler.cpp @@ -79,14 +79,24 @@ uint16_t JsonMqttHandler::appendJsonFooter(EnergyAccounting* ea, uint16_t pos) { } else { memset(pf, 0, 4); } + + String peaks = ""; + uint8_t peakCount = ea->getConfig()->hours; + if(peakCount > 5) peakCount = 5; + for(uint8_t i = 1; i <= peakCount; i++) { + if(!peaks.isEmpty()) peaks += ","; + peaks += String(ea->getPeak(i).value / 100.0, 2); + } - return snprintf_P(json+pos, BufferSize-pos, PSTR("%s\"%sh\":%.2f,\"%sd\":%.1f,\"%st\":%d,\"%sx\":%.2f,\"%she\":%.2f,\"%sde\":%.1f%s"), + return snprintf_P(json+pos, BufferSize-pos, PSTR("%s\"%sh\":%.3f,\"%sd\":%.2f,\"%sm\":%.1f,\"%st\":%d,\"%sx\":%.2f,\"%she\":%.3f,\"%sde\":%.2f,\"%sme\":%.1f,\"peaks\":[%s]%s"), strlen(pf) == 0 ? "},\"realtime\":{" : ",", pf, ea->getUseThisHour(), pf, ea->getUseToday(), pf, + ea->getUseThisMonth(), + pf, ea->getCurrentThreshold(), pf, ea->getMonthMax(), @@ -94,6 +104,9 @@ uint16_t JsonMqttHandler::appendJsonFooter(EnergyAccounting* ea, uint16_t pos) { ea->getProducedThisHour(), pf, ea->getProducedToday(), + pf, + ea->getProducedThisMonth(), + peaks.c_str(), strlen(pf) == 0 ? "}" : "" ); }