I think Rich also asked you to add the duration parameter and capture the return value, so that you can see what if any error message is being returned.
I haven’t run the below code, but it would look something like the following.
I’m new to openHAB, and started playing with openHAB 3.1. Version number implies a mature experience, although I spent mockerflopping days trying to get some sense of logical hierarchy in script flow.
As I was about to give up, I stumble upon this gem of a post! I can finally execute ui scripts from rule scripts! Thanks a lot to the people figuring this out, repeating the solution, and clicking the google result enough for it to rank high enough for me to notice.
I probably made a bad choice that first moment in openHAB where I decided to use ECMAscript, because it seems to be a bit of a second class citizen in reality, and a 9000th class citizen in the openHAB documentation.
It would save me some time because I already know ECMAscript, or so I thought. Little did I know…
PS in case writing 7 lines of code messes with your zen too, just put the longer lines at the top.
var BundleContext = Java.type('org.osgi.framework.FrameworkUtil').getBundle(scriptExtension.class).getBundleContext()
var RuleManager = BundleContext.getService(BundleContext.getServiceReference('org.openhab.core.automation.RuleManager'))
// At some point
RuleManager.runNow('0bdeadbeef')
Calling another rule is now built into openhab-js. But you might need to install the latest until the next release of OH where it should be included with the add-on.
Using npm i openhab from the $OH_CONF/automation/js folder.
Then
rules.runRule(<uid of rule>, <optional map of data to pass>, <optional boolean, when true the called rule's conditions will apply>)