Add external device load sensor

This commit is contained in:
MrSossidge 2026-05-18 13:49:59 +01:00
parent 27a362b5b3
commit 1c19d29353
3 changed files with 12 additions and 0 deletions

View File

@ -9,6 +9,7 @@ struct MpptData {
float pvPower; // W (1W resolution) float pvPower; // W (1W resolution)
float yieldToday; // Wh (10Wh resolution) float yieldToday; // Wh (10Wh resolution)
float pvVoltage; // V (not in MPPT advert, always 0) float pvVoltage; // V (not in MPPT advert, always 0)
float externalLoad;
uint8_t chargeState; // 0=off 3=bulk 4=absorption 5=float etc uint8_t chargeState; // 0=off 3=bulk 4=absorption 5=float etc
uint8_t errorCode; // 0 = no error uint8_t errorCode; // 0 = no error
bool valid; // false if decryption/parse failed bool valid; // false if decryption/parse failed

View File

@ -137,6 +137,14 @@ static void publishDiscovery() {
"\"value_template\":\"{{ value_json.error_code | int }}\"," "\"value_template\":\"{{ value_json.error_code | int }}\","
"\"icon\":\"mdi:alert-circle-outline\"" AVAIL DEV "\"icon\":\"mdi:alert-circle-outline\"" AVAIL DEV
}, },
{
"homeassistant/sensor/victron_smartsolar_garage/external_load/config",
"{\"unique_id\":\"victron_mppt_el\",\"name\":\"External Load\","
"\"state_topic\":\"" MQTT_TOPIC_DATA "\","
"\"value_template\":\"{{ value_json.external_load_a | float }}\","
"\"unit_of_measurement\":\"A\",\"device_class\":\"current\","
"\"state_class\":\"measurement\"" AVAIL DEV
},
}; };
for (auto& s : sensors) { for (auto& s : sensors) {
@ -164,6 +172,7 @@ static void publishData(const MpptData& d) {
doc["charge_state"] = chargeStateName(d.chargeState); doc["charge_state"] = chargeStateName(d.chargeState);
doc["charge_state_raw"] = d.chargeState; doc["charge_state_raw"] = d.chargeState;
doc["error_code"] = d.errorCode; doc["error_code"] = d.errorCode;
doc["external_load_a"] = serialized(String(d.externalLoad, 2));
char buf[256]; char buf[256];
serializeJson(doc, buf); serializeJson(doc, buf);

View File

@ -116,6 +116,8 @@ MpptData parseVictronMppt(const uint8_t* encKey, const uint8_t* data, size_t len
int32_t batI_raw = reader.readSigned(16); int32_t batI_raw = reader.readSigned(16);
uint32_t yieldToday = reader.readUnsigned(16); uint32_t yieldToday = reader.readUnsigned(16);
uint32_t solarPower = reader.readUnsigned(16); uint32_t solarPower = reader.readUnsigned(16);
uint32_t extLoad = reader.readUnsigned(9); // 9 bits, 0.1A/bit
result.externalLoad = (extLoad != 0x1FF) ? extLoad / 10.0f : 0.0f;
result.chargeState = (uint8_t)chargeState; result.chargeState = (uint8_t)chargeState;
result.errorCode = (uint8_t)chargerError; result.errorCode = (uint8_t)chargerError;