feat: Auto-detection inverter paralleli con script dedicati
Build Docker Image for Raspberry Pi / build-and-push (push) Successful in 7m18s
Build Docker Image for Raspberry Pi / build-and-push (push) Successful in 7m18s
- Modificato entrypoint.sh per rilevare automaticamente inverter paralleli - Usa flag -p per parallel discovery (testa QPGS0-9) - Script mqtt-push-parallel.sh per pubblicare dati di ogni inverter - Script mqtt-init-parallel.sh per discovery topics (ogni 10 min) - Naming: voltronic_inv1, voltronic_inv2, ecc. - Fallback automatico a single-mode se PARALLEL_COUNT=0 Nota: Il parallel discovery richiede che inverter supportino comandi QPGS
This commit is contained in:
@@ -235,16 +235,38 @@ if [ "$NEED_DISCOVERY" = "true" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Starting MQTT Bridge Services ==="
|
echo "=== Detecting Inverter Configuration ==="
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Wait a bit for the device to be ready
|
# Wait a bit for the device to be ready
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# Init the mqtt server for the first time, then every 5 minutes
|
# Check for parallel inverters
|
||||||
|
PARALLEL_CHECK=$(/opt/inverter-cli/bin/inverter_poller -p 2>&1)
|
||||||
|
PARALLEL_COUNT=$(echo "$PARALLEL_CHECK" | grep "PARALLEL_COUNT=" | cut -d= -f2)
|
||||||
|
|
||||||
|
if [ ! -z "$PARALLEL_COUNT" ] && [ "$PARALLEL_COUNT" -gt 0 ]; then
|
||||||
|
echo "✓ Detected $PARALLEL_COUNT parallel inverter(s)"
|
||||||
|
echo " Using parallel mode scripts..."
|
||||||
|
USE_PARALLEL=true
|
||||||
|
MQTT_PUSH_SCRIPT="/opt/inverter-mqtt/mqtt-push-parallel.sh"
|
||||||
|
MQTT_INIT_SCRIPT="/opt/inverter-mqtt/mqtt-init-parallel.sh"
|
||||||
|
else
|
||||||
|
echo "ℹ Single inverter mode"
|
||||||
|
echo " Using standard scripts..."
|
||||||
|
USE_PARALLEL=false
|
||||||
|
MQTT_PUSH_SCRIPT="/opt/inverter-mqtt/mqtt-push.sh"
|
||||||
|
MQTT_INIT_SCRIPT="/opt/inverter-mqtt/mqtt-init.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Starting MQTT Bridge Services ==="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Init the mqtt server for the first time, then every 10 minutes (600 seconds)
|
||||||
# This will re-create the auto-created topics in the MQTT server if HA is restarted...
|
# This will re-create the auto-created topics in the MQTT server if HA is restarted...
|
||||||
echo "Starting MQTT initialization service..."
|
echo "Starting MQTT initialization service (every 10 minutes)..."
|
||||||
watch -n 300 /opt/inverter-mqtt/mqtt-init.sh > /dev/null 2>&1 &
|
watch -n 600 "$MQTT_INIT_SCRIPT" > /dev/null 2>&1 &
|
||||||
|
|
||||||
# Run the MQTT Subscriber process in the background (so that way we can change the configuration on the inverter from home assistant)
|
# Run the MQTT Subscriber process in the background (so that way we can change the configuration on the inverter from home assistant)
|
||||||
echo "Starting MQTT subscriber for commands..."
|
echo "Starting MQTT subscriber for commands..."
|
||||||
@@ -257,4 +279,4 @@ echo "✓ All services started successfully!"
|
|||||||
echo " Logs will appear below..."
|
echo " Logs will appear below..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
watch -n 30 /opt/inverter-mqtt/mqtt-push.sh > /dev/null 2>&1
|
watch -n 30 "$MQTT_PUSH_SCRIPT" > /dev/null 2>&1
|
||||||
|
|||||||
Executable
+90
@@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# MQTT Discovery for Parallel Inverters
|
||||||
|
# Registers Home Assistant auto-discovery topics for each parallel inverter
|
||||||
|
|
||||||
|
MQTT_CONFIG="/etc/inverter/mqtt.json"
|
||||||
|
INVERTER_BIN="/opt/inverter-cli/bin/inverter_poller"
|
||||||
|
|
||||||
|
MQTT_SERVER=$(jq -r '.server' "$MQTT_CONFIG")
|
||||||
|
MQTT_PORT=$(jq -r '.port' "$MQTT_CONFIG")
|
||||||
|
MQTT_TOPIC=$(jq -r '.topic' "$MQTT_CONFIG")
|
||||||
|
MQTT_DEVICENAME=$(jq -r '.devicename' "$MQTT_CONFIG")
|
||||||
|
MQTT_USERNAME=$(jq -r '.username' "$MQTT_CONFIG")
|
||||||
|
MQTT_PASSWORD=$(jq -r '.password' "$MQTT_CONFIG")
|
||||||
|
MQTT_CLIENTID=$(jq -r '.clientid' "$MQTT_CONFIG")
|
||||||
|
|
||||||
|
registerTopic () {
|
||||||
|
local inverter_id="$1"
|
||||||
|
local metric="$2"
|
||||||
|
local unit="$3"
|
||||||
|
local icon="$4"
|
||||||
|
|
||||||
|
local device_name="${MQTT_DEVICENAME}_inv${inverter_id}"
|
||||||
|
|
||||||
|
mosquitto_pub \
|
||||||
|
-h $MQTT_SERVER \
|
||||||
|
-p $MQTT_PORT \
|
||||||
|
-u "$MQTT_USERNAME" \
|
||||||
|
-P "$MQTT_PASSWORD" \
|
||||||
|
-i "${MQTT_CLIENTID}_init" \
|
||||||
|
-t "$MQTT_TOPIC/sensor/${device_name}_${metric}/config" \
|
||||||
|
-r \
|
||||||
|
-m "{
|
||||||
|
\"name\": \"${device_name}_${metric}\",
|
||||||
|
\"unit_of_measurement\": \"$unit\",
|
||||||
|
\"state_topic\": \"$MQTT_TOPIC/sensor/${device_name}_${metric}\",
|
||||||
|
\"icon\": \"mdi:$icon\",
|
||||||
|
\"unique_id\": \"${device_name}_${metric}\",
|
||||||
|
\"device\": {
|
||||||
|
\"identifiers\": [\"${device_name}\"],
|
||||||
|
\"name\": \"${device_name}\",
|
||||||
|
\"manufacturer\": \"Voltronic\",
|
||||||
|
\"model\": \"Parallel Inverter\"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
}
|
||||||
|
|
||||||
|
register_inverter_topics() {
|
||||||
|
local inverter_id="$1"
|
||||||
|
|
||||||
|
echo "Registering MQTT discovery topics for: ${MQTT_DEVICENAME}_inv${inverter_id}"
|
||||||
|
|
||||||
|
# Register all metrics for this inverter
|
||||||
|
registerTopic "$inverter_id" "serial" "" "identifier"
|
||||||
|
registerTopic "$inverter_id" "mode" "" "solar-power"
|
||||||
|
registerTopic "$inverter_id" "AC_grid_voltage" "V" "power-plug"
|
||||||
|
registerTopic "$inverter_id" "AC_grid_frequency" "Hz" "current-ac"
|
||||||
|
registerTopic "$inverter_id" "AC_out_voltage" "V" "power-plug"
|
||||||
|
registerTopic "$inverter_id" "AC_out_frequency" "Hz" "current-ac"
|
||||||
|
registerTopic "$inverter_id" "PV_in_voltage" "V" "solar-panel-large"
|
||||||
|
registerTopic "$inverter_id" "PV_in_current" "A" "solar-panel-large"
|
||||||
|
registerTopic "$inverter_id" "PV_in_watts" "W" "solar-panel-large"
|
||||||
|
registerTopic "$inverter_id" "Load_pct" "%" "brightness-percent"
|
||||||
|
registerTopic "$inverter_id" "Load_watt" "W" "chart-bell-curve"
|
||||||
|
registerTopic "$inverter_id" "Load_va" "VA" "chart-bell-curve"
|
||||||
|
registerTopic "$inverter_id" "Battery_capacity" "%" "battery-outline"
|
||||||
|
registerTopic "$inverter_id" "Battery_voltage" "V" "battery-outline"
|
||||||
|
registerTopic "$inverter_id" "Battery_charge_current" "A" "current-dc"
|
||||||
|
|
||||||
|
echo " ✓ Discovery topics registered"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Discover parallel inverters
|
||||||
|
PARALLEL_DISCOVERY=$("$INVERTER_BIN" -p 2>&1)
|
||||||
|
PARALLEL_COUNT=$(echo "$PARALLEL_DISCOVERY" | grep "PARALLEL_COUNT=" | cut -d= -f2)
|
||||||
|
|
||||||
|
if [ -z "$PARALLEL_COUNT" ] || [ "$PARALLEL_COUNT" -eq 0 ]; then
|
||||||
|
echo "No parallel inverters found, falling back to standard init"
|
||||||
|
exec /opt/inverter-mqtt/mqtt-init.sh
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Found $PARALLEL_COUNT parallel inverters"
|
||||||
|
|
||||||
|
# Register topics for each inverter
|
||||||
|
for i in $(seq 1 $PARALLEL_COUNT); do
|
||||||
|
register_inverter_topics "$i"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "✓ All MQTT discovery topics registered for $PARALLEL_COUNT inverters"
|
||||||
Reference in New Issue
Block a user