3 different methods to use scenes with Google Home & openHAB

Hi all =) I’ve read the above tutorial, and wanted to add a scene via item/rule definition. I only have one problem I can’t solve. I use paperui and the mobile-app of android for controlling my items…but these only show linked items. Is there a way to get around making extra sitemap and control everything with paperui?

The answer is short. No.

PaperUI is and was only ever intended to be an administration tool, not the main interface for controlling your devices.

To control a proxy Item like this you have to use a sitemap or HABPanel or HABot.

Ok I found a dirty hack…You can install the network binding, add the ip adress of the pi, and bind all scene items to the online-status channel…then they get displayed but do nothing…really dirty but does it’s job…

Okay this doesn’t work very well…the switch became “uncontrollable” which is expected for the network-binding online channel, as it should only show online-stats…I gave up on paperui and wrote a sitemap…the most easy way was with group-items…it will let you setup a sitemap very fast and reliable.

He bartus, first of all, thanks for this great guide!

I am in the midst of enhancing my scene setup and wanted to use your logic, converting it into ECMA, but I do run into some issues.

I created the following groups in my model (as per your guideline; but with some sub-groups):


One difference to your model is my scene items which are string items (compared to your switches) as I do for instance have various room scenes (example: living room can be evening, morning, media etc.; while master bedroom might have less/more scene selections).
I try to account for this in the set rule combining event.itemName+event.itemState+"_"+item.name.

I got as far as having the rule (in ECMA) running for copying states to the storage items:

Store Rule:
//Set item variables

var livingroom_ceilinglamp_center_onoff = itemRegistry.getItem("livingroom_ceilinglamp_center_onoff").getState ();
var livingroom_ceilinglamp_center_dimmer = itemRegistry.getItem("livingroom_ceilinglamp_center_dimmer").getState ();


if(event.itemName == "scene_config_livingroom_evening_store") {
  events.sendCommand("scene_livingroom_evening_livingroom_ceilinglamp_center_onoff", livingroom_ceilinglamp_center_onoff);
  events.sendCommand("scene_livingroom_evening_livingroom_ceilinglamp_center_dimmer", livingroom_ceilinglamp_center_dimmer);
  //Log.logInfo("TEST", "TESTing AVG" + " " + lastUpdate);
  events.postUpdate("scene_config_livingroom_evening_store", "OFF");

But I run into issues with the flexible “set” rule. Tried to adapt it and make it ECMA compliant but I do run into issues:

Set Rule:
var g_scene_items = ir.getItem("g_scene_items");
//var g_scene_items = ir.getItem("g_scene_livingroom_evening_items");
var g_scene_states = ir.getItem("g_scene_states");

  //var items = g_scene_items.members.findFirst([ grp | grp.name == "g_"+event.itemName+event.itemState+"_items" ]);
  var items = g_scene_items.members.findFirst[ function(grp) { return grp.name == "g_"+event.itemName+event.itemState+"_items" }];

    // Loop through all the Items controlled by this scene
    items.members.forEach[ function(i) {

        //logInfo("Lights", "Lighting Rule getting " + triggeringItem.name+"_"+i.name + " state")

        // Get the state for this Item and Scene
        //var sceneState = g_scene_states.members.findFirst[ GenericItem st | st.name == event.itemName+event.itemState+"_"+item.name ]
        var sceneState = g_scene_states.members.filter[ function(id) { return id.name == event.itemName+event.itemState+"_"+item.name }]

        //logInfo("Lights", triggeringItem.name+"_"+i.name + " state: " + sceneState.state)
        //logInfo("Lights", "Item to change: " + i.name)

        // sendCommand the Scene state
        if(sceneState !== null)

As you can see from the “//” I tried a few different combinations of the findFirst line (which is giving me an error as following (I am sure there will be more errors once this is fixed :slight_smile: ):

2022-01-02 17:16:08.594 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'rule_test4' failed: TypeError: Cannot read property "function(grp) { return grp.name == "g_"+event.itemName+event.itemState+"_items" }" from undefined in <eval> at line number 44

Would be very grateful for any direction on this as I am also not a full expert in ECMA coding.

I can’t help much with this rule but would all of you saw the Scene Control Suit rule templates and UI widget in the Marketplace.

Note, the list of members you get back is a Java List Object, not JavaScript, and you do not have the syntactic sugar that Rules DSL adds which let’s you call findFirst like that.

In JSScripting ooenhab-js converts it to a JS Array so you can do this sort of thing in the normal ECMA 11 way. In Nashorn I don’t think Array supports findFirst and filter and such so you’ll want to use the Java Streaming API instead and stick with the Java List.

1 Like

Thanks Rich!

I will then first stick with version 3 as it seems to be simple to implement (just quite a few code blocks to do) and afterwards look into Jsscripting (anyway wanted to move everything over at some point)/the scene suite.

Please do consider looking at the marketplace. You may not need to code anything at all.