From bafdfc00d20d5a38db527a4d4ef3fd1ac5a5bf19 Mon Sep 17 00:00:00 2001
From: matt-oneill <60574293+matt-oneill@users.noreply.github.com>
Date: Sat, 5 Nov 2022 11:43:13 +0000
Subject: [PATCH 1/4] Update __init__.py
---
custom_components/alphaess/__init__.py | 40 ++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/custom_components/alphaess/__init__.py b/custom_components/alphaess/__init__.py
index 1d1caa2..c64e486 100644
--- a/custom_components/alphaess/__init__.py
+++ b/custom_components/alphaess/__init__.py
@@ -1,18 +1,46 @@
"""The AlphaEss integration."""
from __future__ import annotations
+import voluptuous as vol
+
from alphaess import alphaess
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
+import homeassistant.helpers.config_validation as cv
+
from .const import DOMAIN, PLATFORMS
from .coordinator import AlphaESSDataUpdateCoordinator
+SERVICE_BATTERY_CHARGE_SCHEMA = vol.Schema(
+ {
+ vol.Required('serial'): cv.string,
+ vol.Required('enabled'): cv.boolean,
+ vol.Required('cp1start'): cv.string,
+ vol.Required('cp1end'): cv.string,
+ vol.Required('cp2start'): cv.string,
+ vol.Required('cp2end'): cv.string,
+ vol.Required('chargestopsoc'): cv.positive_int,
+ }
+)
+
+SERVICE_BATTERY_DISCHARGE_SCHEMA = vol.Schema(
+ {
+ vol.Required('serial'): cv.string,
+ vol.Required('enabled'): cv.boolean,
+ vol.Required('dp1start'): cv.string,
+ vol.Required('dp1end'): cv.string,
+ vol.Required('dp2start'): cv.string,
+ vol.Required('dp2end'): cv.string,
+ vol.Required('dischargecutoffsoc'): cv.positive_int,
+ }
+)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Alpha ESS from a config entry."""
+
client = alphaess.alphaess()
client.username = entry.data[CONF_USERNAME]
@@ -26,6 +54,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(update_listener))
+
+ async def async_battery_charge_handler(call):
+ await client.setbatterycharge(call.data.get('serial'), call.data.get('enabled'), call.data.get('cp1start'), call.data.get('cp1end'), call.data.get('cp2start'), call.data.get('cp2end'), call.data.get('chargestopsoc'))
+
+ async def async_battery_discharge_handler(call):
+ await client.setbatterydischarge(call.data.get('serial'), call.data.get('enabled'), call.data.get('dp1start'), call.data.get('dp1end'), call.data.get('dp2start'), call.data.get('dp2end'), call.data.get('dischargecutoffsoc'))
+
+ hass.services.async_register(
+ DOMAIN, 'setbatterycharge', async_battery_charge_handler, SERVICE_BATTERY_CHARGE_SCHEMA)
+
+ hass.services.async_register(
+ DOMAIN, 'setbatterydischarge', async_battery_discharge_handler, SERVICE_BATTERY_DISCHARGE_SCHEMA)
return True
From 9f69a2741ee2652b9e78ff6b0a980fc6318f5238 Mon Sep 17 00:00:00 2001
From: matt-oneill <60574293+matt-oneill@users.noreply.github.com>
Date: Sat, 5 Nov 2022 11:44:12 +0000
Subject: [PATCH 2/4] Create services.yaml
---
custom_components/alphaess/services.yaml | 93 ++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 custom_components/alphaess/services.yaml
diff --git a/custom_components/alphaess/services.yaml b/custom_components/alphaess/services.yaml
new file mode 100644
index 0000000..32c9c0c
--- /dev/null
+++ b/custom_components/alphaess/services.yaml
@@ -0,0 +1,93 @@
+setbatterycharge:
+ name: Set Battery Charge
+ description: >
+ Enables setting Alpha ESS Grid Charging Settings.
+ fields:
+ serial:
+ name: Serial
+ description: Your Alpha ESS Serial number.
+ required: true
+ example: AA123456789
+ enabled:
+ name: Enabled
+ description: Enable Grid Charging battery.
+ required: true
+ example: True
+ default: True
+ cp1start:
+ name: Charging Period 1 Start
+ description: Charging Period 1 Start.
+ required: true
+ example: "01:00"
+ default: "00:00"
+ cp1end:
+ name: Charging Period 1 End
+ description: Charging Period 1 End.
+ required: true
+ example: "04:00"
+ default: "00:00"
+ cp2start:
+ name: Charging Period 2 Start
+ description: Charging Period 2 Start.
+ required: true
+ example: "01:00"
+ default: "00:00"
+ cp2end:
+ name: Charging Period 2 End
+ description: Charging Period 2 End.
+ required: true
+ example: "04:00"
+ default: "00:00"
+ chargestopsoc:
+ name: Charge Cutoff
+ description: Charging Stops at SOC [%].
+ required: true
+ example: 100
+ default: 100
+
+setbatterydischarge:
+ name: Set Battery Discharge
+ description: >
+ Enables setting Alpha ESS Battery Discharge Settings.
+ fields:
+ serial:
+ name: Serial
+ description: Your Alpha ESS Serial number.
+ required: true
+ example: AA123456789
+ enabled:
+ name: Enabled
+ description: Enable Battery Discharge.
+ required: true
+ example: True
+ default: True
+ dp1start:
+ name: Discharging Period 1 Start
+ description: Discharging Period 1 Start.
+ required: true
+ example: "01:00"
+ default: "00:00"
+ dp1end:
+ name: Discharging Period 1 End
+ description: Discharging Period 1 End.
+ required: true
+ example: "04:00"
+ default: "00:00"
+ dp2start:
+ name: Discharging Period 2 Start
+ description: Discharging Period 2 Start.
+ required: true
+ example: "01:00"
+ default: "00:00"
+ dp2end:
+ name: Discharging Period 2 End
+ description: Discharging Period 2 End.
+ required: true
+ example: "04:00"
+ default: "00:00"
+ dischargecutoffsoc:
+ name: Discharging Cutoff
+ description: Discharging Cutoff SOC [%].
+ required: true
+ example: 100
+ default: 100
From f9afbc5fa4b2f3143fb911c9be8e3dc87317cecd Mon Sep 17 00:00:00 2001
From: matt-oneill <60574293+matt-oneill@users.noreply.github.com>
Date: Sat, 5 Nov 2022 11:45:17 +0000
Subject: [PATCH 3/4] Update manifest.json
---
custom_components/alphaess/manifest.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/custom_components/alphaess/manifest.json b/custom_components/alphaess/manifest.json
index 6d96e85..b21d043 100644
--- a/custom_components/alphaess/manifest.json
+++ b/custom_components/alphaess/manifest.json
@@ -8,5 +8,5 @@
"requirements": ["alphaess==0.0.16"],
"config_flow": true,
"iot_class": "cloud_polling",
- "version": "0.0.10"
+ "version": "0.0.11"
}
From b5eb3b0168f3f43e8e12b3ec6e609958744e4fd9 Mon Sep 17 00:00:00 2001
From: matt-oneill <60574293+matt-oneill@users.noreply.github.com>
Date: Sat, 5 Nov 2022 12:00:15 +0000
Subject: [PATCH 4/4] Update README.md
---
README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/README.md b/README.md
index b61821e..65dabf9 100644
--- a/README.md
+++ b/README.md
@@ -24,3 +24,57 @@ Monitor your energy generation, storage, and usage data using an unofficial API
5. Log out of HomeAssistant and back in again
6. Setup this integration for your Alpha ESS energy storage system in Home Assistant via `Configuration -> Integrations -> Add -> Alpha ESS`
7. You will be prompted for the username and password for your account on the Alpha ESS website/app
+
+## Services
+
+This project allows you to use the following services in Home Assistant:
+
+### Alpha ESS: Set Battery Charge
+
+ This service call allows you to set the grid charge settings for your system.
+ Times are not validated and must be compatible with the Alpha values.
+ Data needed:
+ - serial = The serial of your system.
+ - enabled = True or False
+ - cp1start = Charging Period 1 Start Time
+ - cp1end = Charging Period 1 End Time
+ - cp2start = Charging Period 2 Start Time
+ - cp2end = Charging Period 2 End Time
+
+example:
+```yaml
+service: alphaess.setbatterycharge
+data:
+ serial: AA123456789
+ enabled: True
+ cp1start: "01:00"
+ cp1end: "04:00"
+ cp2start: "13:00"
+ cp2end: "16:00"
+ chargestopsoc: 100
+```
+
+### Alpha ESS: Set Battery Discharge
+
+ This service call allows you to set the battery discharge settings for your system.
+ Times are not validated and must be compatible with the Alpha values.
+ Data needed:
+ - serial = The serial of your system.
+ - enabled = True or False
+ - dp1start = Discharging Period 1 Start Time
+ - dp1end = Discharging Period 1 End Time
+ - dp2start = Discharging Period 2 Start Time
+ - dp2end = Discharging Period 2 End Time
+
+example:
+```yaml
+service: alphaess.setbatterydischarge
+data:
+ serial: AA123456789
+ enabled: True
+ dp1start: "01:00"
+ dp1end: "04:00"
+ dp2start: "13:00"
+ dp2end: "16:00"
+ dischargecutoffsoc: 10
+```