Skip to content

Commit

Permalink
added service that can be used to force stop of charging (set manual …
Browse files Browse the repository at this point in the history
…mode to: STOP for 5 minutes)
  • Loading branch information
marq24 committed May 11, 2024
1 parent b51e15b commit c4c6602
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 7 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ action:
mode: single
```

### Force stop charging when PV power is too low

Unfortunately, it is possible that the go-eCharger does not finish charging in ECO mode using the PV power (in a timely manner). To ensure that charging stops when there is no longer enough PV power, you can add the following automation:

You need to adjust the entity ids: `switch.goe_012345_fup`, `sensor.goe_012345_nrg_11` and `sensor.goe_012345_pvopt_averagepgrid` (replace the `012345` with your serial number) and your preferred threshold when this automation should be executed (the `above: -200` for the `pvopt_averagepgrid` means, that as soon as the average power you export to the grid is less than 200 watt the automation will be triggered).

```
alias: go-e FORCE STOP of PV surplus charging
description: >-
Simple automation to ensure that the go-eCharger will stop charging when average PV will drop below given threshold
trigger:
- platform: time_pattern
seconds: /5
condition:
- condition: state
entity_id: switch.goe_012345_fup
state: "on"
- condition: numeric_state
entity_id: sensor.goe_012345_nrg_11
above: 200
- condition: numeric_state
entity_id: sensor.goe_012345_pvopt_averagepgrid
above: -200
action:
- service: goecharger_api2.stop_charging
mode: single
```

<a id="hibernation"></a>

## Hibernation-Mode - Good to know
Expand Down
4 changes: 4 additions & 0 deletions custom_components/goecharger_api2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PLATFORMS,
STARTUP_MESSAGE,
SERVICE_SET_PV_DATA,
SERVICE_STOP_CHARGING,
CONF_11KWLIMIT
)
from .service import GoeChargerApiV2Service
Expand Down Expand Up @@ -73,6 +74,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
service = GoeChargerApiV2Service(hass, config_entry, coordinator)
hass.services.async_register(DOMAIN, SERVICE_SET_PV_DATA, service.set_pv_data,
supports_response=SupportsResponse.OPTIONAL)
hass.services.async_register(DOMAIN, SERVICE_STOP_CHARGING, service.stop_charging,
supports_response=SupportsResponse.OPTIONAL)

if coordinator.check_for_max_of_16a:
asyncio.create_task(coordinator.check_for_16a_limit(hass, config_entry.entry_id))
Expand All @@ -94,6 +97,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
hass.data[DOMAIN].pop(config_entry.entry_id)

hass.services.async_remove(DOMAIN, SERVICE_SET_PV_DATA)
hass.services.async_remove(DOMAIN, SERVICE_STOP_CHARGING)

return unload_ok

Expand Down
1 change: 1 addition & 0 deletions custom_components/goecharger_api2/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"""

SERVICE_SET_PV_DATA: Final = "set_pv_data"
SERVICE_STOP_CHARGING: Final = "stop_charging"
CONF_11KWLIMIT: Final = "limit_to_11kw"

@dataclass
Expand Down
3 changes: 2 additions & 1 deletion custom_components/goecharger_api2/icons.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"services": {
"set_pv_data": "mdi:solar-power"
"set_pv_data": "mdi:solar-power",
"stop_charging": "mdi:hand-front-left-outline"
}
}
2 changes: 1 addition & 1 deletion custom_components/goecharger_api2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-goecharger-api2/issues",
"requirements": [],
"version": "2024.5.5"
"version": "2024.5.6"
}
6 changes: 3 additions & 3 deletions custom_components/goecharger_api2/pygoecharger_ha/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class CAR_VALUES(Enum):
4: "Nicht laden, da manuell gestoppt",
5: "Nicht laden, durch Ladetimer gestoppt",
6: "Nicht laden weil kWh Limit erreicht",
7: "Laden mit günstigen aWATTar Preis",
7: "Laden mit günstigem Strompreis",
8: "Laden im Next-Trip Modus, Testladung",
9: "Laden im Next-Trip Modus, keine Uhrzeit",
10: "Laden im Next-Trip Modus",
Expand All @@ -122,8 +122,8 @@ class CAR_VALUES(Enum):
13: "Laden im Standard Modus (go-e Default)",
14: "Laden im Ladetimer Modus (go-e Scheduler)",
15: "Laden weil 'fallback (Default)'",
16: "Nicht laden, weil 'Fallback (go-e Awattar)'",
17: "Nicht laden, weil 'Fallback (Awattar)'",
16: "Nicht laden, weil 'Fallback (go-e günstiger Strompreis)'",
17: "Nicht laden, weil 'Fallback (günstiger Strompreis)'",
18: "Nicht laden, weil 'Fallback (Automatic Stop)'",
19: "Laden um das Auto wach zu halten",
20: "Laden weil Ladepause nicht erlaubt",
Expand Down
42 changes: 40 additions & 2 deletions custom_components/goecharger_api2/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import datetime
import logging

Expand All @@ -14,6 +15,7 @@ def __init__(self, hass, config, coordinator): # pylint: disable=unused-argumen
self._hass = hass
self._config = config
self._coordinator = coordinator
self._stop_in_progress = False

async def set_pv_data(self, call: ServiceCall):
pgrid = call.data.get('pgrid', None)
Expand Down Expand Up @@ -44,6 +46,42 @@ async def set_pv_data(self, call: ServiceCall):
if call.return_response:
return {"error": str(exc), "date": str(datetime.datetime.now().time())}


if call.return_response:
return {"error": "No Grid Power provided (or false data)", "date": str(datetime.datetime.now().time())}
return {"error": "No Grid Power provided (or false data)", "date": str(datetime.datetime.now().time())}

async def stop_charging(self, call: ServiceCall):
if not self._stop_in_progress:
self._stop_in_progress = True
_LOGGER.debug(f"Force STOP_CHARGING")

try:
resp = await self._coordinator.async_write_key(Tag.FRC.key, 1)
if Tag.FRC.key in resp:
_LOGGER.debug(f"STOP_CHARGING: waiting for 5 minutes...")
await asyncio.sleep(300)
_LOGGER.debug(f"STOP_CHARGING: 5 minutes are over... disable charging LOCK again")

resp = await self._coordinator.async_write_key(Tag.FRC.key, 0)

self._stop_in_progress = False
if call.return_response:
return {
"success": "true",
"date": str(datetime.datetime.now().time()),
"response": resp
}

else:
_LOGGER.debug(f"response does not contain {Tag.FRC.key}: {resp}")

self._stop_in_progress = False
if call.return_response:
return {"error": "A STOP_CHARGING request could not be send", "date": str(datetime.datetime.now().time())}

except ValueError as exc:
if call.return_response:
return {"error": str(exc), "date": str(datetime.datetime.now().time())}

else:
if call.return_response:
return {"error": "A STOP_CHARGING request is already in progress", "date": str(datetime.datetime.now().time())}
4 changes: 4 additions & 0 deletions custom_components/goecharger_api2/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ set_pv_data:
max: 50000
unit_of_measurement: "W"
mode: "box"

stop_charging:
name: Force changing OFF (for 5 minutes)
description: Will ensure that the go-eCharger will stop charging. After 5 minutes the charger will return to default mode
4 changes: 4 additions & 0 deletions custom_components/goecharger_api2/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"ppv": {"name": "Leistung der PV (in Watt)", "description": "Die aktuelle PV-Produktion."},
"pakku": {"name": "Leistung von/aud der Batterie (in Watt)", "description": "Negative Werte bedeuten, dass die Batterie geladen wird, positive Werte bedeuten, dass Strom aus der Batterie verbraucht wird."}
}
},
"stop_charging": {
"name": "Laden stoppen (für 5 Minuten)",
"description": "Stellt sicher, dass der go-eCharger den Ladevorgang stoppt. Nach 5 Minuten wird in den Standardmodus zurückgekehrt"
}
},
"entity": {
Expand Down
4 changes: 4 additions & 0 deletions custom_components/goecharger_api2/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"ppv": {"name": "Power from PV (in Watt)", "description": "The current PV production"},
"pakku": {"name": "Power from/to battery (in Watt)", "description": "Negative values means charging the battery, positive value means consuming power from the battery."}
}
},
"stop_charging": {
"name": "Force changing-OFF (for 5 minutes)",
"description": "Will ensure that the go-eCharger will stop charging. After 5 minutes the charger will return to default mode"
}
},
"entity": {
Expand Down

0 comments on commit c4c6602

Please sign in to comment.