State Description is not honored

  • Platform information:
    • Hardware: RPI 4, 4 GB
    • OS: openhabian
    • Java Runtime Environment: 17.0.7
    • openHAB version: 4.0.0.M4

I have defined a state description for one of my items, but for some reason it is not applied. I simply tell it to have no decimals, like this:
image

And I get loads of them anyway:


image

Some additional info:

  • The item is of type “dimmer”
  • Force update is set to “false”

Any idea why this is happening?

Thanks in advance!

The state description is not going to be shown on the Settings → Items page. The first looks like it might come from there. It’s hard to tell.

Can you show the Item definition? Go to Settings → Items → This Item → Pencil icon → Code tab and paste that here. Use code fences:

```
code goes here
```

A Dimmer Item already should be limited to integers between 0 and 100. A Dimmer Item can’t have decimal places. It would be odd to use a Dimmer to represent a temperature in the first place.

You’re right, so the first image doesn’t tell much I guess. However, with the widget I would expect the state description to be used when simply doing itemName.state (that’s my experience from other widgets at least). Here is the entire widget code:

uid: tapwater_heat_gauge
tags: []
props:
  parameters:
    - context: item
      description: Max temp
      label: Max temp
      name: maxTemp
      required: true
      type: TEXT
  parameterGroups: []
timestamp: Nov 26, 2023, 9:07:45 PM
component: f7-card
config: {}
slots:
  content:
    - component: oh-chart
      slots:
        series:
          - component: oh-data-series
            config:
              axisLine:
                lineStyle:
                  color:
                    - - =0.2*100/85
                      - "#1e90ff"
                    - - =0.35*100/85
                      - "#909090"
                    - - =0.4*100/85
                      - "#000000"
                    - - =0.5*100/85
                      - "#909090"
                    - - =0.7*100/85
                      - lightgreen
                    - - =1*100/85
                      - red
              data:
                - name: Tap Water Temp
                  value: =items['Tap_Water_Temp_Control_Tap_Water_Temp_Control'].state
              endAngle: 0
              max: 85
              min: 0
              splitNumber: =85/5
              startAngle: 270
              type: gauge
        tooltip:
          - component: oh-chart-tooltip
            config:
              show: true

Sure, here it is:

label: Tap Water Temp Control
type: Dimmer
category: temperature
groupNames:
  - Tap_Water_Temp_Control
groupType: None
function: null
tags:
  - Control
  - Temperature
  - Point

Yes, I agree it’s odd. If fact it’s just a workaround for me to be able to map 0-100 values from my sensor to 0-85 degrees. I’m doing this by creating an MQTT dimmer channel and setting absolute min and max to 0 and 118 (since the max refers to the sensor max). I tried applying the gain profile which did not work.

Perhaps you have a better suggestion on what I should do?

Nope. itemName.state will always show the raw state of the item. If you wish to show the state formatted by the state description, then you need to use itemName.displayState.

Use a Number channel which also supports absolute min and max properties. Or you can just leave that out. It’s a sensor, OH doesn’t need to enforce the min and max unless the sensor is liable to throw out bogus values.

Ah, that did it! I didn’t realize that the raw state can still include unit, so I made the wrong assumption. Thanks!

Well, for the mqtt dimmer channel min max it works differently it seems. It actually transforms the data so that the defined max and min maps to 0 and 100. So I’m using it to transform the data rather than filtering out outliers.

That’s what I don’t understand though. It’s a sensor. It’s a temperature sensor. Don’t you want the value of the Item to actually reflect the actual temperature? By using a Dimmer and transforming it, the Item’s state will be around 20% off from the actual temperature.

Yes, I should not have called it a sensor, because it’s actually a servo controller that turns the knob of a thermostat. The servo controller (using tasmota for this) accepts 0-100, and that corresponds to setting the temperature to 0-85.

What would be the preferred method here? Using a gain profile was my first bet, but I never got it to work with the mqtt channel (seems like non-integer values are not sent at all).

OK, that’s very different.

What do you want to Item to represent? Assuming it’s a straight forward mapping between the knob position and temperature and you want to use temperature you can use two transformations:

Incoming (assuming JS):

(function(input){
  var value = parseInt(input);
  var temperature = Math.round(85 * (value/100)); // convert the incoming value to a percent of 85 and round
  // will return an integer between 0 and 85
  return temperature; // you could add units if you wanted to if you use a Number:Temperature
})(input)

Outgoing:

(function(input){
  var value = parseInt(input); // will ignore units if there are any
  var percent = Math.round((value / 85) *100); // convert the incoming temp to a percent of 85 and round
  // will return an integer between 0 and 100
  return percent; 
})(input)

You could also keep the Item state as a “percent” (between 0 and 100) and do the math to convert it to a temperature in the widget.

value =Math.round(85 * (Math.parseFloat(items['Tap_Water_Temp_Control_Tap_Water_Temp_Control'].state) / 100))

Double check the parens there, I might be one off.

Though now that I think of it that probably won’t work because it only converts one way and not the other. Better to use the transformations

1 Like

Tried it, and this works! Thanks! A shame I cannot mark two posts as the solution :laughing: