KNX and HVAC Modes

Hello

I’ve setup my KNX HVAC modes using one channel and two items to manage my KNX HVAC modes. The item I use to manage it from the OpenHab Interface it’s configured as String and I have another item configured as Number to send the commands.

The Item configured as String has a a Default List Item Widget on Metadata and a stateDescription with the values in Options as

2=Standby
1=Comfort
4=Anti Congelacion
3=Noche
0=Automatico

This work as expected, as soon as I change values from the KNX the Item updates the value it shows, but if I try to change the value from the Item it sends the number as expected but the KNX value doesn’t change.

If I use the item with the number definition and input manually the value it changes as expected. To overcome this I’ve created a rule that monitors the string item and when it changes it sends a number to the number item.

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Controlador_Estudio_Modo_Estudio
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: |-
        switch Controlador_Estudio_Modo_Estudio {
          case Controlador_Estudio_Modo_Estudio.state.toString == '0' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(0)
            logInfo("HVAC", "Seleccionado Automatico")
            }
          case Controlador_Estudio_Modo_Estudio.state.toString == '1' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(1)
            logInfo("HVAC", "Seleccionado Comfort")
            }
          case Controlador_Estudio_Modo_Estudio.state.toString == '2' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(2)
            logInfo("HVAC", "Seleccionado Standby")
            }
          case Controlador_Estudio_Modo_Estudio.state.toString == '3' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(3)
            logInfo("HVAC", "Seleccionado Noche")
            }
          case Controlador_Estudio_Modo_Estudio.state.toString == '4' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(4)
            logInfo("HVAC", "Anticongelacion")            }
        }
    type: script.ScriptAction

This works as expected, but for me it doesn’t seem a clean solution to have two items associated to the same function to obtain the expected result. Any advice on this? Maybe I’m overengeering it?

Regarfs

I think you are going through a bunch of unnecessary translations.

Ideally you would set this up as follows:

  • Just one Number Item linked to the KNX Channel
  • Add the state descriptions, options, and default list Item widget metadata to the Number Item. I think with the options you don’t need any further mapping in the state description pattern. But it it’s not showing the text from the options, a Map transform may be needed.
  • You don’t need the rule.

If something isn’t working, post your configs (code tab) and we can work out where it’s going wrong.

There are a few other things to mention with your rule.

  • This rule is basically just reproducing the Map transformation. Map - Transformation Services | openHAB You don’t need a rule to do this. Transforms like this can be applied in the State Description Pattern, at the Link between the Channel and Item through the transform Profile, or at the Channel for many bindings.

  • You can always postUpdate or sendCommand a String representation of the state/command. So even if a rule were required here the whole rule could become:

    Controlador_Estudio_Modo_Estudio_N.sendCommand(newState.toString)
    logInfo("HVAC", "Seleccionado " + newState)
    

Well as I suspected over engeering solution, yours work as expected with so less fuss.

when using the switch statement, a simpler way would be like this:

type: application/vnd.openhab.dsl.rule
      script: |-
        switch(Controlador_Estudio_Modo_Estudio.state.toString) {
          case '0' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(0)
            logInfo("HVAC", "Seleccionado Automatico")
            }
          case '1' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(1)
            logInfo("HVAC", "Seleccionado Comfort")
            }
          case '2' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(2)
            logInfo("HVAC", "Seleccionado Standby")
            }
          case '3' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(3)
            logInfo("HVAC", "Seleccionado Noche")
            }
          case '4' : {
            Controlador_Estudio_Modo_Estudio_N.sendCommand(4)
            logInfo("HVAC", "Anticongelacion")            }
        }
    type: script.ScriptAction
1 Like

That was my first iteration but forgot to add the toString