fix: PV_in_current ora è la corrente reale lato pannelli
Build Docker Image for Raspberry Pi / build-and-push (push) Has been cancelled

Precedentemente DATA[25] (corrente SCC→batteria a tensione batteria)
veniva pubblicato direttamente come PV_in_current, dando valori errati.

Calcolo corretto via conservazione energia nell'SCC (DC-DC converter):
  P_pv   = V_batt × I_scc        (potenza SCC output = potenza pannelli)
  I_pv   = P_pv / V_pv           (corrente reale pannelli a tensione PV)
  P_pv   = V_pv × I_pv           (invariato - solo presentazione diversa)

Esempio con: V_pv=240V, V_batt=55V, I_scc=5A
  Prima: PV_in_current = 5A   (corrente SCC a 55V, errata)
  Dopo:  PV_in_current = 1.15A (corrente reale pannelli a 240V, corretta)
  PV_in_watts = 275W in entrambi i casi (matematicamente invariato)
This commit is contained in:
Pi Developer
2026-02-22 15:07:00 +01:00
parent 078544381e
commit 74508bd330
+30 -11
View File
@@ -103,20 +103,24 @@ processInverter () {
[ "${DATA[12]}" ] && pushMQTTData "$inv_id" "Battery_charge_current" "${DATA[12]}"
[ "${DATA[13]}" ] && pushMQTTData "$inv_id" "Battery_capacity" "${DATA[13]}"
[ "${DATA[14]}" ] && pushMQTTData "$inv_id" "PV_in_voltage" "${DATA[14]}"
[ "${DATA[25]}" ] && pushMQTTData "$inv_id" "PV_in_current" "${DATA[25]}"
[ "${DATA[26]}" ] && pushMQTTData "$inv_id" "Battery_discharge_current" "${DATA[26]}"
# ─── PV_in_watts calculation ──────────────────────────────────────────────
# DATA[25] = SCC output current at battery-bus voltage (not at PV panel V).
# Source: original QPIGS comment "current going out to battery at battery voltage".
# Formula: Battery_voltage × DATA[25] = power delivered by SCC to battery.
# ─── PV panel-side power calculation ─────────────────────────────────────
# DATA[25] is labeled "PV input current" by the inverter but is actually
# the SCC *output* current flowing to the battery at battery voltage.
# The inverter protocol does NOT expose the real panel-side current directly.
#
# The SCC is a DC-DC converter: power_in ≈ power_out (ignoring ~5% losses).
# P_pv = V_batt × I_scc (SCC output power = panel power)
# I_pv = P_pv / V_pv (real panel current at panel voltage)
#
# Edge case - battery fully charged (DATA[25] = 0):
# If STATUS b7=1 (SCC_OK) and STATUS b2=1 (line_loss = no AC grid),
# solar is feeding the load directly. Use Load_watt as proxy.
# If AC grid is present (line_loss=0), solar just floats battery → 0W is correct.
# If SCC_OK (b7=1) and line_loss (b2=1, no AC grid) → solar feeds load directly.
# Best proxy: Load_watt (solar production = what the load is consuming).
# If AC grid is present solar floats battery, nothing meaningful to report.
local BATT_V="${DATA[11]:-0}"
local SCC_A="${DATA[25]:-0}"
local PV_V="${DATA[14]:-0}"
local LOAD_W="${DATA[9]:-0}"
local STATUS="${DATA[19]:-00000000}"
@@ -126,16 +130,31 @@ processInverter () {
local SCC_OK="${STATUS:0:1}"
local LINE_LOSS="${STATUS:5:1}"
local PV_WATTS
local PV_WATTS PV_CURRENT
if awk -v v="$SCC_A" 'BEGIN{exit !(v+0 > 0)}' 2>/dev/null; then
# SCC delivering current to battery
# SCC delivering current to battery: compute panel-side values
# P_pv = V_batt × I_scc
PV_WATTS=$(echo "$BATT_V $SCC_A" | awk '{printf "%.1f", $1 * $2}')
# I_pv = P_pv / V_pv (real current from panels at panel voltage)
if awk -v v="$PV_V" 'BEGIN{exit !(v+0 > 0)}' 2>/dev/null; then
PV_CURRENT=$(echo "$PV_WATTS $PV_V" | awk '{printf "%.2f", $1 / $2}')
else
PV_CURRENT="0.00"
fi
elif [ "$SCC_OK" = "1" ] && [ "$LINE_LOSS" = "1" ]; then
# SCC OK, battery full, no AC grid → solar feeds load
# SCC OK, battery full, no AC grid → solar feeds load directly
PV_WATTS="$LOAD_W"
if awk -v v="$PV_V" 'BEGIN{exit !(v+0 > 0)}' 2>/dev/null; then
PV_CURRENT=$(echo "$PV_WATTS $PV_V" | awk '{printf "%.2f", $1 / $2}')
else
PV_CURRENT="0.00"
fi
else
PV_WATTS="0.0"
PV_CURRENT="0.00"
fi
pushMQTTData "$inv_id" "PV_in_current" "$PV_CURRENT"
pushMQTTData "$inv_id" "PV_in_watts" "$PV_WATTS"
# Watt-hours (approximated from polling interval = 30s = 1/120 hour)