Connecting Goodwe Solar Panel Inverter Directly to Openhab

Here is my little adaption of the very useful script from @Martin_Cholkowski and @DiegoDf :

  • all values are populated as separate mqtt-messages, so no need to extract json
  • content is changed for a Goodwe15K-ET
  • installation of the python script is the same as in the first post, but no need for rules
  • things are created with .things-file
  • I create all items at once in the UI with “add equipment to model”

the script (change IP, username and password)

goodwe2mqtt.py (click to see code)
import asyncio
import goodwe
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
import time

async def get_runtime_data():
    ip_address = '192.168.xx.xx'
    global jsondata
    jsondata = ""
    sensors = [
        "timestamp",                  # Timestamp [2023-10-30 10:50:01]
        "ppv",                        # PV Power [4308 W]
        "total_inverter_power",       # Total Power [2910 W]
        "active_power",               # Active Power [31 W]
        "apparent_power",             # Apparent Power [3153 VA]
        "backup_ptotal",              # Back-up Load [66 W]
        "load_ptotal",                # Load [2813 W]
        "pbattery1",                  # Battery Power [-1120 W]
        "house_consumption",          # House Consumption [3157 W]
        "battery_soc",                # Battery State of Charge [71 %]
        "active_power_total",         # Active Power Total [52 W]
        "meter_active_power_total",   # Meter Active Power Total [52 W]
        "meter_apparent_power_total", # Meter Apparent Power Total [3059 VA]    
    ]

    inverter = await goodwe.connect(ip_address)
    runtime_data = await inverter.read_runtime_data()

    for sensor in inverter.sensors():
        if sensor.id_ in runtime_data:
            if sensor.id_ in sensors:
                jsondata = str(runtime_data[sensor.id_])

                publish.single("goodwe/" + sensor.id_, payload=jsondata, qos=0, retain=False, hostname="localhost",
                port=1883, client_id="", keepalive=60, will=None, auth={'username': 'your_username', 'password': 'yourPassword'},
                tls=None, protocol=mqtt.MQTTv311, transport="tcp")

asyncio.run(get_runtime_data())

We need two things, one for the execution of the script and one for the mqtt-values. Here are the definitions in file-format.

goodwe.things (click so see)
Thing exec:command:goodwe2mqtt "Goodwe2mqtt" [command="/usr/bin/python3 /etc/openhab/scripts/goodwe2mqtt.py",interval=180, timeout=10, autorun=false]

Thing mqtt:topic:GoodweInv "GoodweInv" (mqtt:broker:MosquittoMqttBroker) { Channels:
  Type string : PV_timestamp "PV_timestamp" [ stateTopic = "goodwe/timestamp"]
  Type number : PV_ppv "PV_ppv" [ stateTopic = "goodwe/ppv", unit="W"]
  Type number : PV_total_inverter_power "PV_total_inverter_power" [ stateTopic = "goodwe/total_inverter_power", unit="W"]
  Type number : PV_active_power "PV_active_power" [ stateTopic = "goodwe/active_power", unit="W"]
  Type number : PV_apparent_power "PV_apparent_power" [ stateTopic = "goodwe/apparent_power", unit="VA"]
  Type number : PV_backup_ptotal "PV_backup_ptotal" [ stateTopic = "goodwe/backup_ptotal", unit="W"]
  Type number : PV_load_ptotal "PV_load_ptotal" [ stateTopic = "goodwe/load_ptotal", unit="W"]
  Type number : PV_pbattery1 "PV_pbattery1" [ stateTopic = "goodwe/pbattery1", unit="W"]
  Type number : PV_house_consumption "PV_house_consumption" [ stateTopic = "goodwe/house_consumption", unit="W"]
  Type number : PV_battery_soc "PV_battery_soc" [ stateTopic = "goodwe/battery_soc"]
  Type number : PV_active_power_total "PV_active_power_total" [ stateTopic = "goodwe/active_power_total", unit="W"]
  Type number : PV_meter_active_power_total "PV_meter_active_power_total" [ stateTopic = "goodwe/meter_active_power_total", unit="W"]
  Type number : PV_meter_apparent_power_total "PV_meter_apparent_power_total" [ stateTopic = "goodwe/meter_apparent_power_total", unit="VA"]
}

Any hints how to improve are of course welcome

1 Like