Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sensor for SmartGrid Status #147

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions custom_components/e3dc_rscp/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ async def _async_update_data(self) -> dict[str, Any]:

_LOGGER.debug("Polling general status information")
await self._load_and_process_poll()
await self._load_and_process_poll_switches()

# TODO: Check if we need to replace this with a safe IPC sync
if self._update_guard_powersettings is False:
Expand Down Expand Up @@ -306,6 +307,41 @@ async def _load_and_process_poll(self):
self._mydata["solar-production"] = poll_data["production"]["solar"]
self._mydata["wallbox-consumption"] = poll_data["consumption"]["wallbox"]

async def _load_and_process_poll_switches(self):
"""Load and process switches poll data."""
try:
poll_data: list[dict] = await self.hass.async_add_executor_job(self.proxy.poll_switches)
except HomeAssistantError as ex:
_LOGGER.warning("Failed to poll switches, not updating data: %s", ex)
return

sg0_status=False
sg1_status=False
for switch in poll_data:
if switch["name"] == "SG0":
#48 seems to be the value for switch off
if switch["status"] == 48:
sg0_status = False
else:
sg0_status = True
if switch["name"] == "SG1":
#48 seems to be the value for switch off
if switch["status"] == 48:
sg1_status = False
else:
sg1_status = True

if sg0_status is True and sg1_status is False:
self._mydata["smartgrid"] = "blocked"
elif sg0_status is False and sg1_status is False:
self._mydata["smartgrid"] = "normal"
elif sg0_status is False and sg1_status is True:
self._mydata["smartgrid"] = "recommendation_on"
elif sg0_status is True and sg1_status is True:
self._mydata["smartgrid"] = "startup"
else:
self._mydata["smartgrid"] = "normal"

async def _load_and_process_db_data_today(self) -> None:
"""Load and process retrieved db data settings."""
try:
Expand Down
7 changes: 6 additions & 1 deletion custom_components/e3dc_rscp/e3dc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ def poll(self) -> dict[str, Any]:
"""Poll E3DC current state."""
return self.e3dc.poll(keepAlive=True)

@e3dc_call
def poll_switches(self) -> dict[str, Any]:
"""Poll E3DC switches."""
return self.e3dc.poll_switches(keepAlive=True)

@e3dc_call
def start_manual_charge(self, charge_amount_wh: int) -> None:
"""Initiate the manual charging process, zero will stop charging."""
Expand Down Expand Up @@ -410,4 +415,4 @@ def set_weather_regulated_charge(self, enabled: bool):
# unsuccessful, the next polling cycle will reset this to the actual
# value.
# TODO: Find a way to deal with the weather regulation api
self.e3dc.set_weather_regulated_charge(enabled, True)
self.e3dc.set_weather_regulated_charge(enabled, True)
7 changes: 7 additions & 0 deletions custom_components/e3dc_rscp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@
device_class=SensorDeviceClass.POWER_FACTOR,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="smartgrid",
translation_key="smartgrid",
icon="mdi:solar-power",
device_class=SensorDeviceClass.ENUM,
options=["blocked", "normal", "recommendation_on", "startup"],
torbennehmer marked this conversation as resolved.
Show resolved Hide resolved
),
)


Expand Down
9 changes: 8 additions & 1 deletion custom_components/e3dc_rscp/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@
"farm-additional-total": {
"name": "Farm additional powermeter - total"
},
"smartgrid": {
"name": "SmartGrid Status",
"blocked": "blocked mode",
"normal": "normal operation",
"recommendation_on": "PV surplus operation",
"startup": "Operation for derating"
},
"wallbox-app-software": {
"name": "App software"
},
Expand Down Expand Up @@ -335,4 +342,4 @@
}
}
}
}
}
9 changes: 8 additions & 1 deletion custom_components/e3dc_rscp/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@
"farm-additional-total": {
"name": "Farm additional powermeter - total"
},
"smartgrid": {
"name": "SmartGrid Status",
"blocked": "blocked mode",
"normal": "normal operation",
"recommendation_on": "PV surplus operation",
"startup": "Operation for derating"
},
"wallbox-app-software": {
"name": "App software"
},
Expand Down Expand Up @@ -335,4 +342,4 @@
}
}
}
}
}