Hi All,
I have just jumped into the PyScript. I am going to convert all my automation in PyScript but i wanted to know one thing how can i run a automation in Single Mode in PyScript means if suppose there is automation based on motion if motion detected then wait for 10 sec then switch ON the lights but in that duration of 10 sec if again same automation invoked and current automation is in progress than i dont want automation to trigger two times so how can i run the automation in Single mode(Do not start a new Run)
Running into the same issue with a motion detection trigger. Did you ever find a solution?
I am currently using the Autmation GUI and then calling the PyScript function through the @service
trigger. Detailed here in PyScript docs.
Actually found a solution to this. Basically you have to use task.unique("function_name", kill_me=True)
which forces only one instance of a triggered function to operate at a time. Then I added task.sleep(1)
to the end of the function to force the function to run for an extra single second, basically acts as a cool down period for the function.