How to Trigger Scenes Properly

I’m unclear about how scenes actually work in Openhab. The docs don’t mention them, and most of the forum discussion about them is 2-3 years old, and lacking introductory information.

I’m trying to set up two remotes, to be set on either side of the bed, which will control multiple dimmable lights in our bedroom. I’ve currently got the first remote working, but now I’m trying to set up the second one as well, and I’m running into issues.

I’ve been using this method to control the dimmers from the remote, which has been working okay, but it’s very laggy sometimes, or sometimes commands get dropped completely. Basically, when the remote registers a button press (via a scene_number channel), my rule checks the current state of the dimmers (which I’m storing in scene_number_1, on the remote), performs some logic, sends an update command to the dimmers, then stores the new scene number on the remote. Now that I’m adding a second remote to the code, I’m thinking I’m going about this all wrong.

Basically, I feel like I should be using actual “scenes”, which I believe should allow the remote to control the dimmers directly, without having to route messages through the controller. Instead, what I’m currently doing is setting up rules, which specify specify certain brightness levels to set the dimmers to, based on input from the remote. But all of that logic is handled on the controller.

How does one go about actually setting up scenes, so that the remote controls the dimmers directly? Does this involve setting up association groups as well?

How do you program custom functionality for that, for example, if I want either remote to be able to define 5 custom brightness levels? As I understand it, the only way to do that is with rules and scripts, which are stored on the controller.

I’m currently on OH 2.3.0, but I’ll be upgrading to 2.4.0 soon, if that changes things.

Thanks for your help.

What remote are you using?
How are your remotes connected to openHAB? (What zwave dongle and what zwave binding version)

I’m using the Aeon Z-Stick Gen5, 2 Aeon Smart Dimmer 6’s, and 2 Aeon Wallmote Quads. I’m not sure about the binding version. It’s whatever version that gets installed by default in OH 2.3.0.

Correct

You can use this approach:

I can’t help with a hardware solution, because I do not know your hardware. But did you check this variation of the original approach?

I’m not really concerned about how to write the code to be able to get a remote to trigger some actions. I’ve already got that part working for one remote, and I’m confident I will be able to figure it out for two.

What I’m really wondering about is what is this concept of a Zwave “scene” and how can you trigger these actions in such a way that the remote can control the devices directly, without having to pass the signals through the controller? It sounds like it should be possible, but I’m not sure how that’s done. I’m guessing you have to set up association groups, but are you able to leverage your rules and scripts when you do that?

Well that’s two completely different things you better don’t mix.
You can have a pushbutton device or remote that you can directly associate with one or more dimmers of yours. Dimming usually works fine with a decent remote that’s made for this purpose (it will then have pairs of button for up/down or toggles direction on every press).
Albeit some people or vendors call it a scene if you associate multiple lights to one remote button pair, scenes is something different. If dimming multiple lights in parallel is what you want build it like this and don’t use the ZWave scene features at all.

A scene doesn’t allow for interactive dimming - a scene allows for setting a defined light level only (well unless you ‘dynamize’ it that every scene command in a series of commands also changes the light level which is probably what your scripts do).
If your remote does not have button pairs and you want to use two of its button for dimming one or more device, that’s sort of a misuse and an awkward solution that does not work fine (as you noticed yourself).
Get a device with button pairs that allows for setting direct associations such as the Fibaro FGD-212 or ZWave.me remote that I have.

A true scene item would be something like
Number Szenenschalter "Szenenschalter Essen/Wohnen" <switch> (Szenen) { channel="zwave:device:xxxxxxxx:node51:scene_number" }

That item is being sent a command (usually a number, but I don’t know the Aeotec device) if one of the remote’s button are pressed. This you can trigger on and do whatever you want in a rule.
But it’s a one time action.

2 Likes

Thanks @mstormi! I think that’s getting to the crux of the issue.

So, if I understand you correctly, I won’t be able to associate the remote to the dimmers directly, unless I utilize the remote’s built-in functionality. Otherwise, I just have to code a solution, myself, in which case it will require the Z-Wave controller. Correct?

In my case, I’m using Aeon’s Wallmote Quad, which is really just a generic scene controller; it’s not really specifically designed as a dimmer controller. Therefore, I have to rely on programming scenes which will require the use of the controller, since it doesn’t really have the built-in ability to control dimmers.

Is that generally correct?

It’s unfortunate because I feel like the latency involved in passing the signal off to the controller, which then gets sent back to the dimmers, is causing it to respond very slowly. Also, I frequently re-deploy my OH Docker container when I make configuration changes, and the remote and dimmer setup stops working while the system is re-deploying. However, my Aeon Nano Dimmer, which is installed in the kitchen, continues to operate with the toggle switch it’s attached to while the system is down. I think it’s because I’m not utilizing any rules or scripts with that, just it’s native functionality.

yes

There is a whole host of things that can cause latency problems. You can and should look in the the debug or trace zwave binding logs to see if that appears to be the case. In my experience, the round trip zwave message traffic is well below half a second. But if you have a sparse and not well connected network then that alone could cause latency problems as messages need to be repeated. Bypassing OH will likely not help much to solve this problem. The addition of more mains powered devices will help.

I’ve also seen latency when there is only one mains powered device that is a neighbor to the controller. Again, adding one or more additional mains powered zwave devices to give more than one path to the controller cleared that up.

Why “frequently” and how long does OH take to come back online? As long as you want OH to be the home automation hub of your system, this is going to always be a problem. It might be time to come up with a development approach that doesn’t require so many redeployments.

In that case the entire system is self contained. You are basically operating a “dumb” dimmer switch with no communication with anything else. This is why I personally recommend smart switches over smart bulbs. Even when everything else is down, they can still operate as a “dumb” switch.

Since I commit all of my config changes, I like to redeploy it from time to time, to make sure the changes take effect properly upon deployment. Also to ensure my deployment process is still working properly. That way, if my system goes down for any reason, I know I won’t lose any config changes. Also, I’m still learning how OH works, and I’m re-configuring stuff like my rules and deployment scripts as I continue to learn more.

As to your second question, it takes 20 minutes or so for everything (PaperUI and Habmin, for example) to load up and be usable.

I use the WallMote Quad as a Scene controller and the ZStick from Aeotec in rules. It works very well

Here is a video of it in action, there is no lag whatsoever, its instant. I run OH2 on a fairly grunty Cisco UCS system as I want no issues with performance.

I also use if statements within my scene rules and again, it causes no issue. Its actually great you can do this with OpenHab as I make quite a few different checks on states with regards to some functions on the WallMotes.

This is my partner using/demonstrating the system.

1 Like

Hi Dastrix,
Your video looks amazing ! it’s right like i would like to have in my home.
I have purchased a 4 button remote control and would like to use it to turn on lights in different rooms.
Any chance you are whiling to share with us your configuration files (items, things & rules) ?
Thanks,

1 Like

Certainly.

Rules:


rule "Aeotec 'WallMote' - Kitchen"
when
        Item Kitchen_AeoButton_Scene received update
then
        var int sceneNumber = Kitchen_AeoButton_Scene.state as DecimalType

        switch (sceneNumber) {

        case 1.0 : {
            logInfo("Aeotec Button Kitchen", "single press: " + sceneNumber)
            if (KitchenBarSw1.state == OFF) {
               KitchenBarSw1.sendCommand(ON)
               }
            else if (KitchenBarSw1.state == ON) {
               KitchenBarSw1.sendCommand(OFF)
               }
        }
        case 2.0 : {
            logInfo("Aeotec Button Kitchen", "single press: " + sceneNumber)
            if (KitchenSw1.state == OFF) {
               KitchenSw1.sendCommand(ON)
               }
            else if (KitchenSw1.state == ON) {
               KitchenSw1.sendCommand(OFF)
               }
        }
        case 3.0 : {
            logInfo("Aeotec Button Kitchen", "single press: " + sceneNumber)
            if (LivingRoomSw1.state == OFF) {
               LivingRoomSw1.sendCommand(ON)
               }
            else if (LivingRoomSw1.state == ON) {
               LivingRoomSw1.sendCommand(OFF)
               }
        }
        case 4.0 : {
            logInfo("Aeotec Button Kitchen", "single press: " + sceneNumber)
            if (BackEveSw1.state == OFF) {
               BackEveSw1.sendCommand(ON)
               }
            else if (BackEveSw1.state == ON) {
               BackEveSw1.sendCommand(OFF)
               }
        }


}
end


rule "Aeotec 'WallMote' - Front Door"
when
        Item FrontDoor_AeoButton_Scene received update
then
        var int sceneNumber = FrontDoor_AeoButton_Scene.state as DecimalType

        switch (sceneNumber) {

       case 1.0 : {
            logInfo("Aeotec Button Frnt Door", "1x press: " + sceneNumber)
             if (DaikinACUnit_Power.state == OFF) {
               DaikinACUnit_Power.sendCommand(ON)
               Echo_Dining_TTS.sendCommand("Air conditioning switched on")
                }
            else if (DaikinACUnit_Power.state == ON) {
               DaikinACUnit_Power.sendCommand(OFF)
               Echo_Dining_TTS.sendCommand("Air conditioning switched off")
               }

        }
        case 2.0 : {
            logInfo("Aeotec Button Front Door", "Button 2 single press: " + sceneNumber)
            if (vTimeOfDay.state == "EVENING") {
              KitchenBarSw1.sendCommand(ON)
              gGardenLights_5Minutes.sendCommand(ON)
              Echo_Dining_TTS.sendCommand("Welcome home")
              }
        }
        case 3.0 : {
            logInfo("Aeotec Button Front Door", "Button 3 single press: " + sceneNumber)
            Echo_Dining_TTS.sendCommand('All devices switched off, See you later')
            Scene_Leaving_Home.sendCommand(ON)
            DoorBird_DoorOpener.sendCommand(ON)
        }
        case 4.0 : {
            logInfo("Aeotec Button Front Door", "Button 4 single press: " + sceneNumber)
            Doorbell_OpenDoor1.sendCommand(ON)
            Echo_Dining_TTS.sendCommand("Front Gate unlocked")
        }
}
end



rule "Aeotec 'WallMote' - Bedroom "
when
        Item BedRoom1_AeoButton_Scene received update
then
        var int sceneNumber = BedRoom1_AeoButton_Scene.state as DecimalType

        switch (sceneNumber) {

       case 1.0 : {
            logInfo("Aeotec Button Bedroom", "Button 1 1x press: " + sceneNumber)
             if (gAllLights.state == ON) {
             gAllLights?.members.filter[Lights | Lights.state==ON].forEach[ LightsON |
               LightsON.sendCommand(OFF)
              ]
                }
             if (LivingRoomMotion_Armed.state == OFF) {
               LivingRoomMotion_Armed.sendCommand(ON)
                }
             if (FrontDoor_DoorLock.state == OFF) {
               FrontDoor_DoorLock.sendCommand(ON)
               Echo_Dining_TTS.sendCommand('Locking the front door')
                }
             if (Heater.state == 'HeaterOn') {
               Heater.sendCommand('HeaterOff')
               Echo_Dining_TTS.sendCommand('Turning the heater off')
                }
            else if (LivingRoomDim1.state == 0) {
               LivingRoomDim1.sendCommand(5)
               }
       }
       case 2.0 : {
            logInfo("Aeotec Button Bedroom", "Button 2 1x press: " + sceneNumber)
             if (DiningRoomSw1.state == OFF) {
              DiningRoomSw1.sendCommand(ON)
                }
            else if (DiningRoomSw1.state == ON) {
               DiningRoomSw1.sendCommand(OFF)
               }
       }
       case 3.0 : {
           logInfo("Aeotec Button Bedroom", "Button 2 1x press: " + sceneNumber)
             if (BedRoom1Sw1.state == OFF) {
              BedRoom1Sw1.sendCommand(ON)
                }
            else if (BedRoom1Sw1.state == ON) {
               BedRoom1Sw1.sendCommand(OFF)
               }
       }
       case 4.0 : {
           logInfo("Aeotec Button Bedroom", "Button 2 1x press: " + sceneNumber)
             if (BedRoom2Sw1.state == OFF) {
              BedRoom2Sw1.sendCommand(ON)
                }
            else if (BedRoom2Sw1.state == ON) {
               BedRoom2Sw1.sendCommand(OFF)
               }
       }
}
end

Items:



/*ZWave Aeotec WallMote Kitchen */
Number Kitchen_AeoButton_Scene     "Aeotec Kitchen Button"                                                                          { channel="zwave:device:12c97eda:node17:scene_number" }
Number Kitchen_AeoButton_Battery   "Aeotec Kitchen Battery"          (gBatteries)                                             { channel="zwave:device:12c97eda:node17:battery-level" }
String Kitchen_AeoButton_Slide1    "Aeotec Kitchen #1 Button"                                                                       { channel="zwave:device:12c97eda:node17:switch_startstop1" }
String Kitchen_AeoButton_Slide2    "Aeotec Kitchen #2 Button"                                                                       { channel="zwave:device:12c97eda:node17:switch_startstop2" }
String Kitchen_AeoButton_Slide3    "Aeotec Kitchen #3 Button"                                                                       { channel="zwave:device:12c97eda:node17:switch_startstop3" }
String Kitchen_AeoButton_Slide4    "Aeotec Kitchen #4 Button"                                                                       { channel="zwave:device:12c97eda:node17:switch_startstop4" }

/*ZWave Aeotec WallMote Front Door */
Number FrontDoor_AeoButton_Scene      "Aeotec Front Door Button"                                 { channel="zwave:device:12c97eda:node18:scene_number" }
Number FrontDoor_AeoButton_Battery    "Aeotec Front Door Battery"          (gBatteries)          { channel="zwave:device:12c97eda:node18:battery-level" }
String FrontDoor_AeoButton_Slide1     "Aeotec Front Door #1 Button"                              { channel="zwave:device:12c97eda:node18:switch_startstop1" }
String FrontDoor_AeoButton_Slide2     "Aeotec Front Door #2 Button"                              { channel="zwave:device:12c97eda:node18:switch_startstop2" }
String FrontDoor_AeoButton_Slide3     "Aeotec Front Door #3 Button"                              { channel="zwave:device:12c97eda:node18:switch_startstop3" }
String FrontDoor_AeoButton_Slide4     "Aeotec Front Door #4 Button"                              { channel="zwave:device:12c97eda:node18:switch_startstop4" }


/*ZWave Aeotec Wallmote Bedroom  */
Number BedRoom1_AeoButton_Scene       "Aeotec Bedroom 1 Button"                                  { channel="zwave:device:12c97eda:node20:scene_number" }
Number BedRoom1_AeoButton_Battery     "Aeotec Bedroom 1 Battery"          (gBatteries)           { channel="zwave:device:12c97eda:node20:battery-level" }
String BedRoom1_AeoButton_Slide1      "Aeotec Bedroom 1 #1 Button"                               { channel="zwave:device:12c97eda:node20:switch_startstop1" }
String BedRoom1_AeoButton_Slide2      "Aeotec Bedroom 1 #2 Button"                               { channel="zwave:device:12c97eda:node20:switch_startstop2" }
String BedRoom1_AeoButton_Slide3      "Aeotec Bedroom 1 #3 Button"                               { channel="zwave:device:12c97eda:node20:switch_startstop3" }
String BedRoom1_AeoButton_Slide4      "Aeotec Bedroom 1 #4 Button"                               { channel="zwave:device:12c97eda:node20:switch_startstop4" }

1 Like

How do you prevent the scenes from triggering again when OH is restarted?

I use basically the same rule structure as you, but when OH intializes the scene item state from NULL to the last value, the condition “Item Remote_Scene received update” is triggered.

If the last scene was “activate garage door relay” the door will open on a OH restart. This is a horrible catastrophe.

Should I reset the scene value manually to a safe value, say 99.0, in each rule? This seems like a very dirty hack.

Welcome! To prevent this, don’t execute the rule if the previous state was NULL. There are lots of examples in the forum.

Thanks! That is an excellent answer. I already read about previousState in the manual. But sadly “previousState” is not available in a “received update” rule. This variable can only be used in a “changed” rule.

I would use a “changed” rule, but then the rule would not be triggered if the same button was pressed twice in succession. So “changed” is not an option and “received update” does not give me the previous state as far as I know.

I don’t know what to do. Here is the rule:

rule "Garage Door Relay"
when
        Item Remote_Scene received update 4.0
then
        Relay_Garage_Door.sendCommand(ON)
end

There is a timer that switches the relay off again.

Are you using persistence to restore the Item’s state (restoreOnStartup)? That would be another option.

Yes, I added the mapdb in the Add-ons and set it in preferences as default. I don’t know if this was enough configuration.

Isn’t persistence causing the problem in the first place? The scene being NULL until a button is pressed would be perfectly fine. But instead currently the last scene is restored from NULL to 4.0 which triggers the rule.

I’m thinking about removing mapdb.

Edit: The settings

cat /etc/openhab2/persistence/mapdb.persist
Strategies {
}

Items {
   *: strategy = everyChange, restoreOnStartup
}

What do you see in your events.log at startup?