Best practice for small coding (Design Pattern)

I’ve read and test in the last time so many ideas about a small and readably Szene manger. Actually I’m not happy and it exists a better Approach.

In an other prorgamming language I would create a class with the logic and the needed properties.

I’ve some items in the item file, some variable and the rule in the rules file.

the items file Looks like this

// ------------------------------------------------------------------------------------------------------------------------------------
// S22: Wohnen & Essen
// ------------------------------------------------------------------------------------------------------------------------------------
Switch  S22_Automatic                 "Wohnen & Essen"                                                                        (Scene_Automatic)
Number              S22_Number                                    "Wohnen & Essen [%.0f]"                                                           (Scene_Number)
Number              S22_Timer                                          "Wohnen & Essen [%.0f]"                                                           (Scene_Timer)

// ------------------------------------------------------------------------------------------------------------------------------------
// S23: Küche
// ------------------------------------------------------------------------------------------------------------------------------------
Switch  S23_Automatic                 "Korridor EG"                                                                                   (Scene_Automatic)
Number              S23_Number                                    "Korridor EG [%.0f]"                                                      (Scene_Number)
Number              S23_Timer                                          "Korridor EG [%.0f]"                                                      (Scene_Timer)


Switch  Motion_S21                                      "Bad EG"                                                                            <motion>                (scene_motions,Motions_InnenEG)                       { channel="loxone:miniserver:EEE0009400FE:0D743B76-01CB-7855-FFFFEEE000B8003B" }
Switch  Motion_S22_Essen        "Essen"                                                                               <motion>                (scene_motions,Motions_Wohnzimmer)             { channel="loxone:miniserver:EEE0009400FE:094CCC90-0340-8DAE-FFFFEEE000B8003B" }
Switch  Motion_S22_Wohnen  "Wohnen"                                                                         <motion>                (scene_motions,Motions_Wohnzimmer)             { channel="loxone:miniserver:EEE0009400FE:094CCC90-0340-8DAB-FFFFEEE000B8003B" }
Switch  Motion_S23_Eingang    "Korridor EG Eingang"                   <motion>           (scene_motions,Motions_KorridorEG)                { channel="loxone:miniserver:EEE0009400FE:094CCC90-0341-8DC3-FFFFEEE000B8003B" }

and so on

the rule files has a first part with the definitions and afterward the rules …

// ------------------------------------------------------------------------------------------------------------------------------------
// S31: Korridor UG
// ------------------------------------------------------------------------------------------------------------------------------------
val Number        S31_Delay1                                        = 3                                                         // Nachlauf in Munuten bei Bewegung
val Number        S31_Delay2                                        = 15                                       // Wenn Scene gewählt
val Boolean        S31_Ignore                                        = false                                  // Mückennetz vorhanden, dann berücksichtigen
var Number       S31_NumberSave                                                                                          // Scene gespeicher, wenn Fenster geöffnet wird
var Number       S31_NumberLast                                                                                           // Letzte gesetzte Szene
var Boolean S31_Enabled                                                                                                           // wenn true, so darf die Szene aktiviert werden

// ------------------------------------------------------------------------------------------------------------------------------------
// S32: Gäste
// ------------------------------------------------------------------------------------------------------------------------------------


// ------------------------------------------------------------------------------------------------------------------------------------
// scene motions received update
// ------------------------------------------------------------------------------------------------------------------------------------
rule "scene motions received update"
when
                Item scene_motions received update
then
    if (triggeringItem.state == NULL) return;                                                                                                                         // we don't care about NULL
    // if (previousState == NULL) return;                                                                                                                                // we don't run on changes from the NULL state
                logInfo ("Bewegung","Item = {}", Motions.allMembers.sortBy[lastUpdate].last.name + ": " + Motions.allMembers.sortBy[lastUpdate].last.label )
                
                val _room = Motions.allMembers.sortBy[lastUpdate].last.name.split("_").get(1)              
                val _automatic = Scene_Automatic.allMembers.filter(s|s.name == _room+"_Automatic").head  
                val _timer = Scene_Timer.allMembers.filter(s|s.name == _room+"_Timer").head  
                //val _delay1 = Scene_Delay1.allMembers.filter(s|s.name == _room+"_Delay1").head  
    
                if (_automatic!==null &&_timer!==null) {                                                            //&& _delay1!=NULL
                               if (_automatic.state==ON) {
                               
                                               logInfo ("Test","Automatik ein = {}", Motions.allMembers.sortBy[lastUpdate].last.name + ": " + Motions.allMembers.sortBy[lastUpdate].last.label )
......
                               }
                }
end

What is best Praxis? How can I handle the variable in the same way, because they arn’t in any Groups. Make it sence to work wotjh hashmaps?

many thanks for any good idea.

Your posting is confusing. It’s totally unclear what your question is. Would you please explain that better.
I don’t want to have to understand your code first just in order to understand your question, and likely noone else wants to.

OH has Xtext DSL builtin but access to anything Java so if you are annoyed with Xtext capabilities do it inside Java classes or use the JSR223 engine (to do it in Python or whatever).
If you stay within Xtext rules, there is no general ‘Praxis’ (best practice). You can have rules trigger action for each scene switch or one rule for all scene switches in one room or a set of rooms. You can take direct action in these rules or you can set a Number item to a scene number only instead e.g. by using sceneitem.sendCommand()) and add a rule to take action based on changes to sceneitem. Or anything else. There is no general best practice.

Like Markus said, there really is not a best practice. There are approaches that work better in some circumstances than others. This is why the Design Patterns exist. Design Pattern: What is a Design Pattern and How Do I Use Them

The link at the bottom is to all of the published design patterns.

For something like this Assocaited Items and Encoding Values in Items might be useful.