Custom Component: Generic SunSpec modbus TCP monitoring (inverter, meter etc)

I don’t think you have to do anything, it’s their fault not following the specs. I still have to check with other users that have different models what comes up. Maybe it’s only for “old” inverters like mine, which is a 2013 model with the same fw of 2013.

I found the code and a device_info() for each sensor, but I don’t quite get how to modify it to add the two fields I want to the device info section. It’s my fault, I’m not a programmer…last time I developed something was 25y ago. But I’m having fun again trying to make things work…with some help by kind people like you. :slight_smile:

I don’t want to hijack your thread with my issues, maybe I’ll write you privately…thanks as always, you are very kind.

1 Like

Hi Johan,

when the inverter is off, I have a lot of these in the logs. Obviously I expect connection errors, but I think there’s some other issues. Hope it helps.

2021-06-17 01:04:39 ERROR (MainThread) [custom_components.sunspec] Socket write error: [Errno 32] Broken pipe
2021-06-17 01:04:42 ERROR (MainThread) [custom_components.sunspec] Unexpected error fetching sunspec data: Connection error: [Errno 113] Host is unreachable
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/modbus.py", line 515, in _read
    self.socket.sendall(req)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/config/custom_components/sunspec/__init__.py", line 118, in _async_update_data
    data[model_id] = await self.api.async_get_data(model_id)
  File "/config/custom_components/sunspec/api.py", line 88, in async_get_data
    return await self.read(model_id)
  File "/config/custom_components/sunspec/api.py", line 91, in read
    return await self._hass.async_add_executor_job(self.read_model, model_id)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sunspec/api.py", line 126, in read_model
    model.read()
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/client.py", line 85, in read
    data = self.model.device.read(self.model.model_addr + self.offset, self.len)
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/client.py", line 317, in read
    return self.client.read(addr, count, op)
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/modbus.py", line 584, in read
    data = self._read(addr + read_offset, read_count, op=op)
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/modbus.py", line 517, in _read
    raise ModbusClientError('Socket write error: %s' % str(e))
sunspec2.modbus.modbus.ModbusClientError: Socket write error: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/modbus.py", line 481, in connect
    self.socket.connect((self.ipaddr, self.ipport))
OSError: [Errno 113] Host is unreachable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/sunspec/__init__.py", line 123, in _async_update_data
    self.api.reconnect()
  File "/config/custom_components/sunspec/api.py", line 108, in reconnect
    client.connect()
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/client.py", line 308, in connect
    self.client.connect()
  File "/usr/local/lib/python3.8/site-packages/sunspec2/modbus/modbus.py", line 483, in connect
    raise ModbusClientError('Connection error: %s' % str(e))
sunspec2.modbus.modbus.ModbusClientError: Connection error: [Errno 113] Host is unreachable

Is there any benefits over the other custom ModBus integrations already in HomeAssistant?

I have been using the SolarEdge ModBus integration to good effect, allows 5 second intervals between readings.

Not really, if the other component gives you all the data that you care about. This component aims to work with all SunSpec compliant devices and lets you choose to collect all available data that they offer. Scan interval is configurable in the UI.

Hi for all!
I have installed a smart meter (B21 112-100) on my ABB UNO Dm inverter.
I use successfully this integration on Home Assistant, but I ask if is any solution to read the smart meter registers?!

Hello Alexe!
I had a look at the spec sheet for the meter and it doesn’t look like it’s supporting SunSpec unfortunately, so this integration will not work with it. It does suport modbus over serial, so if you can hook it up to HA via a serial interface you might be able to use the generic modbus integration to read data from it.

1 Like

Thank you for the quick answer!
The smart meter is connected with serial interface rs485 to inverter and I see it’s parameters on inverter interface (web, app).
I don’t know how to link the meter to HA, without the inverter.
I was tried to get the meter with the generic modbus TCP integration, but with no response.
If any of you have an idea, I will be grateful.
Thanks again!

Sorry if I made off topic !

Aha, then it might actually be possible that the inverter makes the meter data available through it’s own modbus registers. Have you checked the available models in the configuration step? Not all are enabled by default.
Another possibility is that it makes the meter registers available on a different slave id, in that case you need to add a new SunSpec integration with that slave id.
Does the manual mention anything about the meter and modbus/sunspec?

I checked all the registers in the sunspec integration, but I did not find references to the meter parameters. I have a list of meter registers that are not in the sunspec list. ex: Active import -20480 (5000 in hex); Active export -20483 (5004 in hex) …etc.
I’m still looking!

Hello

I’m just new to HA, as i am migrating my openhab system to HA. I’ve just installed the sunspec integration, but i’ve got stuck with the connection part to my invertor.
In my previous system i used the same IP, port and Id and that worked.
In HA i get ‘Failed to connect, check hostname and port’
I’ve tried using the hostname, restarted HA, but with same result.
Does anyone has a clou?


Thanks

Hello @woutike !
Connection issues are not so easy to help with, so many things can go wrong.
Can you have a look in the logs and see if there is any error with sunspec in it?
You can find it Configuration → Logs
If you have cli access to the machine running HA, can you log in there and ping the IP?

I’ve a Fronius and a SolarEdge inverter. I’ve installed the custom SunSpec integration for both inverters. During the night I got a lot of errors every 30 seconds. I think the Fronius inverter is responsible for those errors but I’m not sure.

2021-09-01 21:07:45 ERROR (MainThread) [homeassistant.components.fronius.sensor] Failed to update: connection error
2021-09-01 21:08:22 WARNING (MainThread) [custom_components.sunspec] timed out
2021-09-01 21:08:24 ERROR (MainThread) [custom_components.sunspec] Unexpected error fetching sunspec data: Connection error: [Errno 113] Host is unreachable
Traceback (most recent call last):
File "/config/custom_components/sunspec/__init__.py", line 128, in _async_update_data
data[model_id] = await self.api.async_get_data(model_id)
File "/config/custom_components/sunspec/api.py", line 86, in async_get_data
return await self.read(model_id)
File "/config/custom_components/sunspec/api.py", line 89, in read
return await self._hass.async_add_executor_job(self.read_model, model_id)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/sunspec/api.py", line 132, in read_model model.read()
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/client.py", line 85, in read 
data = self.model.device.read(self.model.model_addr + self.offset, self.len)
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/client.py", line 317, in read
return self.client.read(addr, count, op)
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/modbus.py", line 584, in read
data = self._read(addr + read_offset, read_count, op=op)
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/modbus.py", line 520, in _read
c = self.socket.recv(len_remaining)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/modbus.py", line 481, in connect
self.socket.connect((self.ipaddr, self.ipport))
OSError: [Errno 113] Host is unreachable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
self.data = await self._async_update_data()
File "/config/custom_components/sunspec/__init__.py", line 133, in _async_update_data
self.api.reconnect()
File "/config/custom_components/sunspec/api.py", line 106, in reconnect
client.connect()
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/client.py", line 308, in connect
self.client.connect()
File "/usr/local/lib/python3.9/site-packages/sunspec2/modbus/modbus.py", line 483, in connect
raise ModbusClientError('Connection error: %s' % str(e))
sunspec2.modbus.modbus.ModbusClientError: Connection error: [Errno 113] Host is unreachable
2021-09-01 21:08:54 WARNING (MainThread) [custom_components.sunspec] Socket write error: [Errno 32] Broken pipe
2021-09-01 21:08:57 ERROR (MainThread) [custom_components.sunspec] Unexpected error fetching sunspec data: Connection error: [Errno 113] Host is unreachable

What is wrong?

The inverter is probably configured to turn itself off when there is no DC current. This also turns off the IP interface. There is a setting to keep it running - I think its called “night mode” or something like that.

How is it possible to customize the sensors? Is it done via the “read models” setting in the integration configuration?
Just wanting to be sure I don´t miss any sensors as I do not see any sensors regarding my batteries connected to the inverter.

Read models in config lets you select what data registers you want to use, so there is a chance that your battery data is available and can be enabled in there, you can always try to enable all of them and see if anything interesting shows up (should be models above at least 400 i think).
Some vendors can also have separate slave id’s for different data, if you can find documentation for your device it might tell you if that is the case.
Good luck!

The night mode was turned off. So that could not be the problem.

image

Hi,
I’m also struggling with the connection.
I used ‘QModMaster’ as earlier in the discussion.
image
my inverter is ABB PVI 3.6 OUTD met VSN300 wifi logger
How can i get this working in HA.
In the log from HA I see :
2021-10-13 11:07:21 ERROR (MainThread) [custom_components.abb_powerone_pvi_sunspec] Reading data failed! Inverter is unreachable on ID=247
2021-10-13 11:07:24 ERROR (MainThread) [custom_components.abb_powerone_pvi_sunspec] Reading data failed! Inverter is unreachable on ID=247

I have changed to ID=2 and startadres 70.
I get these errors :
2021-10-13 13:41:45 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up abb_powerone_pvi_sunspec platform for sensor
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 249, in _async_setup_platform
await asyncio.shield(task)
File “/config/custom_components/abb_powerone_pvi_sunspec/sensor.py”, line 20, in async_setup_entry
hub.read_modbus_data_inverter()
File “/config/custom_components/abb_powerone_pvi_sunspec/init.py”, line 253, in read_modbus_data_inverter
comm_manufact = decoder.decode_string(size=32).decode(“ascii”)
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xff in position 4: ordinal not in range(128)

THX

It’s ok
after extra reading i have set the regitry on 0 and everything comes in.

The thread for my component is here: Custom Component: ABB/Power-One/FIMER PV Inverters - SunSpec Modbus TCP

You’ll find the instructions to configure the VSN300 in the first post. I use the VSN300.

I was about to start developing a general sunspec plugin when I found this thread.
Good work. Will test the plugin in future thoroughly.
We should continue to develop this plugin with combined force and replace the other Modbus Sunspec inverter plugins like solaredge-modbus
Maybe @erikarenhill is also interested in this?

1 Like