home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.83k stars 30.91k forks source link

TADO: websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'zoneStates' #127388

Open Tazmanian79 opened 1 month ago

Tazmanian79 commented 1 month ago

The problem

I have a script running to change the heating when I'm home or leave. It used to work last winter. Actually it's still working but every time I run the script that I'm away I get an error:

THE ERRORS:

Logger: homeassistant.helpers.script.websocket_api_script
Bron: helpers/script.py:525
Eerst voorgekomen: 08:17:50 (1 gebeurtenissen)
Laatst gelogd: 08:17:50

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'zoneStates'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 778, in async_handle_set_preset_mode_service
    await self.async_set_preset_mode(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 786, in async_set_preset_mode
    await self.hass.async_add_executor_job(self.set_preset_mode, preset_mode)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tado/climate.py", line 435, in set_preset_mode
    self._tado.set_presence(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 248, in set_presence
    self.update_zones()
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 177, in update_zones
    zone_states = self.tado.get_zone_states()["zoneStates"]
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'zoneStates'

AND

Logger: homeassistant.components.websocket_api.http.connection
Bron: components/tado/tado_connector.py:177
integratie: Home Assistant WebSocket API ([documentatie](https://www.home-assistant.io/integrations/websocket_api), [problemen](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
Eerst voorgekomen: 08:17:51 (1 gebeurtenissen)
Laatst gelogd: 08:17:51

[139974120098688] Error handling message: Unknown error (unknown_error) Yves from 185.77.12.226 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 816, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1795, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 557, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 778, in async_handle_set_preset_mode_service
    await self.async_set_preset_mode(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 786, in async_set_preset_mode
    await self.hass.async_add_executor_job(self.set_preset_mode, preset_mode)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tado/climate.py", line 435, in set_preset_mode
    self._tado.set_presence(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 248, in set_presence
    self.update_zones()
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 177, in update_zones
    zone_states = self.tado.get_zone_states()["zoneStates"]
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'zoneStates'

It's only when I have the script running when I'm leaving. When I get back home there is no issue.

This is the script

alias: Verwarming afwezig
sequence:
  - action: climate.set_hvac_mode
    metadata: {}
    data:
      hvac_mode: auto
    target:
      entity_id:
        - climate.living
        - climate.badkamer
        - climate.douche
        - climate.logeerkamer
        - climate.slaapkamer
        - climate.zolder
        - climate.dressing
  - action: climate.set_preset_mode
    metadata: {}
    data:
      preset_mode: away
    target:
      entity_id:
        - climate.living
        - climate.badkamer
        - climate.douche
        - climate.logeerkamer
        - climate.slaapkamer
        - climate.zolder
        - climate.dressing
mode: single
icon: mdi:heat-wave

What version of Home Assistant Core has the issue?

10.09.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Tado

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tado

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (websocket_api) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `websocket_api` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign websocket_api` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


websocket_api documentation websocket_api source (message by IssueLinks)

home-assistant[bot] commented 1 month ago

Hey there @chiefdragon, @erwindouna, mind taking a look at this issue as it has been labeled with an integration (tado) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tado` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tado` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tado documentation tado source (message by IssueLinks)

erwindouna commented 1 month ago

By any chance that one of the following devices are no longer available or specifically called as mentioned in your list?

The code referenced in your logging is wrapped in a try-catch, so I would expect to see the error being triggered properly in your trace. Are you sure you're on the latest version of HA? :)

    def update_zones(self):
        """Update the zone data from Tado."""
        try:
            zone_states = self.tado.get_zone_states()["zoneStates"]
        except RuntimeError:
            _LOGGER.error("Unable to connect to Tado while updating zones")
            return

        for zone in zone_states:
            self.update_zone(int(zone))
Tazmanian79 commented 1 month ago

Yes I'm using the latest version. (just before october release). Now on latest release again.

When I first noticed this error I hve reloaded the integration. And deleted all entities from the script and added them again, just to be sure. So yes all devices are available.

EDIT: just ran the script again and didn't log any error anymore. Strange. Maybe update to 10.0 solved the issue ;-)

erwindouna commented 1 month ago

Feel free to test it a few times. When its structurally resolved, please close this issue. :)

Tazmanian79 commented 1 month ago

I tried to run the scrip again but now same error:

`Logger: homeassistant.components.script.verwarming_afwezig Bron: helpers/script.py:525 integratie: Script (documentatie, problemen) Eerst voorgekomen: 18:28:41 (1 gebeurtenissen) Laatst gelogd: 18:28:41

Verwarming afwezig: Error executing script. Unexpected error for call_service at pos 2: 'zoneStates' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step response_data = await self._async_run_long_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action return await long_task ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call raise result from None File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call return await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 800, in async_handle_set_preset_mode_service await self.async_set_preset_mode(preset_mode) File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 808, in async_set_preset_mode await self.hass.async_add_executor_job(self.set_preset_mode, preset_mode) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tado/climate.py", line 435, in set_preset_mode self._tado.set_presence(preset_mode) File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 248, in set_presence self.update_zones() File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 177, in update_zones zone_states = self.tado.get_zone_states()["zoneStates"]


KeyError: 'zoneStates'`

`Logger: homeassistant.components.websocket_api.http.connection
Bron: components/websocket_api/commands.py:245
integratie: Home Assistant WebSocket API ([documentatie](https://www.home-assistant.io/integrations/websocket_api), [problemen](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
Eerst voorgekomen: 18:28:41 (1 gebeurtenissen)
Laatst gelogd: 18:28:41

[139902849427360] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 718, in _service_handler
    response = await self._async_start_run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 674, in _async_start_run
    script_result = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 707, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1795, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 557, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1021, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1610, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 800, in async_handle_set_preset_mode_service
    await self.async_set_preset_mode(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 808, in async_set_preset_mode
    await self.hass.async_add_executor_job(self.set_preset_mode, preset_mode)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tado/climate.py", line 435, in set_preset_mode
    self._tado.set_presence(preset_mode)
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 248, in set_presence
    self.update_zones()
  File "/usr/src/homeassistant/homeassistant/components/tado/tado_connector.py", line 177, in update_zones
    zone_states = self.tado.get_zone_states()["zoneStates"]
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'zoneStates'`

![Schermafbeelding 2024-10-04 183630](https://github.com/user-attachments/assets/103e4649-3215-4ad6-9567-53caeecc36e1)

EDIT.

But then when I run it again some time later it runs without any errors
![2de](https://github.com/user-attachments/assets/fae643f9-cb63-494f-a2f8-10b688f8702c)
Tazmanian79 commented 4 weeks ago

Any update on this issue?

erwindouna commented 1 week ago

Can you check if all these zones actually exists? The only thing I can think of, is that there's no zone found. Hence, this is what could trigger the try except.

Tazmanian79 commented 1 week ago

Yes all zones exists .... I even removed the integration and re-added to be sure. But still gives me this error.

erwindouna commented 1 week ago

Does it turn off the integration or put it in a disabled state somewhere?

Tazmanian79 commented 6 days ago

no it does not. It very basic script that runs when leaving the house. But the error is not always there. I'm testing it right now ran it 3 times no error at all.

erwindouna commented 5 days ago

On which version are you currently running? I run on the latest and when I ran it a few times I had no issues. image

The only thing I can think of, is that the devices are put in a disabled state and therefore their backend call results in a false results from the API.

Tazmanian79 commented 5 days ago

I ran it a few times (only the script) and now it doesn't give any error. Will check it next time while the whole automation runs.

Keep you posted.