1

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?

Romain Guidoux
  • 2,943
  • 4
  • 28
  • 48

1 Answers1

0

You haven't posted any code, but the error says your code is doing blocking I/O, which is likely because you are using regular http calls, which block.

See the documentation which gives an example of using aiohttp to do async http requests.

craigb
  • 1,081
  • 1
  • 9