Skip to content

Commit

Permalink
Merge branch 'main' into modbus-string-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCodeForCats committed Dec 20, 2024
2 parents 9066392 + 5691b56 commit 6398d2f
Show file tree
Hide file tree
Showing 22 changed files with 516 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: WillCodeForCats/python-lint-action@v1.0.7
- uses: WillCodeForCats/python-lint-action@v1.0.9
with:
python-root-list: "custom_components/solaredge_modbus_multi"
use-flake8: true
Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

# SolarEdge Modbus Multi

Home Assistant integration `solaredge-modbus-multi` supports SolarEdge inverters with Modbus/TCP local polling. It works with single inverters, multiple inverters, meters, batteries, and many other improvements over other integrations that didn't work well with a multi-device setup.

It is designed to communicate locally using Modbus/TCP where you have a single Leader inverter connected with one or more Follower inverters chained using the RS485 bus. Each inverter can connect to three meters and two batteries.

Simple single inverter setups are fully supported - multiple devices is a feature, not a requirement.
This integration provides Modbus/TCP local polling to one or more SolarEdge inverters for Home Assistant. Each inverter can support three meters and three batteries over Modbus/TCP. It works with single inverters, multiple inverters, meters, and batteries. It has significant improvements over similar integrations, and `solaredge_modbus_multi` is actively maintained.

### Features
* Inverter support for 1 to 32 SolarEdge inverters.
Expand All @@ -20,20 +16,20 @@ Simple single inverter setups are fully supported - multiple devices is a featur
* Connects locally using Modbus/TCP - no cloud dependencies.
* Informational sensor for device and its attributes
* Supports status and error reporting sensors.
* User friendly configuration through Config Flow.
* User friendly: Config Flow, Options, Repair Issues, and Reconfiguration.

Read about more features on the wiki: [WillCodeForCats/solaredge-modbus-multi/wiki](https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki)

Note: The modbus interface currently only defines up to 2 batteries per inverter (even if the SolarEdge cloud monitoring platform shows more).

## Installation
Install with [HACS](https://hacs.xyz): Search for "SolarEdge Modbus Multi" in the default repository,

[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=WillCodeForCats&repository=solaredge-modbus-multi&category=integration)

OR

Copy the `solaredge_modbus_multi` folder into to your Home Assistant `config/custom_components` folder.
Download the [latest release](https://github.com/WillCodeForCats/solaredge-modbus-multi/releases) and copy the `solaredge_modbus_multi` folder into to your Home Assistant `config/custom_components` folder.

After rebooting Home Assistant, this integration can be configured through the integration setup UI.
After rebooting Home Assistant, this integration can be configured through the integration setup UI. It also supports options, repair issues, and reconfiguration through the user interface.

### Configuration
[WillCodeForCats/solaredge-modbus-multi/wiki/Configuration](https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki/Configuration)
Expand All @@ -42,9 +38,9 @@ After rebooting Home Assistant, this integration can be configured through the i
[WillCodeForCats/solaredge-modbus-multi/wiki](https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki)

### Required Versions
* Home Assistant 2024.4.0 or newer
* Home Assistant 2024.9.0 or newer
* Python 3.11 or newer
* pymodbus 3.6.6 or newer
* pymodbus 3.6.6 through 3.7.4

## Specifications
[WillCodeForCats/solaredge-modbus-multi/tree/main/doc](https://github.com/WillCodeForCats/solaredge-modbus-multi/tree/main/doc)
Expand Down
66 changes: 51 additions & 15 deletions custom_components/solaredge_modbus_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import asyncio
import logging
from datetime import timedelta
from typing import Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, Platform
Expand All @@ -16,7 +14,7 @@
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import DOMAIN, ConfDefaultInt, RetrySettings
from .const import DOMAIN, ConfDefaultInt, ConfName, RetrySettings
from .hub import DataUpdateFailed, HubInitFailed, SolarEdgeModbusMultiHub

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +46,6 @@
vol.Optional("timeout"): vol.Coerce(int),
vol.Optional("reconnect_delay"): vol.Coerce(float),
vol.Optional("reconnect_delay_max"): vol.Coerce(float),
vol.Optional("retry_on_empty"): cv.boolean,
}
),
}
Expand All @@ -69,17 +66,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up SolarEdge Modbus Muti from a config entry."""

entry_updates: dict[str, Any] = {}
if CONF_SCAN_INTERVAL in entry.data:
data = {**entry.data}
entry_updates["data"] = data
entry_updates["options"] = {
**entry.options,
CONF_SCAN_INTERVAL: data.pop(CONF_SCAN_INTERVAL),
}
if entry_updates:
hass.config_entries.async_update_entry(entry, **entry_updates)

solaredge_hub = SolarEdgeModbusMultiHub(
hass, entry.entry_id, entry.data, entry.options
)
Expand Down Expand Up @@ -168,6 +154,56 @@ async def async_remove_config_entry_device(
return True


async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Migrate old entry."""
_LOGGER.debug(
"Migrating from config version "
f"{config_entry.version}.{config_entry.minor_version}"
)

if config_entry.version > 1:
return False

if config_entry.version == 1:

update_data = {**config_entry.data}
update_options = {**config_entry.options}

if CONF_SCAN_INTERVAL in update_data:
update_options = {
**update_options,
CONF_SCAN_INTERVAL: update_data.pop(CONF_SCAN_INTERVAL),
}

start_device_id = update_data.pop(ConfName.DEVICE_ID)
number_of_inverters = update_data.pop(ConfName.NUMBER_INVERTERS)

inverter_list = []
for inverter_index in range(number_of_inverters):
inverter_unit_id = inverter_index + start_device_id
inverter_list.append(inverter_unit_id)

update_data = {
**update_data,
ConfName.DEVICE_LIST: inverter_list,
}

hass.config_entries.async_update_entry(
config_entry,
data=update_data,
options=update_options,
version=2,
minor_version=0,
)

_LOGGER.warning(
"Migrated to config version "
f"{config_entry.version}.{config_entry.minor_version}"
)

return True


class SolarEdgeCoordinator(DataUpdateCoordinator):
def __init__(
self, hass: HomeAssistant, hub: SolarEdgeModbusMultiHub, scan_interval: int
Expand Down
3 changes: 1 addition & 2 deletions custom_components/solaredge_modbus_multi/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ async def async_setup_entry(
if hub.option_detect_extras and inverter.advanced_power_control:
entities.append(AdvPowerControlEnabled(inverter, config_entry, coordinator))

if hub.option_detect_extras:
entities.append(GridStatusOnOff(inverter, config_entry, coordinator))
entities.append(GridStatusOnOff(inverter, config_entry, coordinator))

if entities:
async_add_entities(entities)
Expand Down
Loading

0 comments on commit 6398d2f

Please sign in to comment.