Doubled Unit Output

Hey guys.

Currently I’m using OH4.2.0.M3 and facing with an issue. Perhaps is was also existing in OH3.4 but never recognized.

I’m using some Aqara sensors and others as well. Connected via Z2M. In many cases I see a doubled display of UoM.

image

What I have done in the most cases was to add a state description.

%.2f %unit%

But I’m sure this can’t be the solution at all. This means that I need to “fix” all items. Is there perhaps an other configuration issue at my end?

Thx, markus

What’s the definition of the widget?

This is no widget. This is only the item configuration in OH.
In the item “list” it looks correct…

… but within the item not…

And yes ofc, if I add the item to pages to some oh-labled cells I also have the doubled unit if I don’t use the state description.

That’s a strange behavior… never seen this before… :person_shrugging:

Me too. That’s why I’m asking here… :slight_smile:

First try it out in the latest snapshot. If it still shows the unit twice file an issue on the openhab-webui repo.

You don’t show it but one can assume you’ve not defined a “Default stand alone widget” metadata on this Item. If you have, that’s what is being shown and that’s what we need to see to ensure there isn’t a config problem there.

Tagging @Mherwege in case you know about this, since you’ve worked with this a lot.

I hadn’t seen it before. But the good thing is, I have been able to reproduce it. I need to further analyse to see what is going on.
I have seen the behaviour for an item linked to an channel on the MQTT binding. I can’t reproduce it for an item not linked to a channel, or linked to a channel of another binding.

2 Likes

It looks like the fundamental issue is with the MQTT binding. You configure a channel to be a Number channel, but no dimension is set on this. A unit is set, and the return value is a string representation. This is then mapped to a Number with Dimension item.
This is an example where the MQTT binding tries to do things with units but is unaware about dimensions. If it is a pure Number channel, it should not pass on any unit at all (that is up to the linked channel with Dimension to add a default).

I suggest to create an issue for this. This may take some time to resolve. In the mean time, use the workaround by setting a pattern.

@lolodomo Do you see something I overlook here? Maybe also in the light of Set a default presentation pattern for String/Number/Datetime items by lolodomo · Pull Request #4175 · openhab/openhab-core · GitHub.

The MQTT binding for a Number channel does not provide a state description. The values do have a unit. An Number:Dimension item is linked. I would expect the default pattern to be %.0f or %.0f %unit%. But the pattern used seems to be %s unit with the unit hardcoded in the state description behind it.
See an example REST response of a local test on my side:

{
  "link": "http://openhabian.local:8080/rest/items/PVEtotalGS2",
  "state": "54462.75 kWh",
  "stateDescription": {
    "step": 1,
    "pattern": "%s kWh",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "kWh",
  "metadata": {
    "unit": {
      "value": "kWh"
    },
    "semantics": {
      "value": "Point_Measurement",
      "config": {
        "relatesTo": "Property_Energy",
        "isPointOf": "Solar_GS2"
      }
    }
  },
  "editable": true,
  "type": "Number:Energy",
  "name": "PVEtotalGS2",
  "label": "PV Productie Totaal GS2",
  "category": "energy",
  "tags": [
    "Measurement",
    "Energy"
  ],
  "groupNames": [
    "Solar_GS2",
    "PVEtotal"
  ]
}

I believe the problem is the state pattern that was set. Why using %s with a unit and not %f ?

1 Like

I really doubt this state pattern is built by the core framework. It is either wrongly provided by user or by the MQTT binding ?

No risk that the default state pattern can be built with such a pattern.

@Mherwege Is there anything I can do? You mentioned to create an issue? I can do this if needed but I guess I can only provide a few information based on my first post.

I just checked the MQTT channel. I defined there also the UoM … Since OH3.x I guess. I didn’t changed this after the migration to OH4.x

Can this be the reason?

I created a PR for this: [MQTT] fix state description by mherwege · Pull Request #16866 · openhab/openhab-addons · GitHub

3 Likes

And the PR is merged, thank you @Mherwege

1 Like

Thx to all. I just updated to 4.2.0.M4 … I checked some of the items that had this issue before.

It seems that all my (special) state descriptions has been gone. Which is fine. No need to change them all back.

Many thanks for debugging and code fixing!!

Hello everyone,

today I migrated to version 4.2.1 and everything looks good, except for some duplicate unit characters in sitemap:

I read the thread and matching pr and I think I understood it, but it only refers to mqtt. But my screenshot is from the km200 binding.

This is what the item definitions look like:

Number:Dimensionless         budPumpModulation               "budPumpModulation [%s %%]"              (gHeizung)                                                                                                           {unit="%", channel="km200:heatingCircuit:719200030:hc1:pumpModulation"}
Number:Power                 budactualPower                  "budactualPower [%s kW]"                 (gHeizung)                                                                                                           {unit="kW", channel="km200:heatSource:719200030:heatSources:actualPower"}
Number:Power                 budactualPower1                 "budactualPower1 [%s kW]"                (gHeizung)                                                                                                           {unit="kW", channel="km200:heatSource:719200030:heatSources:hs1_actualPower"}
Number:Power                 budactualCHPower                "budactualCHPower [%s kW]"               (gHeizung)                                                                                                           {unit="kW", channel="km200:heatSource:719200030:heatSources:actualCHPower"}
Number:Power                 budactualDHWPower               "budactualDHWPower [%s kW]"              (gHeizung)                                                                                                           {unit="kW", channel="km200:heatSource:719200030:heatSources:actualDHWPower"}
Number:Dimensionless         budactualModulation             "budactualModulation [%s %%]"            (gHeizung)                                                                                                           {unit="%", channel="km200:heatSource:719200030:heatSources:actualModulation"}
Number:Dimensionless         budactualModulation1            "budactualModulation1 [%s %%]"           (gHeizung)                                                                                                           {unit="%", channel="km200:heatSource:719200030:heatSources:hs1_actualModulation"}
Number:Dimensionless         budburnerModulationSetpoint     "[%s %%]"                                (gHeizung)                                                                                                           {unit="%", channel="km200:heatSource:719200030:heatSources:burnerModulationSetpoint"}
Number:Power                 budburnerPowerSetpoint          "[%s kW]"                                (gHeizung)                                                                                                           {unit="kW", channel="km200:heatSource:719200030:heatSources:burnerPowerSetpoint"}
Number:Dimensionless         budCHpumpModulation             "budCHpumpModulation [%s %%]"            (gHeizung)                                                                                                           {unit="%", channel="km200:heatSource:719200030:heatSources:CHpumpModulation"}
Number:Dimensionless         budpowerSetpoint                "[%s %%]"                                (gHeizung)                                                                                                           {unit="%", channel="km200:heatSource:719200030:heatSources:powerSetpoint"}
Number:Pressure              budsystemPressure               "[%s bar]"                               (gHeizung)                                                                                                           {unit=" bar", channel="km200:heatSource:719200030:heatSources:systemPressure"}

Now my question: Do I have to adjust all patterns to %.xf in the item definitions?

You have double uints because you are using %s followed by more stuff (e.g. %%).

You either need to use a number formatter (e.g. %.1f, %d, etc) or remove the units from the lable in the Item definition. The former is better as it will cause the Item’s state to be converted to the specified unit if that label unit happens to be different from the unit metadata.

I’m not sure this is something that has changed though. Using %s should have always shown the unit causing %s %% to show the unit twice.

In fact, this would probably be the simplest solution, but I have just looked at the documentation for the sitemap and the item definition again and there is no indication of this anywhere!

Please don’t get me wrong, I’m totally fine if a Number:xxx item has no string representation, but only %d or %.xf works.

But shouldn’t there be something about this in the documentation or should an error appear in the log?

Before 4.2.x the behavior was actually different and there was no duplicate display :slight_smile: