alangibson / homeassistant-sungrow Goto Github PK
View Code? Open in Web Editor NEWSungrow Inverter integration for Home Assistant
Sungrow Inverter integration for Home Assistant
... now what? Sorry if this is an absolute newbie question but what should happen now? What else do I need to configure after adding the integration as instructed to be able to read values from my inverter? What am I supposed to do?
OK, I need to configure a couple of things manually I guess...
Well, I set up a config.yaml which is working for my local SunGather clone in combination with my inverter but here nothing happens. Nothing pops up in Home Assistant. What have I missed?
Integrations should be configurable.
Just collecting ideas:
Please let me know how can I try to fix manualy at least " total_battery_charge_energy_from_pv" - so I could have proper data in HA energy card. Everything else is read OK,
Logger: custom_components.sungrow.sensor
Source: custom_components/sungrow/sensor.py:210
Integration: Sungrow (documentation)
Sensor lookup value is not available in data array: daily_battery_charge_energy_from_pv
Sensor lookup value is not available in data array: total_battery_charge_energy_from_pv
Sensor lookup value is not available in data array: daily_export_power_from_pv
Sensor lookup value is not available in data array: total_export_power_from_pv
Sensor lookup value is not available in data array: meter_power
I'm connected via http mode
Hi Guys.
Happy I stumbled upon this. I have a SG10RT and looks like the sensors are collecting information bar a few of them.
I want to set this up in the energy section of home assistant, but I get errors when adding feeds for sensors to:
What are the correct sensors, I should be using?
If I take a look at the integration the following date points appear to be right.
Any guidance is appreciated.
If I add in say sensor.sg10rt_a2313001072_daily_direct_energy_consumption to Grid consumption, I get an error:
statistics_not_defined
sensor.sg10rt_a2313001072_daily_direct_energy_consumption
Entity unavailable
The state of these configured entities are currently not available:
sensor.sg10rt_a2313001072_daily_direct_energy_consumption (unknown)
Appreciate the work. I can’t load config flow however. Getting the above error message.
Cheers
Things like "Unknown Type Code Detected" should not be hidden in the log after seemingly successfully adding a device.
Although some kind of bug or whatever.... anyway unique_id should be ensured before adding the device.
Thank you for your work, at the moment is not possible to add more then one sungrow inverter. I have 2 sungrow inverter 1x sg40cx + 1x sg50cx.
Scenario: enter incorrect ip, port, select modbus etc...
Click Submit
The form resets. No instead of fixing the port, I have to do everything again.
I've started a fork to create some pull requests. Which was fine for a while. But much sooner than anticipated my code diverged significantly. I've also addressed this in Discord with @mkraiser and @bohdan-s, so far there is no clear statement on their side. From the looks of it @bohdan-s doesn't have much time either way, while @mkaiser might jump on.
Anyway, back to our repos: by now there is not a single line in common between them. That's not intentional! But a byproduct of many many refactorings.
Differences:
Link: https://github.com/AlexanderLanin/homeassistant-sungrow
Defaults/explanations could be better:
Default connection type in https://github.com/bohdan-s/SunGather/blob/main/SunGather/config-example.yaml is modbus
Default port therefore 502. Can you add a comment explaining the different default ports?
Inverter model is missing a hint that this should/can be kept empty
Connection timeout 10 vs 3
Hostname/Port should contain "of Inverter"
"Data request level" is missing any explanation. Can you make it a selection like "Connection Type"?
Hi,
When installing integration this error comes up:
{"message":"Invalid handler specified"}
And i stops there. Any suggestions?
Logger: homeassistant.config_entries
Källa: config_entries.py:2444
Inträffade först: 10:35:16 (1 händelser)
Senast loggade: 10:35:16
Error occurred loading flow for integration sungrow: cannot import name 'Defaults' from 'pymodbus.constants' (/usr/local/lib/python3.12/site-packages/pymodbus/constants.py)
Currently "only" ~30 registers are supported.
Yaml has many more...
At least on "level" 3 everything should be added.
As per title. I would like to set the scan interval lower when charging my car. It is not available as a config option in the UI.
I need some help with the development environment.
In the end we could document how to do this, so this ticket has real benefit :-)
Option: Studio Code Server Addon
Pro: Super Easy
Con:
Option: Terminal & SSH Addon + Local VS Code instance connected via SSH
Pro: all extensions available (e.g. GitHub Copilot)
Con:
Option: work on branch and reload integration in home assistant via HACS
(not yet attempted)
Option: work locally and copy files via bash script over SSH
(not yet attempted. Sounds promising!)
Is there some more clever way? Since home assistant core seems to have a full development environment ready to use...
I have looked at all the IP's connected to my router and when I input them during the configuration they all fail, saying the inverter wasn't found. I know it is just me being dense but I just can't work this out.
I wrote a little proof of concept which works fine for me. In its current state it takes ~20 seconds to run for a single IP and it does find my inverters. Not sure why it takes that long.
Does it make sense to pursue this further?
Maybe there can be two options to add devices, a simple and a manual one?
Assuming we somehow get the IP-Address, we could extend this to proper auto detection...
Output:
Running Sungrow auto detection on 192.168.13.79...
Found 2 inverter(s):
A2350415770 (Type 0xe12) at 192.168.13.79:502 (unit 1) via modbus
A2350415770 (Type 0xe12) at 192.168.13.79:502 (unit 1) via sungrow
Running Sungrow auto detection on 192.168.13.80...
Found 2 inverter(s):
A2350415779 (Type 0xe12) at 192.168.13.80:502 (unit 2) via modbus
A2350415779 (Type 0xe12) at 192.168.13.80:502 (unit 2) via sungrow
Note: for me sungrow works <50% of the time, while modbus is reliable.
(edit: Actually "sungrow" is not maintained anymore. Doesn't even make much sense to keep it?!)
For reference here is the script:
#!/usr/bin/env python3
from pprint import pprint
from pymodbus.client.sync import ModbusTcpClient
from SungrowModbusTcpClient.SungrowModbusTcpClient import SungrowModbusTcpClient
from SungrowModbusWebClient.SungrowModbusWebClient import SungrowModbusWebClient
from concurrent.futures import ThreadPoolExecutor
from queue import Queue
import logging
logger = logging.getLogger(__name__)
def try_connect_and_find_correct_unit(
exectutor: ThreadPoolExecutor, client_class, connection_type: str, host, port
):
"""Try to connect to the inverter and find the correct unit id."""
successfull_connections = []
try:
client = client_class(host=host, port=port)
if client.connect():
logger.debug(
f"{connection_type} connected to {host}:{port}. Looking for unit id..."
)
future = {}
# It seems that usually the unit is 1 or 2, so scanning 1-4 should be enough
for unit in range(1, 5):
# Note: The serial number is stored in the inverter at address 4990 (-1), and is 10 bytes long.
# Right after the serial number, we have the device type, which is 2 bytes long.
future[unit] = exectutor.submit(
client.read_input_registers,
4989,
count=11,
unit=unit,
retries=1,
timeout=3,
)
for unit in range(1, 5):
result = future[unit].result()
if not result.isError():
# Decode the serial number as UTF-8
serial_number = "".join(
[chr(c >> 8) + chr(c & 0xFF) for c in result.registers[:10]]
).strip("\x00")
device_type = hex(result.registers[10])
successfull_connections.append(
{
"connection_type": connection_type,
"host": host,
"port": port,
"unit": unit,
"serial_number": serial_number,
"device_type": device_type,
}
)
logger.debug(f"Found valid unit: {successfull_connections[-1]}")
client.close()
except Exception as e:
logger.debug(f"Exception in try_connect: {e}")
return successfull_connections
def scan_ip(ip):
with ThreadPoolExecutor() as ex:
modbus = ex.submit(
try_connect_and_find_correct_unit,
ex,
ModbusTcpClient,
"modbus",
ip,
port=502,
)
http = ex.submit(
try_connect_and_find_correct_unit,
ex,
SungrowModbusWebClient,
"http",
ip,
port=8082,
)
# SungrowModbusTcpClient cannot run in parallel with ModbusTcpClient!
# The inverter then drops all connections.
modbus.result()
sungrow = try_connect_and_find_correct_unit(
ex, SungrowModbusTcpClient, "sungrow", ip, port=502
)
successfull_connections = modbus.result() + http.result() + sungrow
return successfull_connections
def scan_and_print(host):
print(f"Running Sungrow auto detection on {host}...")
scan_result = scan_ip(host)
print(f"Found {len(scan_result)} inverter(s):")
for inverter in scan_result:
print(
f" {inverter['serial_number']} (Type {inverter['device_type']}) at {inverter['host']}:{inverter['port']} (unit {inverter['unit']}) via {inverter['connection_type']}"
)
if __name__ == "__main__":
logging.basicConfig()
logger.setLevel(logging.INFO)
scan_and_print("192.168.13.79")
scan_and_print("192.168.13.80")
Hi there,
I just saw in the log that this happened:
DEVICE_CLASS_ENERGY was used from sungrow, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.ENERGY instead, please report it to the author of the 'sungrow' custom integration ENERGY_KILO_WATT_HOUR was used from sungrow, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfEnergy.KILO_WATT_HOUR instead, please report it to the author of the 'sungrow' custom integration POWER_WATT was used from sungrow, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfPower.WATT instead, please report it to the author of the 'sungrow' custom integration DEVICE_CLASS_POWER was used from sungrow, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.POWER instead, please report it to the author of the 'sungrow' custom integration
At least to me it seems that this should be updated in source code. As far as I can see, anything could be changed accordingly in config.py.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.