wimb0 / home-assistant-saj-modbus Goto Github PK
View Code? Open in Web Editor NEWHome Assistant Component for reading data locally from SAJ R5 (and Zonneplan One) Inverters through modbus TCP.
License: MIT License
Home Assistant Component for reading data locally from SAJ R5 (and Zonneplan One) Inverters through modbus TCP.
License: MIT License
This custom integration uses deprecated DEVICE_CLASS_*
constants in its codebase.
The DEVICE_CLASS_*
constants have been deprecated and replaced in Home Assistant Core 2021.12 (over a year ago). I would highly suggest updating/migrating this integration to the new enums.
For example, for the device classes supported by the sensor
platform, there is now a SensorDeviceClass
enum. So if a sensor previously used the DEVICE_CLASS_ENERGY
constant, it should now use SensorDeviceClass.ENERGY
. Other platforms (like binary_sensor
, and number
) provide similar enumerations for their supported device classes.
The migration thus only consists of replacing constants with an enumeration member and is, therefore, very low impact and should be fairly straightforward.
If I can help resolve any questions regarding this change or migration, feel free to ask or respond to this issue. I'm happy to help!
Kindest regards,
../Frenck
I've been playing with the new Energy dashboard in Home Assistant 2021.8 and integration v1.5.0.
Apparently for the Solar production sensor to work, a new sensor which outputs kWh instead of W is needed.
It's not possible to select a live production value at the moment.
Will add a new sensor to fix this. Other ideas welcome!
ENERGY_KILO_WATT_HOUR was used from saj_modbus, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfEnergy.KILO_WATT_HOUR instead, please create a bug report at https://github.com/wimb0/home-assistant-saj-modbus/issues
FREQUENCY_HERTZ was used from saj_modbus, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfFrequency.HERTZ instead, please create a bug report at https://github.com/wimb0/home-assistant-saj-modbus/issues
POWER_WATT was used from saj_modbus, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfPower.WATT instead, please create a bug report at https://github.com/wimb0/home-assistant-saj-modbus/issues
TEMP_CELSIUS was used from saj_modbus, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTemperature.CELSIUS instead, please create a bug report at https://github.com/wimb0/home-assistant-saj-modbus/issues
TIME_HOURS was used from saj_modbus, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTime.HOURS instead, please create a bug report at https://github.com/wimb0/home-assistant-saj-modbus/issues
Will provide a PR
I would like to start to monitorize my SAJ inverter using node-red. To get the value of some item (for instance: "L2 voltaje") the pdf file show that it has the address 011CH. However that is an strange address, node-red only allows decimals numbers. Even that is not an hexadecimal value. Can you help me?
Hello, i'm trying to do a read of the rs485 port on the saj r5 inverter but dont get data, i wired the cable like you show in your image, their is a lot i can configur in the converter i'm using maybe i have a config issue. I use the USR-Tcp232-410s and it supports rs232, rs485 modbus rtu to modbus tcp.
Any advice?
Thanks anyway for this post .
I get this issue in the logs, but it could be related with the other issue I've mentioned in the past.
This error originated from a custom integration.
Logger: custom_components.saj_modbus.hub
Source: helpers/update_coordinator.py:315
integration: SAJ Inverter Modbus (documentation, issues)
First occurred: 7:30:35 PM (1 occurrences)
Last logged: 7:30:35 PM
Unexpected error fetching SAJ data: unpack requires a buffer of 4 bytes
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/saj_modbus/hub.py", line 95, in _async_update_data
realtime_data = await self.hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/saj_modbus/hub.py", line 166, in read_modbus_realtime_data
faultMsg0 = decoder.decode_32bit_uint()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pymodbus/payload.py", line 380, in decode_32bit_uint
handle = self._unpack_words(fstring, handle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pymodbus/payload.py", line 340, in _unpack_words
handle = unpack(f"!{wc_value}H", handle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 4 bytes
The integration works pretty well with the supplied instructions but the values are frequently set to 'unavailable' instead of the most recent read values. It seems its trying to read the modbus data to frequent and therefore fails, but this is a wild guess.
In the debug log I see the following ERROR frequently
023-04-19 09:42:41.445 ERROR (MainThread) [custom_components.saj_modbus.hub] Unexpected error fetching SAJ data: unpack requires a buffer of 4 bytes Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 250, in _async_refresh self.data = await self._async_update_data() File "/config/custom_components/saj_modbus/hub.py", line 79, in _async_update_data realtime_data = await self.hass.async_add_executor_job( File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/saj_modbus/hub.py", line 150, in read_modbus_realtime_data faultMsg0 = decoder.decode_32bit_uint() File "/usr/local/lib/python3.10/site-packages/pymodbus/payload.py", line 411, in decode_32bit_uint handle = self._unpack_words(fstring, handle) File "/usr/local/lib/python3.10/site-packages/pymodbus/payload.py", line 361, in _unpack_words handle = unpack(up, handle) struct.error: unpack requires a buffer of 4 bytes 2023-04-19 09:43:41.684 INFO (MainThread) [custom_components.saj_modbus.hub] Fetching SAJ data recovered
Is it possible to get a more detailed log file?
PS: Running on a SAJ inverted (Zonneplan provided) using an EW11A
Inverter shuts down when there is no sunlight.
The modbus adapter is connected to the inverter and is then offline.
Need to add better error handling when this happens.
Want set most of the the sensors to 0 and the inverter status to "Offline".
Hi, Many thanks for your work.
Writting from spain, I got a H1 Hybrid inverter. Do you have any experience with this version?
I've been told that terminal supports Modbus, but I'd need to take out the Wifi Antenna and then I'd loose the statistics and the portal of the manufacturer. The issue is that it refreshes every 5 minutes and I'd need something with about 5-10 seconds.
Thanks!
Hi, I have received from SAJ the H2 modbus document: https://drive.google.com/file/d/1IXDwdgg7BlkSw72qb2bc9Q5qTa4gidhJ/view?usp=drive_link
I wanted to understand if it is possible to integrate also H2 with this information in the Home assistant module.
Thank you.
Hello,
Maybe this is not really an issue with the integration itself, but I do not really know another place where I could possibly find help.
I am trying to use the Serial TCP / RS232 connection method via USB with the Elfin EW10A.
As stated in the integration, I would like to set the Data Bit value to 1. However, the Elfin EW10A only gives 2 options, 7 and 8.
(I guess as a result of this), I am not getting any data in Home Assistant.
Am I doing anything wrong? Or what could solve this?
Many thanks in advance for any reply!
Kind regards,
LTV8
hi, after an unwanted update from saj I find my integration made with nodered and mqtt no longer working. I therefore purchased the RS485 EW11 converter and connected it as per the diagram, however I cannot extrapolate any data that is familiar to me. I rechecked the device configuration and it is correct. Do you have any suggestions?
my inverter is h1 2x5kw batteries
first, to collect the data, I intercepted the mqtt packets sent from the wireless stick to the saj servers, converted the modbus registers and had all the values. Now it doesn't work anymore and the bad thing is that saj doesn't answer me in any way, whether by phone or email.
I thank everyone who will help me
Hi,
When I call the modbus integrations in the main config YAML file the SAJ stops working properly.
Is there a solution to fixes this problem, because I am very happy with your integration so if you can please help.
Everthing is up-to-date.
Used config in YAML:
`modbus:
Outcome of the falling SAJ integration
`Logger: homeassistant.setup
Source: setup.py:215
First occurred: 09:25:22 (1 occurrences)
Last logged: 09:25:22
Setup failed for custom integration saj_modbus: Unable to import component: Exception importing custom_components.saj_modbus
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/loader.py", line 818, in get_component
ComponentProtocol, importlib.import_module(self.pkg_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/config/custom_components/saj_modbus/init.py", line 16, in
from .hub import SAJModbusHub
File "/config/custom_components/saj_modbus/hub.py", line 13, in
from pymodbus.payload import BinaryPayloadDecoder
File "/usr/local/lib/python3.11/site-packages/pymodbus/payload.py", line 28, in
class BinaryPayloadBuilder:
File "/usr/local/lib/python3.11/site-packages/pymodbus/payload.py", line 42, in BinaryPayloadBuilder
self, payload=None, byteorder=Endian.Little, wordorder=Endian.Big, repack=False
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/enum.py", line 784, in getattr
raise AttributeError(name) from None
AttributeError: Little
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 215, in _async_setup_component
component = integration.get_component()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 826, in get_component
raise ImportError(f"Exception importing {self.pkg_path}") from err
ImportError: Exception importing custom_components.saj_modbus`
I have two SAJ inverters (via Zonneplan). I am very happy with the new Power Slider because I have issues with peak voltage (so I can now prevent it by using the Power Slider automatically). Both inverters easily reached the peak (Power Slider showed 100%), until I decided to actively use the Power Slider. When I set it to 100%, the peak was significantly lower for both inverters (luckily I don't have too many issues with peak voltage and can still reach most of the inverter's peak).
I have been working on the script myself to multiply the value passed through by 1.1. With that, I got the peak back for both inverters. The value behind the Power Slider was also set to 110%, even though the slider only goes up to 100%. Apparently, the inverters themselves are protected from going over their peak, and that protection is set higher than 100%. In short, I think many users lose their peak due to the Power Slider. If I experienced it with 2 out of 2 without ever doing anything myself, it might be a common problem. It could be a good solution for the overloaded grid, but I would prefer to leave that solution to the grid operator.
In addition, I have set the update time in the script to 10 seconds myself (it might even be possible to lower it further). This allows me to respond more quickly to peak voltage and greatly reduces the risk of outages. When the voltage goes above 251 volts, I decrease the power slider by 10% (1.1 times is 11%), and when it goes below 250 volts, I add 10% back. So far, this has prevented any outages, with three automatic 10% interventions to date. But the real test will come when the rain finally stops.
It would be great if you could more easily adjust the update time somewhere. But of course, that is just a luxury request.
Hello,
I don't see any other option to ask this way:
Let me know if I had to ask another way.
Is this method also possible for the Huawei SUN2000 (17)KTL-M0?
Can it be made suitable for the HUAWEI (I have no knowledge for this) ?
How should the wiring be connected for this with RJ45 4PIN Connector, see manuel pages 12 and 15 of the EW11A.
To support the new Energy dashboard the new state_class attribute needs to be set to measurement for some of the sensors.
Will provide a patch for this
I've noticed that from time to time, even without an error described in other bug reports my tesla-style-solar-power-card shows 0 for the PV production.
Not sure if there is something in how I compute the sensors, but this is the problem I see frequently when the saj modbus integration takes longer time (like multiple 5 seconds) to process the message.
Is it pissible to add the power slider?
Hi,
I am using the modbus integration for my SAJ R5 inverter and utilize the Elfin EW-11A as interface.
During the day multiple communication time-outs occur which are logged as follows:
2024-03-18 16:18:11.116 DEBUG (MainThread) [custom_components.saj_modbus.hub] Finished fetching SAJ data in 5.014 seconds (success: True)
2024-03-18 16:19:16.109 ERROR (SyncWorker_13) [pymodbus.logging] Connection to (192.168.50.233, 5555) failed: timed out
2024-03-18 16:19:16.112 ERROR (MainThread) [custom_components.saj_modbus.hub] Reading realtime data failed! Inverter is unreachable
What could be the reason of the timeouts?
I have connected the EW11 as described in the README with the SAJ providing the power. Is it better to use an external power supply?
When time-outs are happening the HA UI is partly frozen.
Thanks
Using an Elfin EW11A powered by my R5-5K-T2-15 SAJ Inverter RS485 serial port and after sunset, the modbus communication is no more possible.
In this state, there is a lot of error messages.
HA support device classes to give some more meaning to the sensor values: https://www.home-assistant.io/integrations/sensor/#device-class
Would be great if the power
, voltage
, current
and energy
sensors would report them self to HA with the device_class
.
I'm willing to create a PR for this if you are open for this change.
To be able to automatically turn off the inverter (e.g. when dynamic prices are negative), I'd like to use the 801FH
register (see page 20). Can you add that feature?
I just installed the saj-modbus plugin. But when I try to add a SAJ Inverter Modbus integration I get the following error:
Config flow could not be loaded: {"message":"Invalid handler specified"}
When I check in the log file I see the following to error logs:
Logger: homeassistant.loader
Source: lsiopy/lib/python3.11/site-packages/pymodbus/client/sync.py:183
First occurred: June 27, 2023 at 12:23:38 (2 occurrences)
Last logged: 11:07:40
Unexpected exception importing platform custom_components.saj_modbus.config_flow
Traceback (most recent call last):
File "/lsiopy/lib/python3.11/site-packages/homeassistant/loader.py", line 833, in get_platform
cache[full_name] = self._import_platform(platform_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lsiopy/lib/python3.11/site-packages/homeassistant/loader.py", line 850, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/config/custom_components/saj_modbus/__init__.py", line 16, in <module>
from .hub import SAJModbusHub
File "/config/custom_components/saj_modbus/hub.py", line 10, in <module>
from pymodbus.client.sync import ModbusTcpClient
File "/config/lsiopy/lib/python3.11/site-packages/pymodbus/client/sync.py", line 179, in <module>
class ModbusTcpClient(BaseModbusClient):
File "/config/lsiopy/lib/python3.11/site-packages/pymodbus/client/sync.py", line 183, in ModbusTcpClient
def __init__(self, host='127.0.0.1', port=Defaults.Port,
^^^^^^^^^^^^^
AttributeError: type object 'Defaults' has no attribute 'Port'
and
Logger: homeassistant.config_entries
Source: config_entries.py:863
First occurred: June 27, 2023 at 12:23:38 (2 occurrences)
Last logged: 11:07:40
Error occurred loading flow for integration saj_modbus: Exception importing custom_components.saj_modbus.config_flow
I'm running Home Assistant 2023.6.3 and HACS Integration version 1.32.1 and Frontend version: 20220906112053.
Any help is appreciated.
I've added a smart meter and a Saj SEC device, basically another Modbus reader.
The SEC device and the Elfin are both connected to the inverter RS485 lines. The Modbus addon works, now in Home Assistant I see the Inverter working, but it has many disconnects/communication blackouts.
Any idea how I should/could debug this?
All the thin gray lines at the end are disconnects.
SAJ Inverter status changed to Normal
7:06:17 PM - 3 minutes ago
SAJ Inverter status became unknown
7:05:47 PM - 3 minutes ago
SAJ Inverter status changed to Normal
7:03:02 PM - 6 minutes ago
SAJ Inverter status became unknown
7:02:32 PM - 6 minutes ago
SAJ Inverter status became unavailable
7:02:17 PM - 7 minutes ago
SAJ Inverter status changed to Normal
6:59:37 PM - 9 minutes ago
SAJ Inverter status became unknown
6:59:22 PM - 10 minutes ago
SAJ Inverter status became unavailable
6:59:07 PM - 10 minutes ago
SAJ Inverter status became unknown
6:58:52 PM - 10 minutes ago
SAJ Inverter status changed to Normal
6:55:27 PM - 13 minutes ago
SAJ Inverter status became unknown
6:54:42 PM - 14 minutes ago
SAJ Inverter status became unavailable
6:54:27 PM -
My inverter is SAJ R5-10K-T2. I'm waiting for the smart meter for this to arrive, I believe the Smart Meter compatible with this is actually a Chint DTSU-666.
I was under the impression that the Smart Meter is actually sending the stats over RS485 (not sure if in Modbus) to the inverter, and the inverter only reads this data.
For this project for home assistant is the elfin device required, or I can read the data directly in Raspberry pi with a USB to RS485 adapter? In this case does that imply that the inverter not only reads data from the smart meter, but also broadcasts his own info to other device?
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.