Upload script for Huawei SUN2000 WiFi inverters

Hi all,

I wrote a little python script that can poll your Huawei SUN2000 inverter via its WiFi/modbus interface and upload the data to PVOutput:

https://github.com/init4/huawei_pvoutput/

Hopefully someone finds it useful…

5 Likes

I have made a script with Chatgpt,
— maybe this wil work to –

#!/opt/homebrew/bin/python3

-- coding: utf-8 --

import requests
import datetime
from huawei_solar import HuaweiSolar

try:
# Initialize HuaweiSolar instance
c = HuaweiSolar(host=“192.168.200.1”, port=6607)
except Exception as e:
print(“Error initializing HuaweiSolar:”, str(e))
exit(1)

PVOutput API-instellingen

apikey = “YourAPI” # Vervang met je API-sleutel
system_id = “Yoursystem_id” # Vervang met je System ID

Get current date and time

current_timestamp = datetime.datetime.now()
current_date = current_timestamp.strftime(’%Y%m%d’)
current_time = current_timestamp.strftime(’%H:%M’)

Get interesting data from the HuaweiSolar instance

try:
input_power = c.get(“input_power”)[0]
grid_voltage = c.get(“grid_voltage”)[0]
internal_temperature = c.get(“internal_temperature”)[0]
daily_yield_energy = c.get(“daily_yield_energy”)[0]

# Convert daily_yield_energy from kWh to Wh
daily_yield_wh = daily_yield_energy * 1000

# Formatteer de data voor PVOutput
data = {
    "d": current_date,  # Datum in YYYYMMDD
    "t": current_time,  # Tijd in HH:MM
    "v1": int(daily_yield_wh),  # Dagopbrengst in Wh
    "v2": int(input_power),  # Huidige productie in Watt
    "v5": float(internal_temperature),  # Interne temperatuur (optioneel)
    "v6": float(grid_voltage)  # Netspanning (optioneel)
}

# Headers voor authenticatie
headers = {
    "X-Pvoutput-Apikey": apikey,
    "X-Pvoutput-SystemId": system_id
}

# Upload de data naar PVOutput
try:
    response = requests.post("https://pvoutput.org/service/r2/addstatus.jsp", headers=headers, data=data)
    if response.status_code == 200:
        print("Data succesvol geupload naar PVOutput.")
    else:
        print(f"Fout bij het uploaden naar PVOutput: {response.status_code} - {response.text}")
except Exception as e:
    print("Fout bij het verbinden met PVOutput:", str(e))

except Exception as e:
print(“Error retrieving data from HuaweiSolar:”, str(e))
exit(1)

print(“Data die naar PVOutput wordt geupload:”, data)
print(“Response van PVOutput:”, response.status_code, response.text)