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 !
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.