MQTT state topic with a few stats

Hello,

I am using configuration files and defined below Thing/Channel of my AC via MQTT:

Thing mqtt:topic:mosquitto:AC1 "Master" (mqtt:broker:mosquitto) [] 
{
  Type string : Mode        "Mode"                  [stateTopic="master/climate/masterAC/mode/state"]
  Type switch : Power		"Power"					[stateTopic="master/climate/masterAC/mode/state"				, commandTopic="master/climate/masterAC/mode/command", on="cool", off="off"]
  Type number : TargetTemp  "Target Temperature"    [stateTopic="master/climate/masterAC/target_temperature/state"	, commandTopic="master/climate/masterAC/target_temperature/command"]
  Type number : CurrentTemp "Current Temperature"   [stateTopic="master/climate/masterAC/current_temperature/state"]
  Type string : FanMode     "Fan Mode"              [stateTopic="master/climate/masterAC/fan_mode/state"			, commandTopic="master/climate/masterAC/fan_mode/command"]
}

1. The MQTT Topic "basement/climate/madoka_-_basement/mode/state" (Mode channel) returns more than 2 values (off, cool, hot and fan). Is it possible to use it as a switch, and set the 'off' value to 'off' and the 'on' value to 'cool or hot or fan'?
2. How do I add icons to the channels?
3. How do I add Units Of Measurement to the channels?

Thank you
  1. I do not know at the moment, but I don’t think that it’s possible. I know you can use on/off and true/false
        Type contact : contact      "SNZB-04 Kontakt"                     [ stateTopic="zigbee2mqtt/snzb_04_03/contact", on="false", off="true" ]

But I think Type “String” is okay.

I have a similar Item (Window-Sensor) which shows “OPEN/CLOSED/TILTED”. For special purposes I use a rule to convert the states into another item

rule "HM Status Terrassentuer Esszimmer Umwandlung"
    when
//      Item Dummy_4 changed to ON or
      Item HmIP_SRH_0515_1STATE changed 
    then
      if ( HmIP_SRH_0515_1STATE.state == "OPEN" ) {
          HmIP_SRH_0515_1STATECONTACT.postUpdate(OPEN)
//          logInfo("homematic","Terrassentür offen  ")
          return ;
      }
      else if (HmIP_SRH_0515_1STATE.state == "CLOSED") {
          HmIP_SRH_0515_1STATECONTACT.postUpdate(CLOSED)
//          logInfo("homematic","Terrassentür geschlossen  ")
      }
      else if (HmIP_SRH_0515_1STATE.state == "TILTED") {
          HmIP_SRH_0515_1STATECONTACT.postUpdate(OPEN)
//          logInfo("homematic","Terrassentür gekippt  " )
      }
      else {
          logInfo("homematic","Terrassentür nix passiert {} ", HmIP_SRH_0515_1STATE )
      }
end

  1. Icons are not possible in .things-File (Channels) afaik.

  2. You can use UoM in Channels this way

  Thing mqtt:topic:danny:snzb0201 "Sensor SNZB-02"  (mqtt:broker:danny )   @ "zigbee2mqtt"
    {
    Channels:
        Type number  : voltage       "SNZB-02 Spannung"                    [ stateTopic="zigbee2mqtt/snzb_02_01/voltage", unit="mV" ]
        Type number  : battery       "SNZB-02 Batterie"                    [ stateTopic="zigbee2mqtt/snzb_02_01/battery", unit="%" ] 
        Type number  : humidity      "SNZB-02 Luftfeuchtigkeit"            [ stateTopic="zigbee2mqtt/snzb_02_01/humidity", unit="%" ] 
        Type number  : temperature   "SNZB-02 Temperatur"                  [ stateTopic="zigbee2mqtt/snzb_02_01/temperature", unit="°C" ]
        Type number  : linkquality   "SNZB-02 Empfangsstäreke LQI"         [ stateTopic="zigbee2mqtt/snzb_02_01", transformationPattern="JSONPATH:$.linkquality" ]

    }

…but you also can use it in the .itms-file like

Number                      Be2709w_03_LQI               "Birne E27 9 W 03 LQI  [%.0f]"                  <qualityofservice>      (gBe2709w_03,gRSSI)                   ["Frequency"]                               { channel="mqtt:topic:danny:e2709w03:linkquality", stateDescription=" " [pattern="%.0f LQI"] }         

or for Quantity-Types

Number:Temperature          snzb02p_01_temperature       "Aussensensor Sued Terrasse Temperatur"         <temperature>           (gsnzb02p_01)                        ["Temperature","Measurement"]               { channel="mqtt:topic:danny:snzb02p01:temperature", stateDescription="pattern" [pattern="%.1f %unit%"] }         

  1. Yes but you’ll have to use a stateTransformation, either a map transform or a Script transform. This is not possible using the on and off properties.
  2. See @fibu-freak’s answer
  3. See @fibu-freak’s answer

Thank you both.
I tried to use the script transform option but it didn’t work.

I used below thing configuration - “Mode2” channel uses stateTransformation:

Thing mqtt:topic:mosquitto:AC1 "Master" (mqtt:broker:mosquitto) [  ] 
{
  Type switch : Power   "Power" [stateTopic="master/climate/masterAC/mode/state", commandTopic="master/climate/masterAC/mode/command", on="cool", off="off"]
  Type string : Mode	"Mode"	[stateTopic="master/climate/masterAC/mode/state"]
  Type string : Mode2	"Mode2"	[stateTopic="master/climate/masterAC/mode/state", stateTransformation="JS:daikin_transform.js"]
}

and put the following “daikin_transform.js” file under the transform folder (I am not a programmer so I used ChatGPT):

(function(input) {
    // Define the mapping
    var mapping = {
        "off": "off",
        "cool": "on",
        "heat": "on",
        "heat_cool": "on",
        "fan_only": "on",
        "dry": "on"
    };

    // Return the mapped value, or "off" as the default if the input is not in the mapping
    return mapping[input] !== undefined ? mapping[input] : "off";
})(input)

The problem is that both channels “Mode” & “Mode2” return the same value “cool”, instead “cool” for “Mode” and “on” for “Mode2”.

What did I do wrong?

What there a change in the mode after you made the changes to the Channels? If the device doesn’t change there won’t be an event to run the transformation and the Item will remain “cool” until the mode changes to something else.

It was changed from cool to dry:

2024-11-14 17:32:40.765 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Daikin_BRC1_Master_OnOffStatus' changed from OFF to ON
2024-11-14 17:32:40.773 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Daikin_BRC1_Master_Mode2' changed from cool to dry
2024-11-14 17:32:40.774 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Daikin_BRC1_Master_Mode' changed from cool to dry

JavaScript Transformation service was installed

I found the problem. I used stateTransformation instead of transformationPattern