How to execute a Python script that connects to a websocket on an external URL?

Hi, I am using Home Assistant and I would like to execute a Python script every 30 minutes. To do that I am using pyscript with the @time_trigger("cron(...)") annotation.

However my script connects to a websocket (to an external URL, not the one of HASS) and I get the following error:

    2022-02-01 18:48:00 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for pyscript doing I/O at custom_components/pyscript/eval.py, line 1899: return func(*args, **kwargs)
    2022-02-01 18:48:00 ERROR (MainThread) [custom_components.pyscript.file.tydomCalls.test_service] Exception in <file.tydomCalls.test_service> line 179:
            conn.request("GET", "/mediation/client?mac={}&appli=1".format(mac), None, httpHeaders)
                                                                                      ^
    RuntimeError: I/O must be done in the executor; Use `await hass.async_add_executor_job()` at custom_components/pyscript/eval.py, line 1899: return func(*args, **kwargs)

So I wonder how I can execute my script, if pyscript doesn’t allow that?

Thanks

Nobody has an idea? :frowning:

Hello @RomainGx!
I had a same problem with this error and I found a solution here: https://github.com/custom-components/pyscript/issues/268
There is a link to docs with advice to use task.executor function. It helped me.
And I hope it will help you too!