Created
June 25, 2026 21:22
-
-
Save deverton/1240fca4457e847c23ef8f2beb65616d to your computer and use it in GitHub Desktop.
Simple Python script to set the Goodwe Meter Target Power Offset to reduce imports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import pymodbus | |
| from pymodbus.client import ModbusTcpClient | |
| client = ModbusTcpClient('192.168.1.1', port=502) | |
| if client.connect(): | |
| unit_id = 247 | |
| reg_address = 47120 | |
| print('--- Step 1: Reading Initial Value ---') | |
| initial_read = client.read_holding_registers(address=reg_address, count=1, device_id=unit_id) | |
| if initial_read.isError(): | |
| print('Error reading initial value:', initial_read) | |
| else: | |
| raw_val = initial_read.registers[0] | |
| signed_val = raw_val - 65536 if raw_val > 32767 else raw_val | |
| print(f'Current Meter Target Power Offset: {signed_val} W') | |
| print('\n--- Step 2: Writing New Value (+20W for Export) ---') | |
| # Updated to device_id here as well | |
| write_res = client.write_registers(address=reg_address, values=[20], device_id=unit_id) | |
| if write_res.isError(): | |
| print('Error writing to register:', write_res) | |
| else: | |
| print('Write command sent successfully.') | |
| print('\n--- Step 3: Verifying Change ---') | |
| post_read = client.read_holding_registers(address=reg_address, count=1, device_id=unit_id) | |
| if post_read.isError(): | |
| print('Error reading verification value:', post_read) | |
| else: | |
| raw_val_post = post_read.registers[0] | |
| signed_val_post = raw_val_post - 65536 if raw_val_post > 32767 else raw_val_post | |
| print(f'New Meter Target Power Offset: {signed_val_post} W') | |
| if signed_val_post == 20: | |
| print('\nVerification Success! The inverter has updated its target.') | |
| else: | |
| print('\nVerification Failed: The value did not update to 20W.') | |
| client.close() | |
| else: | |
| print('Failed to connect to the inverter IP address.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment