Connecting Goodwe Solar Panel Inverter Directly to Openhab

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