OH3 Dimmer item to MQTT channel

I’m running OH3 3.2.0.M4 on a RPi 3. I’ve come from OH2 (and 1), and am trying to work out how to do most of my implementation in the GUI, by starting with a fresh install and creating my items afresh.

I have a digital clock, which takes an MQTT channel as a brightness parameter, between 0 (off) and 15 (max). I have created a brightness dimmer item and linked it to the channel. In the channel’s advanced options I’ve set the absolute min / max to 0/15.

When I change the dimmer it sends the MQTT command, but it had translated the values to 1/100th of their supposed values. For example I set the dimmer to 1 and the MQTT message sent is 0.1, set to 15 the messages is 0.15 (with some trailing 0’s). (Channel code below)

I can obviously get round this by setting the channel max/min to 0/1500, which works, but isn’t elegant

But I’m obviously mis-understanding something about how the dimmer / channel is meant to work, or what I should set to translate the value to multiply it by 100.

Any help gratefully received.

Thanks,
Matt


UID: mqtt:topic:ac0a884346:72045792fa
label: Lounge Clock
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:ac0a884346
location: Lounge
channels:
  - id: Message
    channelTypeUID: mqtt:string
    label: Message
    description: null
    configuration:
      commandTopic: nodeNTP_2/inmsg
  - id: Brightness
    channelTypeUID: mqtt:number
    label: Brightness
    description: null
    configuration:
      postCommand: true
      min: 0
      formatBeforePublish: "%s"
      qos: 0
      max: 15
      commandTopic: nodeNTP_2/bright
      step: 1

The dimmer type channel used to get a misleading “percent type” description in the GUI, don’t know if that’s still true.

Dimmer type Items work on a percent type state. 50% = 0.5
Likely a side effect of linking Dimmer Item to number channel.

Thanks. So what is the workaround? Should I convert to a number channel, if so how do I set the brightness? Can I add code (or a rule) to multiply the dimmer value by 100?

It’s already a number type channel, apparently linked to a Dimmer type Item.
Why not try a dimmer type channel, so you have matching elements?

Ah, thanks, I’ve changed the MQTT channel to a dimmer channel and now I have 0-100% on the slider.

It does seem a bit odd that I have to choose either an arbitrary 0-100 (that translates 10 0-15), or a 0-15 slider that the number channel provides which translates to 0.00 to 0.15). I wonder if I should instead be using a map to convert 0.01 to 1, 0.02 to 2 … 0.15 to 15. That way my slider would match the output?

Th idea of a Dimmer Item is that it is an idealised model. All openHAB Dimmers look alike, have states from 0% to 100%, all appear and act the same in the user UI.

It matters not if you link that Item to a zwave device supporting percent, a KNX dimmer supporting 0-255, an audio volume supporting 0-10. Converting from the standard Dimmer to and from the device specifics is the business of the binding. When a protocolis well-defined like KNX that’s often built-in. Where its completely arbitrary like MQTT, it’s up to you the user to supply transformations to do your custom matching.

So … if you don’t like that 0-100% behaviour of the Dimmer type Item, then don’t use a Dimmer type Item. A Number type Item linked to a number type MQTT channel supports any range that you want.

Your troubles stem from mismatching a Dimmer Item and number channel.

The dimmer makes complete sense. However I can’t figure out how to create an item, linked to my mqtt channel that I can set the number value to. When I create an item from the channel, there doesn’t seem to be a type that allow me to enter a number either from a list, or text entry etc. If I create a number type item, how do I send it a value - I’m obviously missing something simple here…

a Number type Item is a Number type Item, again they all look alike.
Like all Items, you can send it commands under UI control or from rules.

You seem to be having a UI presentation problem?
any Item type can be use with any UI widget type (though not all combinations make sense). The point is that an Item type is not tied to any UI presentation, you choose the Item type that best represents what you want, then choose the screen widget. Not the other way round,

each Item type has a default widget. If you want your Item to use a different widget, choose it in metadata

But going back to your original post -

That’s an obvious candidate to use a Dimmer type Item.

and then link it to MQTT dimmer type channel, and scale the 0-100% to 0-15 using the min/max parameters.
I think your original error was just about channel type (but the postCommand is not wanted either).

2 Likes

Ah, that’s brilliant - thank you very much for your help. I was missing the idea of the metadata (default standalone / default list item - widgets). I can now have either % dimmer, or 1-15 slider; works perfectly.temp