diff --git a/custom_components/e3dc_rscp/coordinator.py b/custom_components/e3dc_rscp/coordinator.py index 25fe02d..b381bf3 100644 --- a/custom_components/e3dc_rscp/coordinator.py +++ b/custom_components/e3dc_rscp/coordinator.py @@ -239,6 +239,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: @@ -321,6 +322,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: diff --git a/custom_components/e3dc_rscp/e3dc_proxy.py b/custom_components/e3dc_rscp/e3dc_proxy.py index 813954a..40e9215 100644 --- a/custom_components/e3dc_rscp/e3dc_proxy.py +++ b/custom_components/e3dc_rscp/e3dc_proxy.py @@ -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.""" @@ -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) \ No newline at end of file diff --git a/custom_components/e3dc_rscp/sensor.py b/custom_components/e3dc_rscp/sensor.py index c029318..e7ee39d 100644 --- a/custom_components/e3dc_rscp/sensor.py +++ b/custom_components/e3dc_rscp/sensor.py @@ -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"], + ), ) diff --git a/custom_components/e3dc_rscp/strings.json b/custom_components/e3dc_rscp/strings.json index df09ea2..0f87a11 100644 --- a/custom_components/e3dc_rscp/strings.json +++ b/custom_components/e3dc_rscp/strings.json @@ -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" }, @@ -335,4 +342,4 @@ } } } -} \ No newline at end of file +} diff --git a/custom_components/e3dc_rscp/translations/en.json b/custom_components/e3dc_rscp/translations/en.json index baa0911..1c4a911 100644 --- a/custom_components/e3dc_rscp/translations/en.json +++ b/custom_components/e3dc_rscp/translations/en.json @@ -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" }, @@ -335,4 +342,4 @@ } } } -} \ No newline at end of file +}