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

set_override not working #307

Closed
flaparoo opened this issue Feb 29, 2024 · 2 comments · Fixed by #309
Closed

set_override not working #307

flaparoo opened this issue Feb 29, 2024 · 2 comments · Fixed by #309
Labels
bug Something isn't working

Comments

@flaparoo
Copy link

The following service call doesn't work (any more - it used to):

service: openevse.set_override
data:
  state: active
  auto_release: true
target:
  device_id: 6cacd2a2b6da7241e57efb2e91aa2914

It results in:

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:485
First occurred: February 29, 2024 at 08:18:40 (4 occurrences)
Last logged: 07:24:41
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'ea1027847f4fd53570e7268f7bbbf7f2'

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openevse/services.py", line 143, in _set_override
    manager = self.hass.data[DOMAIN][config_id][MANAGER]
              ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'ea1027847f4fd53570e7268f7bbbf7f2'

I have utility meter helpers associated with the OpenEVSE device, and found the ea1027847f4fd53570e7268f7bbbf7f2 ID is one of the utility meters. Looking into the device_registry, I've noticed that this entity ID is the first in the list of config_entries (the OpenEVSE ID is 8edefc891bd4052fc70db0efe3d6bb8a):

...snip...
        "config_entries": [
          "ea1027847f4fd53570e7268f7bbbf7f2",
          "8edefc891bd4052fc70db0efe3d6bb8a",
          "491cc37b5d41354d25d0be44f36b6724",
          "5fbba5e170a55226cbc2c2c96ecfcee8",
          "63062806607a924b147014f6dfe8b634"
        ],
        "connections": [
          [
            "openevse",
            "8edefc891bd4052fc70db0efe3d6bb8a"
          ]
        ],
...snip...

My best guess is that the integration falls over here: https://github.com/firstof9/openevse/blob/main/custom_components/openevse/services.py#L141
I think instead of always using the first item in the config_entries list, it needs to loop through the list and identify the actual OpenEVSE device/entity. I don't know how to do that, though.

@iRonin
Copy link

iRonin commented May 25, 2024

I have an issue that may be related to this one. This is the config from core.devices_registry:

{"area_id":null,"config_entries":["8b4…"],"configuration_url":"homeassistant://hacs","connections":[],"disabled_by":null,"entry_type":"service","hw_version":null,"id":"6c3…","identifiers":[["hacs","388213457"]],"labels":[],"manufacturer":"firstof9","model":"integration","name_by_user":null,"name":"OpenEVSE","serial_number":null,"sw_version":null,"via_device_id":null},
      {"area_id":"garage","config_entries":["8ca…"],"configuration_url":"http://192.168.0.213/","connections":[["openevse","8ca…"],["openevse","55e…"]],"disabled_by":null,"entry_type":null,"hw_version":null,"id":"ece…","identifiers":[["openevse","94B5557DA46C"]],"labels":[],"manufacturer":"OpenEVSE","model":"openevse_wifi_tft_v1","name_by_user":null,"name":"openevse","serial_number":null,"sw_version":"v5.1.0_modified","via_device_id":null},

The error:

2024-05-25 15:07:29.593 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: '55e…'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openevse/services.py", line 355, in _make_claim
    manager = self.hass.data[DOMAIN][config_id][MANAGER]
              ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: '55e…'
2024-05-25 15:07:29.595 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139929624152384] Error handling message: Unknown error (unknown_error) CK from 192.168.0.125 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 793, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1731, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 503, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 533, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openevse/services.py", line 355, in _make_claim
    manager = self.hass.data[DOMAIN][config_id][MANAGER]
              ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: '55e…'

It seems the script takes wrong connection from "connections":[["openevse","8ca…"],["openevse","55e…"]]

I remember when I configured the plugin I've got two OpenEVSE devices (even though I have one), then I remove that one or disabled (don't remember), then I was getting this weird error that I didn't know what it was - it had the id of that connection that was not configured. Now I edited it out from core.devices_registry but maybe it will help someone else.

@firstof9
Copy link
Owner

Please do not edit core.devices_registry it's not meant for human modification.
If HA shows two devices, remove them both and re-add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants