Sending a Number-item with MQTT

Running openHAB 3.2 stable (not yet 3.3) on a RaspberryPi.

What I got:

  1. a number-item for the state of my washing machine [0,1,2]
  2. a running, functioning MQTT-broker

What I don’t get:
the mqtt sending the value of the item onChanges to the topic

my Thing:

  - id: Betriebsart
    channelTypeUID: mqtt:number
    label: Betriebsart
    description: Betriebsart Waschmaschine
    configuration:
      qos: 2
      commandTopic: pl12/waschmaschine/betriebsart
      retained: true

item - number item is “follow” linked to the channel.


if the item value changes, nothing happens. I know, I miss something trivial, but I don’t find it.

Alright, follow profile often leads to user headaches, but works as designed.
What it’s supposed to do is listen for Item state update (not just change) and forward to the linked channel as though it were a command.
Real commands to the Item are ignored by this follow channel (though of course they might eventually cause a state update).

So you would need to set up the MQTT channel to “do something” with commands, by giving commandTopic - which you’ve done, tick.
You could also add formatting stuff, but not needed yet for testing.

Does it work? Find out without the complication of follow. Create a temporary test Number Item and link it to your MQTT channel as well in the ordinary way.
Send your test Item a number command, via REST API, rule or GUI. Does it do what you expect?
Only move on the real Item with follow once this works.

Note that MQTT binding can be reluctant to update with edits - if you have been editing channels and links, and now have something you believe should work but doesn’t, then try a reboot.

oh… That’s … surprising! :wink:
What surprises me more, I do have another item (switch), which works with the exact same configuration (follow, same broker, …) and sends ON/OFF to the respected topic. I remember faintly, that perhaps I missed something with the number vs string issue and MQTT…

I’ll try a reboot later, thanks.

After a reboot I witness the same behaviour:

  • two items with identical configuration
  • one is configured using and items-file, one added via UI
  • MQTT-Thing and Channels are added via UI

file-item:

Number StatusWaschmaschine "Betriebszustand der Waschmaschine"                  <washingmachine>                            { stateDescription=" "[ pattern="%d", options="3.0=fertig,2.0=wäscht,1.0=Standby,0.0=Aus,3=fertig,2=wäscht,1=Standby,0=Aus,NULL=keine Daten,-=keine Daten" ] }

UI-item:

value: " "
config:
  options: 3.0=fertig,2.0=wäscht,1.0=Standby,0.0=Aus,3=fertig,2=wäscht,1=Standby,0=Aus,NULL=keine Daten,-=keine Daten
  pattern: "%d"

MQTT-Thing/Channels configuration:

label: MQTT Waschmaschine
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: Offline
  payloadAvailable: On
bridgeUID: mqtt:broker:synology
channels:
  - id: Betriebsart
    channelTypeUID: mqtt:number
    label: Betriebsart
    description: Betriebsart Waschmaschine
    configuration:
      commandTopic: pl12/waschmaschine/betriebsart
      postCommand: true
      retained: true
      qos: 2
  - id: TestStatusWaMa
    channelTypeUID: mqtt:number
    label: Test Status WaMa
    description: ""
    configuration:
      commandTopic: pl12/waschmaschine/betriebsart
      postCommand: true
      retained: true
      qos: 2

If I link the “TestNewItem” item to the “TestStatusWaMa”-channel via “follow”, I get the MQTT-state changes:

2022-07-22 15:11:11.870 [DEBUG] [qtt.generic.AbstractMQTTThingHandler] - Successfully published value 1 to topic pl12/waschmaschine/betriebsart

2022-07-22 15:11:11.831 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TestNewItem' received command 1
2022-07-22 15:11:11.844 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TestNewItem' predicted to become 1
2022-07-22 15:11:11.855 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestNewItem' changed from 2 to 1

If I link the “StatusWaschmaschine” item to the “Betriebsart”-channel via “follow”, I don’t get anything.

2022-07-22 15:10:30.316 [TRACE] [.MqttChannelStateDescriptionProvider] - Providing state description for channel mqtt:topic:synology:Spuelmaschine:Power

2022-07-22 15:10:31.993 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'StatusWaschmaschine' received command 1
2022-07-22 15:10:31.997 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'StatusWaschmaschine' predicted to become 1
2022-07-22 15:10:32.001 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'StatusWaschmaschine' changed from 0 to 1

What do I miss?

I don’t know why you are using follow profile, when you are sending commands to Items.
Simplify.
Make a plain ordinary Item-channel link, no profile.
Send the Item a command.

This MQTT channel parameter is completely irrelevant in a channel with no stateTopic - it’s about incoming MQTT messages.
It shouldn’t be doing any harm, though.

I expect this is all going to boil down to some subtle difference in theway you havedefined state options on the Items.
Try the no-follow-profile test, where the options are irrelevant after the Item is commanded.

The follow profile acts on Item state, so we might expect state options to become relevant there.

because I just want to “follow”, not update the item. Removed the “follow” to “Standard” as I didn’t define a stateTopic anymore.

jepp, was an old configuration with another item. removed it.

still the same. Now I have just a standard link between channel and item. And as far as I can see, both items and channel configurations are identical - except for name and source of configuration.

even if I dig deeper and open the JSON-DB configuration is also identical.

JSON-DB

org.openhab.core.thing.link.ItemChannelLink.json

...
  "TestNewItem -\u003e mqtt:topic:synology:Waschmaschine:TestStatusWaMa": {
    "class": "org.openhab.core.thing.link.ItemChannelLink",
    "value": {
      "channelUID": {
        "segments": [
          "mqtt",
          "topic",
          "synology",
          "Waschmaschine",
          "TestStatusWaMa"
        ],
        "uid": "mqtt:topic:synology:Waschmaschine:TestStatusWaMa"
      },
      "configuration": {
        "properties": {
          "profile": "system:default"
        }
      },
      "itemName": "TestNewItem"
    }
  },
  "StatusWaschmaschine -\u003e mqtt:topic:synology:Waschmaschine:Betriebsart": {
    "class": "org.openhab.core.thing.link.ItemChannelLink",
    "value": {
      "channelUID": {
        "segments": [
          "mqtt",
          "topic",
          "synology",
          "Waschmaschine",
          "Betriebsart"
        ],
        "uid": "mqtt:topic:synology:Waschmaschine:Betriebsart"
      },
      "configuration": {
        "properties": {
          "profile": "system:default"
        }
      },
      "itemName": "StatusWaschmaschine"
    }
  },

org.openhab.core.items.Metadata.json

  "stateDescription:TestNewItem": {
    "class": "org.openhab.core.items.Metadata",
    "value": {
      "key": {
        "segments": [
          "stateDescription",
          "TestNewItem"
        ],
        "uid": "stateDescription:TestNewItem"
      },
      "value": " ",
      "configuration": {
        "options": "3.0\u003dfertig,2.0\u003dwäscht,1.0\u003dStandby,0.0\u003dAus,3\u003dfertig,2\u003dwäscht,1\u003dStandby,0\u003dAus,NULL\u003dkeine Daten,-\u003dkeine Daten",
        "pattern": "%d"
      }
    }
  },
  "stateDescription:StatusWaschmaschine": {
    "class": "org.openhab.core.items.Metadata",
    "value": {
      "key": {
        "segments": [
          "stateDescription",
          "StatusWaschmaschine"
        ],
        "uid": "stateDescription:StatusWaschmaschine"
      },
      "value": " ",
      "configuration": {
        "options": "3\u003dfertig,2\u003dwäscht,1\u003dStandby,0\u003dAus,NULL\u003dkeine Daten,-\u003dkeine Daten",
        "pattern": "%d"
      }
    }
  },

it’s really strange - or I don’t get it…
Is it the mix of “textual item-definition” and “UI driven metadata and Thing”?