How to stop a running script?


I am running a script which is supposed to execute when a squeezebox is being turned on (alarm)
The script also turns the lights on by invoking a script which is changing the dimmer level up to 100 over time.

Is there are possibility to end this script, once I turn the alarm of by hand? Would I do this in the script (while X.state == ON …?) or via a separate rule?

By script, I assume you mean a shell script running via the Exec binding or executeCommandLine Action.

If that is the case the answer is no, there is no way to stop a running script*. The script gets executed in a totally separate thread and it has its own context, a context that executeCommandLine doesn’t return to you and which the Exec binding does not make available to you.

A much better solution would be to use an implementation that is a little more reactive and works via messaging rather than a blocking script, or move the implementaiton of the dimming to a Rule rather than a long running script.

  • NOTE: This isn’t entirely true. You could write another script with the smarts to execute and parse the output of top to find the PID for the running script and issue the kill command to stop that command. But I’m assuming, perhaps erroneously, that the fact you had to post this question means you would find doing this challenging. I would definitely find doing this challenging myself.

Thanks for your feedback.
I am actually using an openhab script, sitting in the scripts folder.
However I have helped myself by putting an additional condition in the “while”-loop I am using and starting the lights already before the loop starts.
As soon as the lights are killed manually, it stops as the condition is !true.

Now I am only fiddling with my Squeezebox Radio which does not seem to update power status when the alarm goes off…