@joriskofman Glad we are making progress!
Can you provide the full path of the personal folder you are using?
It should be
<OPENHAB_CONF_DIR>/ automation/jsr223/ruby/personal
The directory monitored is handled by the core, not by the JRuby implementation itself. Are you also using Jython? Do those scripts get loaded, etc?
When I create a new script in the openHAB interface and enter some code, pressing the “run now” button, a new line is created under the “rules” section, with the title of the script that was just created.
When I then make changed to the script and deploy it again by pressing the “run now” button a new entry is deployed under the “rules” section, but the old one does not get destroyed. So playing around with the code one can easily end up with many rules that might run at the same time. The only way to destroy these rules is to restart openHAB, as the rules are locked because they are loaded from a file (this is the reason the openHAB interface gives).
I have not played around with the UI method of creating rules, so I will have to experiment with that. When the rules are file based the core takes care of destroying the rules when files are changed / loaded. The scripting libraries don’t handle that part of it. So without looking at it yet I am not sure creating a rule definition within code in the UI is supported. Based on what @rlkoshak said above I think in the UI you are only supposed to put whatever is in the run block above in your rule code and the triggers would be configured in the UI and not in the code blocks. Again though, I haven’t looked at the rule editing in the UI.
Sub scenario 2.1:
Initial state:
NewItem
is OFF
Output:
The reponse in the logger is always only “button changed event”, but only for ON commands, not for OFF commands, or changes from ON to OFF.
OFF commands shouldn’t trigger changed if the switch is already OFF (this is a standard openhab). However, they should trigger from ON to OFF. I added a test to make sure that is the case. Can you take a look here and let me know if I am testing the right thing?
If that doesn’t help with logs set to trace can you go from on to off and provide the logs?
Sub scenario 2.2:
This is something that is not clear and I need to add documentation on. Anything outside of a run or triggered block is executed when the rule is being parsed. The reason it fails to deploy or is “stuck” in running state is because you have a loop that is being processed while while NewItem.truthy?
during the rule processing phase not the rule execution phase. That while loops is adding delays and run blocks onto the rule queue.
I have made an issue to clarify the docs around rule processing and rule execution.
I will need to think about the use case you are trying here for the best way to tackle it. Even if you move it inside of a run block it won’t work the way you want it too. Give me a bit to think about it.