Connecting Goodwe Solar Panel Inverter Directly to Openhab

Hi, I have recently connected my Goodwe inverter and am looking on how to control it. I have used this to connect it to openHAB, which works out of the box (thank you!). But this doesn’t allow me to control it.
I am aspecially intrested in controlling the battery mode and changing the paramters on the fly (every hour max.)

Is there a way to do this, maybe add it to this script based addon-on? I have found this home assistant implementation but can’t find a OH counterpart…

Or is this the moment I have to get HA running and control it via HA using OH? Any advice highly appreciated.

Best regards,
Uitgslapen

Hello Daan,

The goodwe library allows to send commands to the inverter. The possibilities are described in inverter.py as ‘@abstractmethod’ methods.

My knowledge of python is very basic, I don’t know how to implement this.

Best regards,
Diego

With this test script you can read the available settings:

# readSettings.py

import asyncio
import goodwe

async def get_settings_data():
    ip_address = '192.168.1.120'

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

    for setting in inverter.settings():
        if setting.id_ in runtime_data:
            print(f"{setting.id_}: \t\t {setting.name} = {runtime_data[setting.id_]} {setting.unit}")

asyncio.run(get_settings_data())

The script shows some errors when it tries to read settings that don’t exist in my inverter.

And this test script shows the possible operation modes and the active mode:

# operationModes.py

import asyncio
import goodwe

async def read_operation_modes():
    ip_address = '192.168.0.138'

    inverter = await goodwe.connect(ip_address)
    supported_modes = await inverter.get_operation_modes(True)
    print(supported_modes)
    active_mode = await inverter.get_operation_mode()
    print(active_mode)

asyncio.run(read_operation_modes())

I guess you would like to change the operation mode. You could look into the HA code to understand how to do it. Look into the select.py code.

And here you can read some extra info of your inverter (model name, firmware version,…)

# deviceInfo.py

import asyncio
import goodwe

async def device_info():
    ip_address = '192.168.1.120'

    inverter = await goodwe.connect(ip_address)
    info = await inverter.read_device_info()
    print(f"model name:      {inverter.model_name}")
    print(f"serial number:   {inverter.serial_number}")
    print(f"rated power:     {inverter.rated_power}")
    print(f"AC output type:  {inverter.ac_output_type}")
    print(f"firmware:        {inverter.firmware}")
    print(f"arm firmware:    {inverter.arm_firmware}")
    print(f"modbus version:  {inverter.modbus_version}")
    print(f"dsp1 version:    {inverter.dsp1_version}")
    print(f"dsp2 version:    {inverter.dsp2_version}")
    print(f"dsp svn version: {inverter.dsp_svn_version}")
    print(f"arm version:     {inverter.arm_version}")
    print(f"arm svn version: {inverter.arm_svn_version}")

asyncio.run(device_info())

GoodWe like many other inverters can be controlled via Modbus, including battery if you figure out how.

I found this document… will do some modbus reading to see if it makes sense…

https://downloads.vodnici.net/uploads/wpforo/attachments/483/4349-1GoodweModbusPROTOCOLHybrid-ENV1-3EMseries.pdf

And will also try the proposed scripts.

thanks…

looks oldish, there’s at least a 2022 version available

Hi all,
I have recently upgraded from Debian 11 Bullseye to 12 Bookworm and suddenly my set-up (as per the original post in this thread) has stopped working.
If I run the script manually, I get the following error:

user@machine: bash /etc/openhab/scripts/goodwe.sh
Traceback (most recent call last):
File “/etc/openhab/scripts/goodwejson.py”, line 2, in
import goodwe
ModuleNotFoundError: No module named ‘goodwe’

I guess the problem is that the goodwe module is no longer available to the script.

This solution does not work either:
sudo -u openhab pip install goodwe

as this has apparently been disabled in Bookworm.

Any help to restore the system to functional would be most appreciated.

Look here.

In Bookworm the goodwe library must be installed for user openhab. I will change it in the original post.

Thank you Diego for the prompt reply. I had already tried that to no avail. Being a beginner, these virtual environments a a little Greek to me…


sudo -u openhab pip install goodwe
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.


Again, thank you! much appreciated

Well, I have not upgraded to Bookworm yet…

Can you direct me to that version, I do not find a different/newer version…

I installed it with the --break-system-packages option mentioned.

I have edited the original post. Did you install it this way?

I installed it for all users, not specifaclly for openhab.

Writing settings to the inverter can be done this way:

# setTime.py

import asyncio
import goodwe
from datetime import datetime

async def set_time():
    ip_address = '192.168.1.120'

    inverter = await goodwe.connect(ip_address)
    await inverter.write_setting("time", datetime.now())
    new_time = await inverter.read_setting("time")
    print(f"Goodwe time has been set to {new_time}")
    
asyncio.run(set_time())

This python script can be called from Openhab from a Javascript rule like this:

var result = actions.Exec.executeCommandLine(time.Duration.ofSeconds(10),"python3", "/etc/openhab/scripts/setTime.py");
console.info(result);

Changing the Operation mode would have to be done with inverter.set_operation_mode. I don’t (yet) want to experiment with this on my installation.

I have been able to get it back to work by using a virtual environment. Not sure this is the best option, but it does actually work.

I have a new script, (entornoInversor.sh), where a new virtual environment is created, activated and where the missing goodwe module is installed:

#! /bin/bash
python3 -m venv Inversor
source Inversor/bin/activate
pip3 install goodwe

I run this script once on starting the OpenHab service (add this to exec.things):

exec:command:goodwe_env [command="bash /etc/openhab/scripts/entornoInversor.sh", interval=0, timeout=5, autorun=true]

and I have amended my existing script to work with the new environment:

#!/bin/bash
source /etc/openhab/scripts/Inversor/bin/activate 
RESULT=$(python3 /etc/openhab/scripts/goodwejson.py)

echo "$RESULT" | tr '\n' ' '

Another option would be to use a Debian package from the testing/unstable repo (https://packages.debian.org/trixie/python3-goodwe). I have not tried this yet.

Just my 0.02p

I am polling every 20 sec. with a timeout of 15 sec. and I do not have any problems. Looks it is very different based on the inverter model.

My inverter models are GW8K-ET and GW5K-ET

I am polling every minute with no problems. The inverter is a GW5000 EH.