Skip to content

Commit

Permalink
initial web-api-version
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 authored and marq24 committed Sep 3, 2023
1 parent 0af96f6 commit 04ef010
Show file tree
Hide file tree
Showing 13 changed files with 886 additions and 138 deletions.
93 changes: 58 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
# Home Assistant sensor for SENEC.Home V3
# Home Assistant sensor for SENEC.Home V3

This fork was created from [mchwalisz/home-assistant-senec](https://gitgub.com/mchwalisz/home-assistant-senec) mainly
because I wanted additional fields and some configuration options (like polling interval). Since I own a
__SENEC.Home V3 hybrid duo__ I can __only test my adjustments in such a configuration__.

__Use this fork on your own risk!__
But this does not imply, that this Integration is working only with V3 systems. The Integration should work with
multiple SENEC.Home Systems based on local `lala.cgi` calls.

Have that said - the __SENEC.Home V4__ will not come with a build-in web server that can be polled from your LAN. So
in order to support V4 this integration is polling (a limited amount of) data from the mein-senec.de web portal. The
__available data is__ (currently) __limited__ (only 13 sensor entities) and will be polled with an interval of 5 minutes.

__Thanks to [@mstuettgen](https://github.com/mstuettgen) developing the initial SENEC.Home V4 web-access! I hope you
support this repro in the future with possible enhancements for the WEB-API.

__Please note that this integration will _not work_ with Senec V4 systems!__ Senec V4 use a different communication
layer that is not compatible with previous Senec hardware. So if you are a V4 owner you might be in the uncomfortable
situation to develop a own integration from the scratch. [IMHO it's impossible to develop such a integration remotely]
## __Use this fork on your own risk!__

## Modifications (compared to the original version) in this fork

- Added User accessible configuration option
- Added configurable _update interval_ for the sensor data (I use _5_ seconds, without any issue)
- Reading DeviceID, DeviceType, BatteryType & Version information
- Added WebAPI access in order to support SENEC.Home V4
Systems - [thanks too @mstuettgen for the initial work!](https://github.com/mstuettgen/homeassistant-addons/tree/main/senecweb2mqtt)
__and__ for all other SENEC.Home Systems where the total-statistics data have been removed with the latest update by
SENEC (currently with hardcoded polling interval of 5 minutes)

- Additional Sensors:
- For each MPP1, MPP2, MPP3 [potential (V), current (A) & power (W)]
- For your EnFluRi-Net (Freq, potential, current, power)
- For your EnFluRi-Usage (Freq, potential, current, power) [disabled by default]

- Additional Sensors:
- For each MPP1, MPP2, MPP3 [potential (V), current (A) & power (W)]
- For your EnFluRi-Net (Freq, potential, current, power)
- For your EnFluRi-Usage (Freq, potential, current, power) [disabled by default]

- Added BatteryCell Details [mainly disabled by default]
- Module [A-D]: Current/Voltage/State of Charge (SoC)/State of Health (SoH)/Cycles
- Cell temperature [1-6] per module [A-D]
- Voltage per cell [1-14] per module [A-D]

- Added Wallbox Details [disabled by default]

- If you connect the internal Inverter [in the case of the Duo there are even two (LV & HV)] to your LAN (see
[details below](#inv-lnk)), then you can add these additional instances and directly access the data from the DC-AC
converters
- Added BatteryCell Details [mainly disabled by default]
- Module [A-D]: Current/Voltage/State of Charge (SoC)/State of Health (SoH)/Cycles
- Cell temperature [1-6] per module [A-D]
- Voltage per cell [1-14] per module [A-D]

- Added Wallbox Details [disabled by default]

- If you connect the internal Inverter [in the case of the Duo there are even two (LV & HV)] to your LAN (see
[details below](#inv-lnk)), then you can add these additional instances and directly access the data from the
DC-AC
converters

- Added Switch(es):
- Added a switch to manually load the battery [state: 'MAN. SAFETY CHARGE' & 'SAFETY CHARGE READY'] (obviously this
will use additional power from grid when your PV inverters will not provide enough power)

_This switche might sound very foolish - but if you are not subscribed to the (IMHO total overpriced) SENEC-Cloud
electricity tariff __and__ you have been smart and signed up for a dynamic price model (based on the current stock
price) then loading your battery when the price is the lowest during the day might become a smart move (and also
disallow battery usage while the price is average). Specially during the winter!_
- EXPERIMENTAL: Added a switch to enable 'storage mode' [state: LITHIUM SAFE MODE DONE'] [disabled by default]
The functionality of this switch is currently __not known__ - IMHO this will disable the functionality of the PV!
__Please Note, that once enabled and then disable again the system will go into the 'INSULATION TEST' mode__ for a
short while (before returning to normal operation)
- Added a switch to manually load the battery [state: 'MAN. SAFETY CHARGE' & 'SAFETY CHARGE READY'] (obviously this
will use additional power from grid when your PV inverters will not provide enough power)

_This switche might sound very foolish - but if you are not subscribed to the (IMHO total overpriced) SENEC-Cloud
electricity tariff __and__ you have been smart and signed up for a dynamic price model (based on the current stock
price) then loading your battery when the price is the lowest during the day might become a smart move (and also
disallow battery usage while the price is average). Specially during the winter!_

- EXPERIMENTAL: Added a switch to enable 'storage mode' [state: LITHIUM SAFE MODE DONE'] [disabled by default]

The functionality of this switch is currently __not known__ - IMHO this will disable the functionality of the PV!
__Please Note, that once enabled and then disable again the system will go into the 'INSULATION TEST' mode__ for a
short while (before returning to normal operation)

- Modified _battery_charge_power_ & _battery_discharge_power_ so that they will only return data >0 when the system
state is matching the corresponding CHARGE or DISCHARGE state (including state variants)
Expand All @@ -68,26 +81,33 @@ situation to develop a own integration from the scratch. [IMHO it's impossible t

### Manual

- Copy all files from `custom_components/senec/` to `custom_components/senec/` inside your config Home Assistant directory.
- Copy all files from `custom_components/senec/` to `custom_components/senec/` inside your config Home Assistant
directory.
- Restart Home Assistant to install all dependencies

### Adding or enabling integration

#### My Home Assistant (2021.3+)

[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=senec)

#### Manual

Add custom integration using the web interface and follow instruction on screen.

- Go to `Configuration -> Integrations` and add "Senec" integration
- Provide name for the device, and it's address (hostname or IP)
- Provide area where the battery is located

<a id='inv-lnk'></a>

## Connecting the internal (build in) Senec Inverter Hardware to your LAN and use it in HA

The __SENEC.Home V3 hybrid duo__ have build in two inverters - called LV and HV. This hardware has its own LAN
connectors, but they have not been connected during the installation process (I guess by purpose).

### __DO THIS ON YOUR OWN RISK!__

Nevertheless, when you dismount the front and the right hand side panels you simply can plug in RJ45 LAN cables into
both of the inverters LAN connectors and after a short while you should be able to access the web frontends of the
inverters via your browser.
Expand All @@ -96,14 +116,17 @@ _Don't forget to assign fixed IP's to the additional inverter hardware. You can
in order to make sure that the inverters will make use of the fixed assigned IP's._

### Position of SENEC.Inverter V3 LV LAN connector

![img|160x90](images/inv_lv.png)
On the front of the device

### Position of SENEC.Inverter V3 HV LAN connector _(hybrid duo only!)_

![img|160x90](images/inv_hv.png)
On the right hand side of the device

### Adding Inverter(s) to your HA

Once you have connected the inverter(s) with your LAN you can add another integration entry to your Senec Integration in
Home Assistant:

Expand All @@ -112,7 +135,7 @@ Home Assistant:
3. there you find the '__Add Entry__' button (at the bottom of the '__Integration entries__' list)
4. specify the IP (or hostname) of the inverter you want to add
5. __important:__ assign a name (e.g. _INV_LV_).

Repeat step 3, 4 & 5 of this procedure, if you have build in two inverters into your Senec.HOME.

## Home Assistant Energy Dashboard
Expand Down
3 changes: 3 additions & 0 deletions STATSENSORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Since SENEC Application v825 no STATISTIC data is provided [No Data for multiple Sensors]

currently you find all available information here in this issue https://github.com/marq24/ha-senec-v3/issues/4
14 changes: 9 additions & 5 deletions custom_components/senec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from datetime import timedelta

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_SCAN_INTERVAL, CONF_TYPE
from homeassistant.const import CONF_HOST, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_USERNAME, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import EntityDescription, Entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from custom_components.senec.pysenec_ha import Senec, Inverter
from custom_components.senec.pysenec_ha import Senec, Inverter, MySenecWebPortal

from .const import (
DOMAIN,
Expand All @@ -25,7 +25,8 @@
CONF_DEV_NAME,
CONF_DEV_SERIAL,
CONF_DEV_VERSION,
CONF_SYSTYPE_INVERTER
CONF_SYSTYPE_INVERTER,
CONF_SYSTYPE_WEB
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -61,7 +62,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, platform))

entry.add_update_listener(async_reload_entry)

return True


Expand All @@ -70,10 +70,14 @@ class SenecDataUpdateCoordinator(DataUpdateCoordinator):

def __init__(self, hass, session, entry):
"""Initialize."""
self._host = entry.data[CONF_HOST]
if CONF_TYPE in entry.data and entry.data[CONF_TYPE] == CONF_SYSTYPE_INVERTER:
self._host = entry.data[CONF_HOST]
self.senec = Inverter(self._host, websession=session)
if CONF_TYPE in entry.data and entry.data[CONF_TYPE] == CONF_SYSTYPE_WEB:
self._host = "mein-senec.de"
self.senec = MySenecWebPortal(user=entry.data[CONF_USERNAME], pwd=entry.data[CONF_PASSWORD], websession=session)
else:
self._host = entry.data[CONF_HOST]
if CONF_USE_HTTPS in entry.data:
self._use_https = entry.data[CONF_USE_HTTPS]
else:
Expand Down
6 changes: 4 additions & 2 deletions custom_components/senec/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

from typing import Literal
from . import SenecDataUpdateCoordinator, SenecEntity
from .const import DOMAIN, MAIN_BIN_SENSOR_TYPES, CONF_SYSTYPE_INVERTER, ExtBinarySensorEntityDescription
from .const import DOMAIN, MAIN_BIN_SENSOR_TYPES, CONF_SYSTYPE_INVERTER, CONF_SYSTYPE_WEB, ExtBinarySensorEntityDescription

_LOGGER = logging.getLogger(__name__)

async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities):
coordinator = hass.data[DOMAIN][config_entry.entry_id]
if (CONF_TYPE in config_entry.data and config_entry.data[CONF_TYPE] == CONF_SYSTYPE_INVERTER):
_LOGGER.info("No switches for Inverters...")
_LOGGER.info("No binary_sensors for Inverters...")
if (CONF_TYPE in config_entry.data and config_entry.data[CONF_TYPE] == CONF_SYSTYPE_WEB):
_LOGGER.info("No binary_sensors for WebPortal...")
else:
entities = []
for description in MAIN_BIN_SENSOR_TYPES:
Expand Down
Loading

0 comments on commit 04ef010

Please sign in to comment.