Skip to content

Commit

Permalink
Merge pull request #47 from matt-oneill/BatteryChargeService
Browse files Browse the repository at this point in the history
Add a service to set battery charge / discharge
  • Loading branch information
CharlesGillanders authored Nov 7, 2022
2 parents 64e950d + b5eb3b0 commit 4aaec5b
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 1 deletion.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br>

### Alpha ESS: Set Battery Charge<br>

This service call allows you to set the grid charge settings for your system. <br>
Times are not validated and must be compatible with the Alpha values. <br>
Data needed:<br>
- serial = The serial of your system. <br>
- enabled = True or False <br>
- cp1start = Charging Period 1 Start Time <br>
- cp1end = Charging Period 1 End Time <br>
- cp2start = Charging Period 2 Start Time <br>
- cp2end = Charging Period 2 End Time <br>

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<br>
This service call allows you to set the battery discharge settings for your system. <br>
Times are not validated and must be compatible with the Alpha values. <br>
Data needed:<br>
- serial = The serial of your system. <br>
- enabled = True or False <br>
- dp1start = Discharging Period 1 Start Time <br>
- dp1end = Discharging Period 1 End Time <br>
- dp2start = Discharging Period 2 Start Time <br>
- dp2end = Discharging Period 2 End Time <br>
example:
```yaml
service: alphaess.setbatterydischarge
data:
serial: AA123456789
enabled: True
dp1start: "01:00"
dp1end: "04:00"
dp2start: "13:00"
dp2end: "16:00"
dischargecutoffsoc: 10
```
40 changes: 40 additions & 0 deletions custom_components/alphaess/__init__.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion custom_components/alphaess/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"requirements": ["alphaess==0.0.16"],
"config_flow": true,
"iot_class": "cloud_polling",
"version": "0.0.10"
"version": "0.0.11"
}
93 changes: 93 additions & 0 deletions custom_components/alphaess/services.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4aaec5b

Please sign in to comment.