Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tutorials/getting_started/rules_scenes.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ Use the following block and add the _scene id_ to the block to call the scene
Save it and that's it.
:::

::: tab JS
::: tab Groovy

```groovy
var ruleManagerBundleContext = org.osgi.framework.FrameworkUtil.getBundle(org.openhab.core.automation.RuleManager).bundleContext

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, it might make sense to use the bundle context of the Groovy scripting bundle as this is what executes the code and "owns" its resources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is tried and it works for Groovy, DSL Scripts, and DSL Rules at the same time.

I cannot say anything about using different bundleContext, as I do not understand it.

var ruleManagerServiceReference = ruleManagerBundleContext.getServiceReference(org.openhab.core.automation.RuleManager)
var ruleManager = ruleManagerBundleContext.getService(ruleManagerServiceReference)
ruleManager.runNow("scene_office_dimmed_light")
ruleManagerBundleContext.ungetService(ruleManagerServiceReference)
```

:::

::: tab JS Scripting

```javascript
rules.runRule('scene_office_dimmed_light', {});
Expand All @@ -127,7 +139,7 @@ Save it and that's it.
rules[“id”] gives you the rule object for the given id, which supports the [trigger method](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Rules/Rule.html#trigger-instance_method) (aliased as run).

```ruby
rules["scene_id"].run
rules["scene_office_dimmed_light"].run
```

::::