Connecting Goodwe Solar Panel Inverter Directly to Openhab

Hi Guys,
can somebody of you guys confirm if I can get all data from the converter locally, if its offline and not connected to the cloud?
I have an offer for a solar plant that includes a goodwee converter (GoodWe ET Plus Hybrid GW5K-ET). Before accepting it, I wanted to make sure that I can operate it completely local & offline and retrieve all data locally. l would even block all internet access for the converter in my router.

Hi Diego,

I followed your manual, and all was working fine, up to the point with the bash commmand.
I get the following result in my tail-log, is this solvable?

2023-04-06 @ 16:00:13 [WARN ] - Handler StationHandler of thing semsportal:station:myPortal:solarPanels tried accessing its bridge although the handler was already disposed. 2023-04-06 @ 16:00:13 [WARN ] - Handler StationHandler tried updating the thing status although the handler was already disposed. 2023-04-06 @ 16:00:32 [WARN ] - Tried to execute 'bash /etc/openhab/scripts/goodwe.sh', but it is not contained in whitelist. 2023-04-06 @ 16:00:36 [WARN ] - Handler StationHandler of thing semsportal:station:myPortal:solarPanels tried accessing its bridge although the handler was already disposed. 2023-04-06 @ 16:00:36 [WARN ] - Handler StationHandler tried updating the thing status although the handler was already disposed. 2023-04-06 @ 16:01:32 [WARN ] - Tried to execute 'bash /etc/openhab/scripts/goodwe.sh', but it is not contained in whitelist. 2023-04-06 @ 16:02:13 [WARN ] - Handler StationHandler of thing semsportal:station:_myPortal:solarPanels tried accessing its bridge although the handler was already disposed. 2023-04-06 @ 16:02:13 [WARN ] - Handler StationHandler tried updating the thing status although the handler was already disposed.

Hi Nico

This part of the error message:

suggests that the script was not placed in the whitelist as explained above:

Hi,
I’ve followed the discription and was able to get the current status with cli.
When i go to openhab i can see the created items “zp***”.
All values show “NULL” instead of the actual values.

When i look at item ZP_JSON_Out i also see a “?” under “Channel Links”.

Can somebody help me figure out how this is happening and how i can solve this?
As mentioned at the start, when i perfrom BASH /¨/goodwe.sh i’m getting the actual values from the invertor.

Regards

I made a mistake in the code plus didn’t install the bindings mentioned here.

Prerequisites:

Install the exec binding

Install the JSONpath transformation addon (other addons)

After installating the binding the values are correct in the system.

Now i want to add them as cells in a layout but this doesn’t seem to workout.
They don’t show the value and are not linked to a thing.
I’ll keep trying in the mean time but if anyone can give me some advice on this matter it’s always welcome.

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

Continuing the discussion from Connecting Goodwe Solar Panel Inverter Directly to Openhab:

Hy Larsen and thanks for the additional explanation. Sry for my nooby question but when I execute the script all I got is the error message:

File “/etc/openhab/scripts/goodwe2mqtt.py”, line 3, in
import paho.mqtt.client as mqtt
ModuleNotFoundError: No module named ‘paho’

Do I have to load an additional library?
Mosquitto is installed and works so far.
Can you help me with that?

Regards

sure: You need the goodwe library installed (see first post).
But maybe in your case that failed as newer debian versions prevent the direct installation in order to avoid problems with other dependencies.
I went the short way and installed with

sudo pip3 install goodwe --break-system-packages

and

pip3 install paho-mqtt --break-system-packages

I don’t think that this will cause any problems for my system (only openhab) but if somebody has an easy but more elegant or correct solution please tell us.

Thanks a lot. installing paho was the right thing to do. Now I don’t get values direkt to my item in Openhab, but MQTT FX gets values that i can use.

I downloaded the python library and made the goodwetest.py script.
I am not sure were to place it. I am on OH 4.1.1 on a Raspberry 3. I made the file access via samba. I tried:
\…\openHAB-conf\scripts
and
\…\openHAB-userdata\etc\scripts
None of these places work.
The error message in openhabian via putty is:
python3: can’t open file ‘/home/openhabian/goodwetest.py’: [Errno 2] No such file or directory

How can I fix it?

Hi Bjoern,

If you use Putty, it is in:

/etc/openhab/scripts

With Samba, it is in:

\\sharename\openHAB-conf\scripts

Apparently python3 looks in your home directory. Before you execute the script, you should go to the correct directory and then execute it:

cd /etc/openhab/scripts
python3 goodwetest.py

Or you can put it in your home directory and execute it without changing directories. But the definitive files goodwejson.py and goodwe.sh must be placed in /etc/openhab/scripts.

Great, thank you!! That were the missing information.

I implemented all above and made my changes to the items file etc… (Hopefully it survives the next update).

I get the data into openhab. However, there is an error issued:

2024-02-01 21:26:21.420 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item ‘ZP_JSON_Out’ updated to { “ppv”: 0, “total_inverter_power”: 171, “active_power”: -23, “grid_in_out”: 0, “load_p1”: 18, “load_p2”: 70, “load_p3”: 79, “load_ptotal”: 167, “temperature_air”: 31.3, “pbattery1”: 126, “battery_mode”: 2, “e_day”: 9.4, “house_consumption”: 149, “battery_temperature”: 19.0, “battery_soc”: 53, “battery_soh”: 99, “end”: 0 }

/etc/openhab/scripts/goodwe.sh: line 2: $‘\r’: command not found
/etc/openhab/scripts/goodwe.sh: line 4: $‘\r’: command not found
/etc/openhab/scripts/goodwe.sh: line 2: $‘\r’: command not found
/etc/openhab/scripts/goodwe.sh: line 4: $‘\r’: command not found

The goodwe.sh is copied and pasted as given in the first post. I just re-did it and saved it in UFT-8 format. The error message is still there. This error is issued three times and then all the values come in formated style.
Can anyone spot the issue? What do I need to change?

Hi Bjoern,

You used a Windows text editor to save the file.

  • In Windows each line in a text file ends with two characters: carriage return (CR or \r) and line feed (LF or \n).
  • In Unix style text files only the linefeed is used.

So you need to convert the file to Unix style. This can be done in different ways. One possibility is:

awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt

The errors would probably also go away if you delete the empty lines 2 and 4.

@DiegoDf
What you wrote was the problem. I deleted the lines and now it works error free.

One remark for items definition. Some of the items defined are not energy but power. E.g. for Number:Power zpActivePower “zpActivePower [%.0f W]”
That makes the difference in the items overview. Otherwise there the wrong unit kWh instead of W is shown. When you click into the item the unit is always as defined in “[” “]”.

Thanks Bjoern. This was an error. I have edited the original post. Changed the wrong Number:Energy lines in Number:Power.

For information: I changed a little my above script and the things-file:

  • remove loop from python-script so that only openhab loops
  • increase looping delay to 180sec, because polling more often breaks the connection of the inverter to the sems-portal. (The critical time seems to be different for different models)

hello guys, I was just on the way to set up openhabian and connect it to Goodwe inverter with battery. Nice work done already acording to that thread. But I did not saw anyone to also send some commands to inverter… Anybody tried for example set up export limit? Or force charging battery?

Best regards, Alex

According to this post, with Debian bookworm you should install the goodwe library for the openhab user:
sudo -u openhab pip install goodwe