CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
134 stars 28 forks source link

Operating mode unavailable on Libbi/Zappi #516

Open marcroberts opened 2 months ago

marcroberts commented 2 months ago

I've had my Libbi & Zappi for a couple of months now and have setup some automations with my Octopus Intelligent Go tarif to prevent the Libbi supplying the house when the extra off-peak charging hours are active.

After a few weeks the Libbi 'operating mode' became unavailable. I was unable to see or set this mode directly although the automations setup seem to still trigger this correctly strangely.

image

More recently the Zappi 'operating mode' has also become unavailable

image

Any ideas as to why, and how they can be fixed (ideally without breaking any existing automations)

marcroberts commented 2 months ago

Oh, I’ve just seen this in the logs. Hope this helps


This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/myenergi/select.py:174
integration: myenergi (documentation, issues)
First occurred: 15:44:01 (54 occurrences)
Last logged: 16:37:13

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 414, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 494, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 152, in state
    current_option = self.current_option
                     ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/myenergi/select.py", line 174, in current_option
    return LIBBI_MODE_NAMES[mode]
           ~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'BALANCE'
MalcolmSpencer commented 2 months ago

I have the same issue and error in the log file. I have HA-Myenergi 0.0.27 installed

Core 2024.4.3 Supervisor 2024.04.0 Operating System 12.2 Frontend 20240404.2

MalcolmSpencer commented 2 months ago

Firstly i am not a programmer but I do have a basic understanding of Python.

The issue seems to be at File "/config/custom_components/myenergi/select.py", line 174,

@property
def current_option(self):
    """Return the state of the sensor."""
    mode = self.device.local_mode
    return LIBBI_MODE_NAMES[mode]

LIBBI_MODE_NAMES = {0: "Stopped", 1: "Normal", 5: "Export"}

but I think mode is using the API returned names which are STOP, BALANCE and DRAIN and hence the key error. should it be using mode_int?

LIBBI_MODE_CONFIG = { "Stopped": {"mode_int": 0, "mode_name": "STOP"}, "Normal": {"mode_int": 1, "mode_name": "BALANCE"}, "Export": {"mode_int": 5, "mode_name": "DRAIN"},

MalcolmSpencer commented 2 months ago

I fixed this by changing select.py line 12 to

LIBBI_MODE_NAMES = {"STOP" : "Stopped", "BALANCE" : "Normal", "DRAIN" : "Export"}

This will need to be fixed in the next build

FlipGFlop commented 2 months ago

I have had the same issue for a few weeks and I can confirm that the fix worked for me too.