Skip to content

Commit

Permalink
Feature: add VE.Direct "RELAY" to live view, MQTT, and HASS
Browse files Browse the repository at this point in the history
  • Loading branch information
SW-Niko authored and schlimmchen committed Nov 20, 2024
1 parent 1d5816d commit 4beea35
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/VeDirectFrameHandler/VeDirectData.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct veMpptStruct : veStruct {
std::pair<uint32_t, bool> 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<uint32_t, uint32_t> loadCurrent_IL_mA; // Load current in mA (Available only for models with a physical load output)
std::pair<uint32_t, bool> 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
Expand Down
6 changes: 6 additions & 0 deletions lib/VeDirectFrameHandler/VeDirectMpptController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions src/MqttHandleVedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/MqttHandleVedirectHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:electric-switch", "RELAY", "ON", "OFF", *optMpptData);
}
if (optMpptData->loadOutputState_LOAD.first != 0) {
publishBinarySensor("MPPT load output state", "mdi:export", "LOAD", "ON", "OFF", *optMpptData);
}
Expand Down
3 changes: 3 additions & 0 deletions src/WebApi_ws_vedirect_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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"
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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"
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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"
Expand Down

0 comments on commit 4beea35

Please sign in to comment.