OH3: Generic MQTT thing - Channel Item Dimmer

Hello
a dimmer Item with min / max value 0 / 100 publishes values from 0 to 100…thats ok.
If min max values are different from 0 / 100 it looks like this:

Min - Max      Publish

0 - 90         0 - 81
0 - 80         0 - 64
0 - 20         0 - 4
0 - 10         0 - 1
10 - 100       19 - 100
20 - 100       36 - 100
30 - 100       51 - 100
50 - 100       75 - 100
80 - 100       96 - 100
90 - 100       99 - 100
  - id: MQTT_prozent
    channelTypeUID: mqtt:dimmer
    label: MQTT_prozent
    description: ""
    configuration:
      commandTopic: go-eCharger/000000/cmd/req
      min: 10
      formatBeforePublish: "%s"
      max: 100

I this a bug a feature or do i undestand something wrong ?

The Min - Max controls how the 0-100 that is stored by the Dimmer Item are translated to the range you defined. So let’s take your 0-10 example. That means I would expect the Dimmer’s values between 0-9 to be 0, values between 10-19 to be 1 and so on.

So yes, if you set the min and max to be 0-10, and you only changed the Dimmer Item to be a value between 0 and 10 you would only see 0 until you get to 10 where it becomes 1.

The Dimmer Item will always store a value between 0 and 100. What happens is that 0-100 gets translated to a number between the defined min and max before being sent. You are not constraining the values that the Dimmer Item can hold. You are defining a formula that is use to transform the Dimmer’s value to be within the range expected by the device.

publish = (((Max - Min) / 100) * DimmerItemValue) + Min

Don’t think you want that, it just might be interfering with scaling.

“…formatBeforePublish: "%s"....Don’t think you want that, it just might be interfering with scaling.”

Thats not a problem, the device also needs a prefix which works.
The device undestand the command but how to send the right values (eg 6, 7,8…14, 15,16) thats my problem.

  - id: MQTT_prozent
    channelTypeUID: mqtt:dimmer
    label: MQTT_prozent
    description: ""
    configuration:
      commandTopic: go-eCharger/021683/cmd/req
      min: 6
      formatBeforePublish: amp=%.0f
      max: 16

Oh right, secret settings. That makes it hard to help.

I think you might need a custom transform to do both scaling and prefix. It’s not at all clear in what order the binding will apply what you have now.

This is starting to look like an XY Problem. What are you controlling that only accepts values between 6 and 16?

As I tried to explain, those values will not change how the Dimmer Item behaves. It will always store a value between 0 and 100. Setting the min and max on the channel is not going to restrict the Item to only be between 6 and 16. What it will do is do the math (see above) to convert from those 100 values to a value between 6 and 16.

You probably want a String Item or a Number Item and using a selection on the sitemap or something like that.

1 Like