Solaredge Modbus Configuration for Single Inverter and Battery

Hi there, every time I’m using this integration I’m getting the following error one time:

This error originated from a custom integration.

Logger: custom_components.solaredge_modbus
Source: custom_components/solaredge_modbus/__init__.py:232
Integration: SolarEdge Modbus
First occurred: 17:47:49 (1 occurrences)
Last logged: 17:47:49

Error reading modbus data
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/solaredge_modbus/__init__.py", line 232, in async_refresh_modbus_data
    update_result = self.read_modbus_data()
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/solaredge_modbus/__init__.py", line 307, in read_modbus_data
    self.read_modbus_data_inverter()
  File "/home/homeassistant/.homeassistant/custom_components/solaredge_modbus/__init__.py", line 593, in read_modbus_data_inverter
    inverter_data = self.read_holding_registers(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/solaredge_modbus/__init__.py", line 291, in read_holding_registers
    return self._client.read_holding_registers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/client/mixin.py", line 102, in read_holding_registers
    return self.execute(
           ^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/client/base.py", line 177, in execute
    if self.use_sync:
               ^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/transaction.py", line 168, in execute
    response, last_exception = self._transact(
                               ^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/transaction.py", line 313, in _transact
    result = self._recv(response_length, full)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/transaction.py", line 343, in _recv
    read_min = self.client.framer.recvPacket(min_size)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/framer/base.py", line 77, in recvPacket
    return self.client.recv(size)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/client/tcp.py", line 210, in recv
    ready = select.select([self.socket], [], [], end - time_)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pymodbus/client/tcp.py", line 257, in _handle_abrupt_socket_close
    if data:
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] ModbusTcpClient(192.168.0.154:502): Connection unexpectedly closed 4.291534423828125e-05 seconds into read of 8 bytes without response from slave before it closed connection

Apart of that, it works fine. Is there anything I can do the elimiate this error?

Look a couple of posts above yours - e.g. to this one. Follow the answers down. I have a longer one with some logging-experiments here.

I have tried a couple of things like the author of this plugin suggests here. But have concluded in the end that my inverter likes to reset itself twice a day, which makes the connection fail - and there is nothing I can do about it, except work around the problem in my automations. I don’t mind the error-message particularily much - but the inverter also resets some internal states, which I then have to set again (e.g. battery discharge state). This is a bit of a pain, but you can work around that by reacting in your automations to the inverter posting its values again to the sensors.

1 Like

You actually aren’t using my integration. To avoid those errors I recommend trying my integration which is SolarEdge Modbus Multi.

1 Like

You are so right, I am sorry! I’m using

https://github.com/binsentsu/home-assistant-solaredge-modbus

and not your

https://github.com/WillCodeForCats/solaredge-modbus-multi

Let me change that! :slight_smile:

I see this dashboard approach uses the power values retrieved from Solaredge.
I have this running for more than a year, but the difference with the Solaredge app is quite big.
I am now trying to achieve the same by using the retrieved energy values. Did anybody already achieved this?

I am still struggling to calculate the real solar production.
My battery is sometimes charging from the grid, and that makes it difficult

1 Like

I am facing the same problem. I think I could do the energy calculations for all directions if only there is a register that says how much energy SolarEdge inverter has imported from AC side (which means charging battery from grid). As of now there is only a register that contains lifetime production (exported energy) and it is a sum of energy from panels and battery.

SE will release an updated note with modbus registers but date is not know yet per their support. I am hoping that this info will be added. Just recently my AC power register finally went into negative value when charging battery from grid. I can calculate correctly power when it comes to household consumption excluding the power for battery charging from grid.

I have also requested guidance (register number) on reliable way of detecting grid loss - I have a backup system too and setting battery reserve via modbus. This is not documented in their notes as of now, but configurable in their mobile app.

I use the solaredge-modbus-multi integration alongside a modbus-proxy container so that I can access the data separately also. It’s been rock solid for months. Yesterday my installer had to change a setting and his app forced him to update the firmware on the inverter. Since then, the modbus-proxy has stopped responding about 5 times in 24 hours, so HA just stops receiving any data from the inverter. The only fix is to restart the modbus-proxy container (which hasn’t changed at all by the way).

Has anyone else encountered this problem? I’m wondering if they increased the timeouts or something? I use ethernet so it’s not a WiFi issue.

The firmware update is optional. When you open SetApp (the app for installation), the app automatically downloads the latest version of firmware. However, the installer can skip the update process and just continue with whatever it is they need to do.

Solaredge recommends updating the firmware only if there are issues, otherwise, leave it alone.

Your installer should know that.

Yeah they are not very well versed with SolarEdge equipment it seems. I just checked HA and it looks like the version reported by the inverter only changed at 20:44 last night, more than 30 hours after the update was done. It’s now version 4.19.36, it was 4.17.221 before.

I was hoping the issues were caused by the inverter timing out due to being busy installing the update or something, but modbus-proxy has lost connection once since then. I have increased the “timeout” to 15s and “connection time” to 0.5s to see if that helps at all.

SolarEdge say nothing relating to modbus via TCP has changed and suggests checking the cables. Useless.

I think I need some kind of automated way to restart the modbus connection if it stops responding, but I don’t think the proxy has that feature built-in.

As I am currently trying to set up a similar system, I’d be interested in seeing your solution!

In my current setup I’m running an automation that sets the storage command and storage default mode to “solar only” if the forecasted production for the day is less than a fixed number, else the setting is maximize self consumption.

However, this does not help with discharges of the battery…

Several people have reported issues with meter energy values after updating to the latest firmware.

I have been offered a downgrade to 4.18.32 but apparently they can’t downgrade me back to 4.17.221, which is quite annoying. If that doesn’t resolve the issue then I’ll just have to push them to investigate fix the issue but I suspect that’ll take months.

I’ve had no modbus issues for 36 hours now, so it seems as if the downgrade worked.

Hello WillCodeForCats,

fyi: I have just upgraded to HA 2024.1.0 and have received this message during start-up:

2024-01-04 14:34:58.569 WARNING (MainThread) [homeassistant.const] TIME_SECONDS was used from solaredge_modbus_multi, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTime.SECONDS instead, please create a bug report at Issues · WillCodeForCats/solaredge-modbus-multi · GitHub

This was updated in v2.4.8-pre.2 since I missed it when all the others were changed.

1 Like

In Release v2.4.8-pre.1 there is a potentially backwards incompatible change to the Energy sensors to better fit today’s Home Assistant.

  1. The entity names for Energy sensors will no longer have kwh in them by default.

The reason kwh should be removed from the name is because this is no longer strictly true. The inverter actually uses watt-hours and previously the entity would statically scale to kWh. However at some point Home Assistant updated to allow entities to be dynamically configured for units and precision through the UI, so now anyone can choose to see energy in Wh, kWh, MWh, whatever units HA supports for Energy class sensors. So having a sensor name with kwh in it is no longer appropriate when it could be several other supported units for its class.

This can be backwards compatibility breaking but it depends: existing energy sensor entities with kwh in the name won’t change on simple upgrades to the current version of the integration.

The name will change to the new default if you remove and re-add the integration or device. New users will notice if they installed a version after v2.4.8 for the first time that their Energy sensor names don’t end with kwh and templates will need to be adjusted to remove kwh from the name.

I don’t know if there’s a way to set up templates to look for both the old and new sensor entity names (with a name ending in kwh or not). If there is this would make it easier to accommodate existing and new users without template changes.

I don’t like making breaking changes, but sometimes it turns out that decisions made in the past that were good for the time don’t always fit long term. I like that HA added these features to change between units dynamically, but I wish I’d named my entities better to consider that.

  1. Internally the native unit for energy will be watt-hours.

The inverter’s native units when reading it over modbus is watt-hours. The default suggested unit will still be kWh so it won’t appear anything has changed other than the name, and let Home Assistant to do the unit conversions and remove any hardcoded unit conversions.

This shouldn’t affect anyone, but I’m mentioning it just in case.

1 Like

Thanks for the info!

I am trying to setup PV / Solar Excess Optimizer Blueprint and wondering if I am missing something with the Modbus integration.

Is there a dedicated Export, Load and Combined Import/Export Power sensor? I can see some of these in the standard SolarEdge integration but they only update every 15 minutes. I have setup the last one using a template sensor based off the sensor.solaredge_m1_ac_power entity but not sure about the others.

The blueprint states:

  • Export Power: Sensor which contains your current export power to the grid in watts. Must not be negative! For best results, this sensor should be updated at least every minute.

  • Load Power: Sensor which contains your current load power (combined household appliance consumption without home battery charging consumption ) in watts. Must not be negative! For best results, this sensor should be updated at least every minute.

  • Combined Import/Export Power: Sensor which contains both , your current import power from the grid (positive values) and your current export power to the grid in watts (negative values). For best results, this sensor should be updated at least every minute.

Edit - sorted the Export Power sensor, just no idea how to get the load power as circled below

1 Like

You will need to calculate load (consumption) based on the values of import/export and production if you don’t have a dedicated consumption meter.

I’m sure that’s already done in a template in this thread somewhere.

1 Like

I’m looking for help with some battery info (since I don’t have batteries).

I want to know if the device attributes (for entity sensor.solaredge_b1_device) are fixed values or of they can change over time. The documentation calls them “battery nameplate information” which means to me that nameplate values should never change as if they are printed or attached to the device itself, and why I chose to implement them as attributes of the device.

However, if they can change over time, ones that can change should probably be added as their own sensor entities for statistics instead of attributes. These are the attributes I’m looking at:

  • batt_charge_peak
  • batt_discharge_peak
  • batt_max_charge
  • batt_max_discharge
  • batt_rated_energy

Thanks got an answer on another thread with the exact templates. Posting here incase anyone needs in the future - template sensors

1 Like