OH3 | Help with scene implementation

Hi.
In the topic linked below, I asked help/ ideas regarding light scenes or scenes in general.

I came to the conclusion that what I wanted was not easy to achieve with a design pattern or some other smart solution to keep repetition to a minimum.

I will explain what I have made so far and where I get stuck. Hopefully someone can give me just that insight so that I can continue.

Scenes:
My requirements were:
controllable via GUI, physical buttons and voice

I started operating lamps. but would also like to include the TV and tremostat in the future

I made a script for each scene

I start simple, one room with 5 scenes

Scripts:
scenes_livingroom_off
scenes_livingroom_work
scenes_livingroom_tv
scenes_livingroom_dinner
scenes_livingroom_relax

Each script has the same items, only the “.sendCommand(xxx)” is different.

Example script for one Scene :

// Items to control in this scene 
huiskamer_plafond_lamp_Switch.sendCommand(OFF)
huiskamer_eettafel_lamp_Switch.sendCommand(OFF)
Huiskamerkabinetlamplinks_power.sendCommand(ON)
Huiskamerkabinetlamprechts_power.sendCommand(ON)
huiskamer_staande_lamp_1_Switch.sendCommand(ON)
huiskamer_staande_lamp_2_Switch.sendCommand(OFF)
  
// Put all scene switches off except for the active one 
scenes_switch_huiskamer_off.sendCommand(OFF)
scenes_switch_huiskamer_work.sendCommand(OFF)
// scenes_switch_huiskamer_tv.sendCommand(OFF)
scenes_switch_huiskamer_dinner.sendCommand(OFF)
scenes_switch_huiskamer_relax.sendCommand(OFF)

I made virtual switches for each scene to activate it

Virtual Switches:

scenes_switch_huiskamer_off
scenes_switch_huiskamer_work
scenes_switch_huiskamer_tv
scenes_switch_huiskamer_dinner
scenes_switch_huiskamer_relax

In the scripts that are activated by these switches I have included that all other switches (not active scene) must be turned off.

Now I want to make rules that run the scene script when the switch goes from OFF to ON

scenes_switch_rule_huiskamer_off
scenes_switch_rule_huiskamer_work
scenes_switch_rule_huiskamer_tv
scenes_switch_rule_huiskamer_dinner
scenes_switch_rule_huiskamer_relax

It should be easy now to control switches with GUI, physical buttons and voice :slight_smile: !

If I create a new Rule
And go to the Then part of the rule > Add Action > choose Run Script, then I do not have the option to select an existing script, I can only create a new script.

I do see two lines with: “execute a given script” and “Allows the execution of a user-defined script.

But I don’t know how to use this function.

So that is question 1

Question 2
Does it make sense to put the switches in a group to see which one is ON (so that I can make a switch widget with 5 scene buttons and the active scene lights up)

Maybe I make it all too complicated, and has openHAB built-in functions that can make some parts more intelligent/easier.

All comments are welcome.

Instead of multiple switches you can use a string item which is then also able to be controlled by Alexa. Call the item ‘the lounge scene’ for instance. Then you can say Alexa, set ‘the lounge scene’ to …

Then a rule so when it’s changed it does what you want.

You can also remember previous states in the rule so if you say set ‘the lounge scene’ to ‘off’ then it restores previous states

Less items to manage in Alexa and openhab then. Plus you can easily add new scenes and change existing ones

You can set the label nicely to so it makes a nice voice command.
I have a few…
‘We are’… going out, going to bed etc
‘It’s time for’…

Hi Dave
Thanks for your reaction.
I’m a google assistant (GA) user because it’s to date the only one in my native language (dutch).
I was under the impression that this (scenes with parameters) was not yet possible with GA.

Your solution sounds way easier than mine.

So i have to brush up my google skills and find out if and how I can do this with GA

And then find out how to do the “remember previous states” logic in DSL script

I went with the switch approach.

I made a switch for each of the 5 scenes in the living room
Scene: off, work, relax, dinner and TV

When one of the 5 switches goes from OFF to ON, the corresponding Script will be started.

Now the next bump.

I have an Aqara Opple 6 way switch.
if I press button 1 I get “button_1_single” as answer and for button 2 “button_2_single” etc.

Now I can make a separate rule for each button. So 6 rules to turn on 6 switches.

In openhab 2.x I would use something like:

rule "scenes_huiskamer"
when
    Item Aqara_Opple_switch changed
then
    var actionName = receivedEvent.getEvent()
    switch(actionName) {
        case "0": {   Turn on switch 1   }
        case "1": {   Turn on switch 2   }
        case "2": {     ....   }
        case "3": {     ....   }
        case "4": {     ....   }
    }
end

As I understand it now I have to cut the DSL rule in 2 pieces in OH3 GUI.

1) trigger part, when Item scenes_livingroom changed (by creating a rule)
2) THEN part {script block} (by creating a script)

But does the script (2) still know which button has been triggered in the rule (1) ???

How does that work??