Generic rule for update HVAC

i would like to operate HVAC control from KNX with one control item in OH; this item (Number, with mapping, 1, 2, 3, 4) get after updating HVAC via OH or KNX (via switch in the room) value from 33, 34, 36, 40 (means comfort, standby, night, freeze);

channel command/address is like 5.010:“control address”+<“state address”

so i need a generic rule to change the HVAC control items from 33 to 1, 34 to 2, 36 to 3 and 40 to 4; the result is the correct state information in widgets with the HVAC control item;

the simple process/rule for one specific HVAC control item is not a problem, like …

  - id: "1"
      itemName: HEA_MDE_414
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      type: application/vnd.openhab.dsl.rule
      script: |-
        var Number new_state = 0
        val mde_com = 33.0
        val mde_stb = 34.0
        val mde_ngt = 36.0
        val mde_fre = 40.0

        new_state = HEA_MDE_414.state as Number

        switch (new_state)
          case (mde_com): { new_state = new_state - 32 }
          case (mde_stb): { new_state = new_state - 32 }
          case (mde_ngt): { new_state = new_state - 33 }
          case (mde_fre): { new_state = new_state - 36 }
        logInfo('text',"MDE_414     : " + HEA_MDE_414.state)
        logInfo('text',"new_state   : " + new_state)
    type: script.ScriptAction

but i have approx. 60 HVAC control items and will not write 60 rules with the same content (like switch/case statement);

have anybody an idea?

First of all, if all the rule is doing is translating from 33 to 1 and so on, why not use a Transform? I don’t know if the KNX binding supports transforms but there is a transform Profile and this looks like it can be a simple map. But if not maybe a JavaScript transform is needed (I don’t understand the switch statement).

I do note that this rule will run twice for every change. First when the Item changes to 0 (for example) and again when this rule updates the Item to 33. For this reason this is often why a Design Pattern: Proxy Item is usually used for cases like this.

If for some reason you cannot use a transformation, see Design Pattern: Associated Items for approaches to handle all the Items in the same rule.