Creating persistent async tasks

I’m developing an integration where the api uses asyncio and requires an event loop in the form of a Coroutine to be called. I had attempted to use hass.async_create_task to generate a task and run the event loop however because the task doesn’t complete until the api is shutdown the startup of home assistant gets stalled in async_block_til_done. The work-around is to create the task outside of home assistant’s APIs (e.g. using asyncio.create_task) however this doesn’t seem like a good solution.

Is there an intended approach to this such as running these types of Coroutines after the start phase?

1 Like

Did you ever find a solution? I have the exact same issue.

I faced the same issue for ha-nest-protect (custom component) and in the end I settled for asyncio.create_task

Yep, that’s what I do also in this custom component. Been working fine for many users for a long time.