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.56k stars 30.74k forks source link

automation asyncio task is broken #117431

Closed J4nM closed 5 months ago

J4nM commented 5 months ago

The problem

I have an automation that reacts on my garage door opening but since the May release it is broken. I can reproduce with a very minimal config. Simply monitoring the state of a switch on the door, if going from "off" to "on" , send a message.

What version of Home Assistant Core has the issue?

Core 2024.5.3

What was the last working version of Home Assistant Core?

Core 2024.4.x

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Automation

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

id: '1715516304603'
alias: Garage_door
description: ''
trigger:
  - platform: state
    entity_id:
      - switch.garagedoor
    from: 'off'
    to: 'on'
condition: []
action:
  - service: notify.mobile_app_jans_iphone13_pro
    data:
      title: Garaget öppet!
      message: //Homeassistant
      data:
        apns_headers:
          apns-collapse-id: garage-open

Anything in the logs that might be useful for us?

May 14 14:47:27 homeassistant hass[1399737]: 2024-05-14 14:47:27.394 WARNING (SyncWorker_1) [homeassistant.helpers.frame] Detected that integration 'automation' attempted to create an asyncio task from a thread at homeassistant/components/automation/__init__.py, line 723: return await self.action_script.async_run(, please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+automation%22
May 14 14:47:27 homeassistant hass[1399737]: 2024-05-14 14:47:27.394 ERROR (SyncWorker_1) [homeassistant.components.automation.garage_door] While executing automation automation.garage_door
May 14 14:47:27 homeassistant hass[1399737]: Traceback (most recent call last):
May 14 14:47:27 homeassistant hass[1399737]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/components/automation/__init__.py", line 723, in async_trigger
May 14 14:47:27 homeassistant hass[1399737]:     return await self.action_script.async_run(
May 14 14:47:27 homeassistant hass[1399737]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 14 14:47:27 homeassistant hass[1399737]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/script.py", line 1731, in async_run
May 14 14:47:27 homeassistant hass[1399737]:     return await asyncio.shield(create_eager_task(run.async_run()))
May 14 14:47:27 homeassistant hass[1399737]:                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 14 14:47:27 homeassistant hass[1399737]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/util/async_.py", line 29, in create_eager_task
May 14 14:47:27 homeassistant hass[1399737]:     loop = get_running_loop()
May 14 14:47:27 homeassistant hass[1399737]:            ^^^^^^^^^^^^^^^^^^
May 14 14:47:27 homeassistant hass[1399737]: RuntimeError: no running event loop

Additional information

## System Information

version | core-2024.5.3
-- | --
installation_type | Home Assistant Core
dev | false
hassio | false
docker | false
user | homeassistant
virtualenv | true
python_version | 3.12.2
os_name | Linux
os_version | 4.18.0-348.7.1.el8_5.x86_64
arch | x86_64
timezone | Europe/Stockholm
config_dir | /home/homeassistant/.homeassistant
bdraco commented 5 months ago

Please follow the instructions at https://community.home-assistant.io/t/2024-5-tracking-down-instability-issues-caused-by-integrations/724441 to find the integration causing the problem

J4nM commented 5 months ago

It appears to be tellduslive and that makes sense since it's a Telldus door switch.

May 15 10:21:09 homeassistant hass[1659604]: 2024-05-15 10:21:09.238 WARNING (SyncWorker_8) [homeassistant.helpers.frame] Detected that integration 'tellduslive' calls async_write_ha_state from a thread at homeassistant/components/tellduslive/entry.py, line 53: self.async_write_ha_state(), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+tellduslive%22
May 15 10:21:09 homeassistant hass[1659604]: 2024-05-15 10:21:09.238 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140646000053440] Unexpected exception
May 15 10:21:09 homeassistant hass[1659604]: Traceback (most recent call last):
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
May 15 10:21:09 homeassistant hass[1659604]:     response = await hass.services.async_call(
May 15 10:21:09 homeassistant hass[1659604]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/core.py", line 2738, in async_call
May 15 10:21:09 homeassistant hass[1659604]:     response_data = await coro
May 15 10:21:09 homeassistant hass[1659604]:                     ^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/core.py", line 2779, in _execute_service
May 15 10:21:09 homeassistant hass[1659604]:     return await target(service_call)
May 15 10:21:09 homeassistant hass[1659604]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 975, in entity_service_call
May 15 10:21:09 homeassistant hass[1659604]:     single_response = await _handle_entity_call(
May 15 10:21:09 homeassistant hass[1659604]:                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
May 15 10:21:09 homeassistant hass[1659604]:     result = await task
May 15 10:21:09 homeassistant hass[1659604]:              ^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1680, in async_turn_on
May 15 10:21:09 homeassistant hass[1659604]:     await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
May 15 10:21:09 homeassistant hass[1659604]:   File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
May 15 10:21:09 homeassistant hass[1659604]:     result = self.fn(*self.args, **self.kwargs)
May 15 10:21:09 homeassistant hass[1659604]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/components/tellduslive/switch.py", line 48, in turn_on
May 15 10:21:09 homeassistant hass[1659604]:     self._update_callback()
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/components/tellduslive/entry.py", line 53, in _update_callback
May 15 10:21:09 homeassistant hass[1659604]:     self.async_write_ha_state()
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
May 15 10:21:09 homeassistant hass[1659604]:     self.hass.verify_event_loop_thread("async_write_ha_state")
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/core.py", line 440, in verify_event_loop_thread
May 15 10:21:09 homeassistant hass[1659604]:     frame.report(
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/frame.py", line 162, in report
May 15 10:21:09 homeassistant hass[1659604]:     _report_integration(what, integration_frame, level, error_if_integration)
May 15 10:21:09 homeassistant hass[1659604]:   File "/home/homeassistant/Envs/HA/lib/python3.12/site-packages/homeassistant/helpers/frame.py", line 203, in _report_integration
May 15 10:21:09 homeassistant hass[1659604]:     raise RuntimeError(
May 15 10:21:09 homeassistant hass[1659604]: RuntimeError: Detected that integration 'tellduslive' calls async_write_ha_state from a thread at homeassistant/components/tellduslive/entry.py, line 53: self.async_write_ha_state(). Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+tellduslive%22.
home-assistant[bot] commented 5 months ago

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

Code owner commands Code owners of `tellduslive` 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 tellduslive` 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)


tellduslive documentation tellduslive source (message by IssueLinks)

J4nM commented 5 months ago

Many thanks, works perfectly. No other issues seen.