Skip to content

Commit

Permalink
Merge branch 'main' into 565-ev-charger-support
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCodeForCats committed Aug 31, 2024
2 parents 73fba84 + 754aaf6 commit 1cd0039
Show file tree
Hide file tree
Showing 23 changed files with 949 additions and 401 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ body:
label: Read the Instructions
description: Make sure your configuration is correct, your LAN is working, and you have read about "Known Issues" in the wiki. Do not open an issue to ask how to set up or configure the integration.
options:
- label: I have read https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki
required: true
- label: My configuration follows https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki/Configuration
required: true
- label: This issue is not about a template error (template errors should not be reported as an issue, read https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki/Template-Design-Notes)
- label: I have read the Known Issues https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki/Known-Issues
required: true
- label: This issue is not about a template error (do not report template errors, read https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki/Template-Design-Notes)
required: true
- type: textarea
id: additional-context
Expand Down
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.6
- uses: WillCodeForCats/python-lint-action@v1.0.8
with:
python-root-list: "custom_components/solaredge_modbus_multi"
use-flake8: true
Expand Down
18 changes: 7 additions & 11 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,7 +38,7 @@ 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.3.2 or newer
* Home Assistant 2024.4.0 or newer
* Python 3.11 or newer
* pymodbus 3.6.6 or newer

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
36 changes: 35 additions & 1 deletion custom_components/solaredge_modbus_multi/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import logging

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
Expand All @@ -30,6 +33,8 @@ async def async_setup_entry(
if hub.option_detect_extras and inverter.advanced_power_control:
entities.append(AdvPowerControlEnabled(inverter, config_entry, coordinator))

entities.append(GridStatusOnOff(inverter, config_entry, coordinator))

if entities:
async_add_entities(entities)

Expand Down Expand Up @@ -92,3 +97,32 @@ def name(self) -> str:
@property
def is_on(self) -> bool:
return self._platform.decoded_model["AdvPwrCtrlEn"] == 0x1


class GridStatusOnOff(SolarEdgeBinarySensorBase):
"""Grid Status On Off. This is undocumented from discussions."""

device_class = BinarySensorDeviceClass.POWER
icon = "mdi:transmission-tower"

@property
def available(self) -> bool:
return (
super().available and "I_Grid_Status" in self._platform.decoded_model.keys()
)

@property
def unique_id(self) -> str:
return f"{self._platform.uid_base}_grid_status_on_off"

@property
def name(self) -> str:
return "Grid Status"

@property
def entity_registry_enabled_default(self) -> bool:
return "I_Grid_Status" in self._platform.decoded_model.keys()

@property
def is_on(self) -> bool:
return not self._platform.decoded_model["I_Grid_Status"]
Loading

0 comments on commit 1cd0039

Please sign in to comment.