Scene Control Suite - Scene Activation

hi there

thank you for your idea and your widget. It hink I don´t know how to get it to work, as my widget stays empty.


Widget_2

I’ve created one rule for activation, and one for modification.

configuration:
  undoSettings: false
  triggerState: ON
  sceneController: Scene_Controller
  triggerItem: KNX_Buero_DL_schalten
triggers:
  - id: "4"
    configuration:
      itemName: KNX_Buero_DL_schalten
      command: ON
    type: core.ItemCommandTrigger
conditions:
  - inputs: {}
    id: "3"
    configuration:
      itemName: Scene_Controller
      state: "true"
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >-
        /*

        This Script activates the items in a Scene Controllers ActiveItems metadata.

        */

        //Nashorn and JSscripting compatibility

        if(typeof(require) === "function") Object.assign(this, require('@runtime'));

        //Set Logger

        var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.runController');


        //Access MetadataRegistry

        var FrameworkUtil = Java.type('org.osgi.framework.FrameworkUtil');

        this.ScriptHandler = Java.type("org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler");

        var _bundle = FrameworkUtil.getBundle(ScriptHandler.class);

        var bundle_context = _bundle.getBundleContext();

        var MetadataRegistry_Ref = bundle_context.getServiceReference('org.openhab.core.items.MetadataRegistry');

        var MetadataRegistry = bundle_context.getService(MetadataRegistry_Ref);

        var MetadataKey = Java.type('org.openhab.core.items.MetadataKey');


        //Function To Read Scene Metadata And Activate Items

        run_controller = function (controllerID, undoSettings) {
        	undoSettings = undoSettings || false;
        	var metaList = MetadataRegistry.get(new MetadataKey('ActiveItems',controllerID));
        	if (metaList && undoSettings) {
        	var configList = metaList['configuration'];
        	for (var id in configList) {
        		events.sendCommand(id,(configList[id] == 'ON') ? 'OFF' : ((configList[id]) == 'OFF' ? 'ON' : configList[id]));
        	};
        	} else if (metaList) {
        	var configList = metaList['configuration'];
        	for (var id in configList) {
        		events.sendCommand(id,configList[id]);
        	};
        	} else {
        	logger.info(['No items currently controlled by ',controllerID].join(''));
        	};
        };


        //Activate

        run_controller('Scene_Controller',false)
    type: script.ScriptAction

The modification rule is emty.

BR

The widget only shows items that have been configured with the proper tag. Have you read through the setup section on the tutorial? If you have the proper items, they will show up in the widget whether the rules are properly configured or not.

How did you create the rules? The text you’ve posted is not correct, it still contains the configuration section of the rule template. These rules are posted here in the market-place as rules templates, which are not exactly the same as rules. You have to install the rules templates using the Add-onsAutomation section of the settings page of your OH instance. Then these rule templates get translated into correctly formatted rules if you create a new rule using the template.

If you did install using the market-place, what version of OH are you using?

Hi Justin

First of all, I must apologize for my late feedback.
I have now found the error and the controller items show up in the list.

I have also created the two rules.
Unfortunately, it still does not seem to work.
When I change something in the widget or press refresh, I see it in the log files as follows:

2022-04-18 22:26:28.880 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Rule_SceneModify' changed from Scene_Guten_Morgen,KNX_Buero_DL_schalten,REFRESH to None

I have the two rules in the attachment.

If I now switch the Activation Item DL_Buero to ON, nothing happens.

Somewhere I seem to have a logical error

BR
Daniel
activation_rule.txt (2.5 KB)
modify_rule.txt (3.8 KB)

That should be correct. When you click on one of the actions in the widget, the widget sends a command to the Rule_SceneModify item that is a string with various information in it. When that item changes its state in response to the command, it triggers the modify rule. The modify rule reads the information it needs from the item state and performs the indicated modification. As a last step, the rule then resets the value of the rule item to None. The fact that you are seeing that line in the log means that the modify rule is running properly.

It looks like there are two issues with your activation rule in the condition section (the ‘But only if…’ part of the rule).

  1. Your configuration state says true instead of ON, but that’s because there was a bug in the way the rules templates were setting some values. I fixed that error a couple days ago, but if you still have the old version you downloaded before then you’re still subject to that error when you create a new activation rule. You can get the new version with the bug fix, by removing and re-adding the rule template.

  2. You have configured the condition item to be Rule_SceneModify when this is intended to be the name of the controller item (in the example you sent Scene_Guten_Morgen). The idea here is to take advantage of the fact that the scene controllers are switches and allow you to disable the scene. You want your Guten Morgen scene to run most mornings, I imagine, but what if you’re on vacation? Maybe it doesn’t make sense to have the scene run then. In that case you can use the widget to switch the scene controller to off (“disabled” in the widget). The activation rule is supposed to check the state of the scene controller itself before activating and if the scene controller has been set to OFF (deactivated) the then rule will not run.

One way or the other you want the rule to look like this in the end if you want to use this ability to disable the scene:


Only in your case the item is Scene_Guten_Morgen.

Thank you - now it works like a charm.

I really appreciate your help

BR
Daniel

1 Like

I guess this is was not update for OH4 since the last post was almost 18 months ago

I have not updated this for OH4. In OH you now have access to the built in scenes, so this seemed redundant, and, in fact, I no longer use it myself. I just use the native OH scenes.

Off the top of my head, however, I can’t think of any reason why it should have any conflicts with OH4.

1 Like

It doesn’t like the call to library for the controller function. I am working on converting to the built in scenes now.

I’m not sure what this actually refers to; this rule doesn’t use any external libraries. But, if you’re going to the built in scenes anyway, then I won’t worry about.

Just out of curiousity, how do handle enabling and disabling scenes?

I have one additional switch item for each scene. In the rule that calls the scene to run, that switch item is checked in the rule conditions. So if the switch is off, the scene will not be activated even if the other triggers for the rule do occur. (In fact, I have several such items as there are also generic times when whole batches of scenes are disabled such as when the family is on vacation.)

You can also, if you prefer, use rules to control whether other rules (including scenes) are enabled or disabled via the rule actions.

1 Like

Thanks

It might be worth adding the versioning string to the title so it doesn’t show up in MainUI for those running OH 4. “[3.3.0;3.4.9)” captures all OH 3 versions from 3.3.0 to the last 3.4 release but will hide these entries in MainUI for those running OH 4.

The warning there is you’ll get an error in the logs when a disabled rule (a Scene is just a rule after all) is called.