From dfb9eddb79a6f5d6009c83db11bdb97943b1d527 Mon Sep 17 00:00:00 2001 From: SW-Nico Date: Thu, 7 Nov 2024 11:29:07 +0100 Subject: [PATCH] add VE.Direct "RELAY" to live view, MQTT, and HASS --- lib/VeDirectFrameHandler/VeDirectData.h | 1 + lib/VeDirectFrameHandler/VeDirectMpptController.cpp | 6 ++++++ src/MqttHandleVedirect.cpp | 1 + src/MqttHandleVedirectHass.cpp | 3 +++ src/WebApi_ws_vedirect_live.cpp | 3 +++ webapp/src/locales/de.json | 1 + webapp/src/locales/en.json | 1 + webapp/src/locales/fr.json | 1 + 8 files changed, 17 insertions(+) diff --git a/lib/VeDirectFrameHandler/VeDirectData.h b/lib/VeDirectFrameHandler/VeDirectData.h index 1a06d1014..e5b2868c6 100644 --- a/lib/VeDirectFrameHandler/VeDirectData.h +++ b/lib/VeDirectFrameHandler/VeDirectData.h @@ -43,6 +43,7 @@ struct veMpptStruct : veStruct { std::pair loadOutputState_LOAD; // physical load output or virtual load output state (on if battery voltage // reaches upper limit, off if battery reaches lower limit) std::pair loadCurrent_IL_mA; // Load current in mA (Available only for models with a physical load output) + std::pair relayState_RELAY; // relay alarm state. On=true, Off=false // these are values communicated through the HEX protocol. the pair's first // value is the timestamp the respective info was last received. if it is diff --git a/lib/VeDirectFrameHandler/VeDirectMpptController.cpp b/lib/VeDirectFrameHandler/VeDirectMpptController.cpp index 08480ffde..d4e9dac5d 100644 --- a/lib/VeDirectFrameHandler/VeDirectMpptController.cpp +++ b/lib/VeDirectFrameHandler/VeDirectMpptController.cpp @@ -31,6 +31,11 @@ bool VeDirectMpptController::processTextDataDerived(std::string const& name, std _tmpFrame.loadOutputState_LOAD.first = millis(); return true; } + if (name == "RELAY") { + _tmpFrame.relayState_RELAY.second = (value == "ON"); + _tmpFrame.relayState_RELAY.first = millis(); + return true; + } if (name == "CS") { _tmpFrame.currentState_CS = atoi(value.c_str()); return true; @@ -130,6 +135,7 @@ void VeDirectMpptController::loop() // Check if optional TEXT-Data is outdated resetTimestamp(_tmpFrame.loadOutputState_LOAD); resetTimestamp(_tmpFrame.loadCurrent_IL_mA); + resetTimestamp(_tmpFrame.relayState_RELAY); // Third we check if HEX-Data is outdated if (!isHexCommandPossible()) { return; } diff --git a/src/MqttHandleVedirect.cpp b/src/MqttHandleVedirect.cpp index d174a43be..3f71e7cdd 100644 --- a/src/MqttHandleVedirect.cpp +++ b/src/MqttHandleVedirect.cpp @@ -135,6 +135,7 @@ void MqttHandleVedirectClass::publish_mppt_data(const VeDirectMpptController::da MqttSettings.publish(topic + t, String(val)); \ } + PUBLISH_OPT(relayState_RELAY, "RELAY", currentData.relayState_RELAY.second ? "ON" : "OFF"); PUBLISH_OPT(loadOutputState_LOAD, "LOAD", currentData.loadOutputState_LOAD.second ? "ON" : "OFF"); PUBLISH_OPT(loadCurrent_IL_mA, "IL", currentData.loadCurrent_IL_mA.second / 1000.0); PUBLISH_OPT(NetworkTotalDcInputPowerMilliWatts, "NetworkTotalDcInputPower", currentData.NetworkTotalDcInputPowerMilliWatts.second / 1000.0); diff --git a/src/MqttHandleVedirectHass.cpp b/src/MqttHandleVedirectHass.cpp index f8cbcaae8..4002d656c 100644 --- a/src/MqttHandleVedirectHass.cpp +++ b/src/MqttHandleVedirectHass.cpp @@ -88,6 +88,9 @@ void MqttHandleVedirectHassClass::publishConfig() publishSensor("Panel maximum power yesterday", NULL, "H23", "power", "measurement", "W", *optMpptData); // optional info, provided only if the charge controller delivers the information + if (optMpptData->relayState_RELAY.first != 0) { + publishBinarySensor("MPPT error relay state", "mdi:export", "RELAY", "ON", "OFF", *optMpptData); + } if (optMpptData->loadOutputState_LOAD.first != 0) { publishBinarySensor("MPPT load output state", "mdi:export", "LOAD", "ON", "OFF", *optMpptData); } diff --git a/src/WebApi_ws_vedirect_live.cpp b/src/WebApi_ws_vedirect_live.cpp index 4a56646e0..da4b1b751 100644 --- a/src/WebApi_ws_vedirect_live.cpp +++ b/src/WebApi_ws_vedirect_live.cpp @@ -181,6 +181,9 @@ void WebApiWsVedirectLiveClass::populateJson(const JsonObject &root, const VeDir device["CS"] = mpptData.getCsAsString(); device["MPPT"] = mpptData.getMpptAsString(); device["OR"] = mpptData.getOrAsString(); + if (mpptData.relayState_RELAY.first > 0) { + device["RELAY"] = mpptData.relayState_RELAY.second ? "ON" : "OFF"; + } device["ERR"] = mpptData.getErrAsString(); device["HSDS"]["v"] = mpptData.daySequenceNr_HSDS; device["HSDS"]["u"] = "d"; diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index dc343c671..f520cc64c 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -180,6 +180,7 @@ "CS": "Betriebszustand", "MPPT": "Betriebszustand des Trackers", "OR": "Grund für das Ausschalten", + "RELAY": "Status Fehlerrelais", "ERR": "Fehlerbeschreibung", "HSDS": "Anzahl der Tage (0..364)", "MpptTemperature": "Ladereglertemperatur" diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index ab2e864c9..a3e601a31 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -180,6 +180,7 @@ "CS": "State of operation", "MPPT": "Tracker operation mode", "OR": "Off reason", + "RELAY": "Error relay state", "ERR": "Error code", "HSDS": "Day sequence number (0..364)", "MpptTemperature": "Charge controller temperature" diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index c5ca108bf..a88478f67 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -180,6 +180,7 @@ "CS": "State of operation", "MPPT": "Tracker operation mode", "OR": "Off reason", + "RELAY": "Error relay state", "ERR": "Error code", "HSDS": "Day sequence number (0..364)", "MpptTemperature": "Charge controller temperature"