diff --git a/sources/inverter-mqtt/mqtt-push-parallel.sh b/sources/inverter-mqtt/mqtt-push-parallel.sh index 49b513f..c93b696 100755 --- a/sources/inverter-mqtt/mqtt-push-parallel.sh +++ b/sources/inverter-mqtt/mqtt-push-parallel.sh @@ -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,17 +130,32 @@ 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_watts" "$PV_WATTS" + + 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) local PV_WH=$(echo "$PV_WATTS" | awk '{printf "%.4f", $1 / 120}')