Is it possible to run concurrent HomeAssistant Service call? #527
Replies: 1 comment
-
I think the answer here is to have a decorated function, which PyScript will start as soon as the script loads. It then runs as a coroutine. I think an issue with this is that it will run to perpetuity, i.e. refreshing PyScript scripts won't kill it. But also on my Pi 3B+ it gets reaped by the watchdog all the time, so it's not super useful at least when you use it to change state of lights. @task_unique('background_pyscript', kill_me=False)
@time_trigger('startup')
def async_foo():
pass |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to write a service handler that listens to a service, and can be called more than once at a time. Right now, the error I get if I call that service and it's already running, is this:
2023-09-25 22:11:19.278 WARNING (MainThread) [homeassistant.components.automation.r2_all_service_call] Circle Remote - All Service Call: Already running
What can I do to allow HomeAssistant to call my code twice, concurrently? This looks like a HomeAssistant error, not a PyScript error.
Ultimately, I want to be able to listen for a button press from a zigbee remote, run a background task that listens to a variable internal to PyScript, and when I press another button on that zigbee remote, the second button press will change that variable and tell the first background task to stop.
For instance, press and hold the 'dim' button on a Tradfri remote, lower the brightness once every second, and then stop dimming once the remote signals the button is no longer being pressed.
My only hurdle is how to make two service calls run concurrently.
The service calling my PyScript event handler is a catch-all zha_event Event Trigger. I don't think switching back to a Device **Trigger** will help here? It's also way more verbose.
I thought maybe there's a way to detach my code from the service, and have some background task in PyScript? Maybe I missed something in the docs?
All the best,
Jacob C
Beta Was this translation helpful? Give feedback.
All reactions