-
Hello everybody, first of all I am quite new to python and usually wrote my scripts in javascript for IoBroker. But since I want to switch to HomeAssistant and have some more or less complex scripts written in javascript, I was looking for a way to write scripts with a similar complexity for HA. So this is how I came across pyscript. Unfortunately, I am now stuck for multiple hours (even with chatGPT) and can not find a solution for my, what I would call, simple first usecase: But until now, I did not even manage to create a parallel running function without blocking the other function. Here is my minimal example:
What happens is, that the log.info("This should be printed directly after starting the timer.....") is only visible in the protocoll after the 5s timer expires. So basically the timer_task() blocks the handle_triggered() task. Additionally I get an error at the end which says: 2025-07-27 21:14:29.243 ERROR (MainThread) [custom_components.pyscript.function] run_coro: got exception Traceback (most recent call last): And I really do not understand why. So if there is any expert who can help me, I would be really really grateful! Thanks, Ben |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Try task.sleep? And review what the Reference doc says about async, just to make sure it aligns with what you expect. |
Beta Was this translation helpful? Give feedback.
-
The tutorial has some examples that are similar to what you trying to do. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help! Task.sleep did work finally! |
Beta Was this translation helpful? Give feedback.
Try task.sleep? And review what the Reference doc says about async, just to make sure it aligns with what you expect.