UoM Implementation Need Help

Hello,

I tried to understand the UoM of openhab a little bit…

My implementing is like this

Thing mqtt:topic:zwave (mqtt:broker:mosquitto) {
Type number : nodeID_16_battery "nodeID_16_battery" [ stateTopic="zwave/nodeID_16/battery/endpoint_0/level", unit="%", transformationPattern="JSONPATH:$.value"]
}
Number:Dimensionless	Z_way_number_DoorWindowSensor16_battery	"Eingangstür [%.1f %unit%]"									<battery>	(group_house_sensorbattery, group_house_sensorbatterylow)						{channel="mqtt:topic:zwave:nodeID_16_battery",  stateDescription=" "[ pattern="%.2f %" ]}


If I check my items automatically as Jan has written here UoM default units and consequences - #117 by J-N-K

I get this information

Number:Dimensionless Z_way_number_DoorWindowSensor16_battery has a state description not set in metadata

What part is wrong implemented from myside?

your code goes here

The unit is not passed to the item and you need to configure the% unit in the item again, otherwise for number: dimensionless the default unit of # will apply

Understood but how can I pass it via the mqtt binding?

If it’s openHAB4, you have to set unit for the Item:

Number:Dimensionless Z_way_number_DoorWindowSensor16_battery "Eingangstür" <battery> (group_house_sensorbattery, group_house_sensorbatterylow) {channel="mqtt:topic:zwave:nodeID_16_battery", stateDescription=""[pattern="%.1f %unit%"], unit="%" }

I updated

Number:Dimensionless	Z_way_number_DoorWindowSensor16_battery	"Eingangstür  [%.1f %unit%]"									<battery>	(group_house_sensorbattery, group_house_sensorbatterylow)						{channel="mqtt:topic:zwave:nodeID_16_battery", stateDescription=""[pattern="%.1f %unit%"], unit="%" }

but still get this information

Number:Dimensionless Z_way_number_DoorWindowSensor16_battery has a state description not set in metadata

copied the version from @Udo_Hartmann

Number:Dimensionless Z_way_number_DoorWindowSensor16_battery "Eingangstür" <battery> (group_house_sensorbattery, group_house_sensorbatterylow) {channel="mqtt:topic:zwave:nodeID_16_battery", stateDescription=""[pattern="%.1f %unit%"], unit="%" }

Getting same information…

The unit stuff discussed so far is a red herring (i.e. a false clue). The error is complaining about the state description. It thinks it’s not defined.

All I can guess is there is a syntax error somewhere in your Item config. I don’t fight syntax errors any more so that’s the biggest clue I can provide.

I just wanted to elaborate a bit on this.

The unit appended to the state update from the binding and the unit that the Item will hold are independent. The binding can pass “45 %” as the state update but if the Number:Dimensionless Item doesn’t have unit metadata defined that “45 %” will be converted to the system default unit of ONE.

45 % = .45 ONE

So you don’t pass the unit via the MQTT binding at all. You configure it on the Item. That’s the tl;dr on what everyone is saying. That’s usually the root cause of UoM problems. But that isn’t the problem here. You’ve some syntax error in your stateDescription metadata or elsewhere in the Item definition.

thanks for zour input but noe I am alittle bit confused…

I generated an item in the gui and getting the same information from my script


and see in the log

2024-01-29 18:52:40.797 [INFO ] [enhab.automation.script.file.test.js] - Number:Dimensionless Generic_MQTT_Thing_nodeID_16_battery has a state description not set in metadata

A pattern of just “%” is kind of meaningless. The pattern needs to follow Items | openHAB.

And what is that rule?

That indicates this log statement is coming from a rule.

copied from here


rules.JSRule({
  name: "pihole API rule",
  description: "Access to pihole API",
  triggers: [triggers.GenericCronTrigger("0/40 * * * * ? *")],
  execute: (event) => {

var response = actions.HTTP.sendHttpGetRequest("http://localhost:8080/rest/items?metadata=statedescription&recursive=false");

    const items = JSON.parse(response);
    let itemCount = 0;

    items.forEach(item => {
        if (item.type.startsWith('Number:')) {
            if (item.stateDescription == undefined) {
                console.log(item.type + ' ' + item.name + ' has no state description at all');
                itemCount++;
            } else if (item.stateDescription.pattern.includes('%unit%')) {
                console.log(item.type + ' ' + item.name + ' has state description with unit placeholder');
                itemCount++;
            } else if (item.metadata == undefined || item.metadata.stateDescription == undefined) {
                console.log(item.type + ' ' + item.name + ' has a state description not set in metadata');
                itemCount++;
            }
        }
   

    console.log('Total number of items that need your attention: ' + itemCount);
});

OK, so that rule identifies those Items you have which might need attention by defining unit metadata.

And this leads me back to my original assessment. There is something wrong with the Item definition which is preventing this Item from having a stateDescription metadata. The JSON that is returned from the REST API lacks the stateDescription metadata.

I’m not sure what this has to do with PiHole or why you’d run it every 40 seconds.

Pull the JSON and look at it or add some logging to see more about this Item’s JSON.

It’s not a problem for an Item to not have a State Description by the way. It’s only a problem if you are trying to define it and it’s not applying. Are you certain your changes to the .items file are being picked up when you save the file?

It’s my test rule originally started to implement the pihole v6 api never changed the name so it’s my test rule…> Nothing to do with pihole

When I do changed I want to run it regularly why 40s …just a random thing

Yes, the json file or the api returns no meta data for this items…this is my question why is there no meta data? Okay for the file based one I need to check the spelling but for the GUI created one also no meta data is there…

Yes, I am guess so that is updated because I change always the item description and this is at least updated

Your screen shots are not super clear (screen shots are very hard to read, the contents of the code tab are almost always better), but the actual Pattern applied there in the screen shot is not valid. A pattern of “%” isn’t going to do anything. I don’t know if that will cause problems. Maybe?

If you leave the Item page and come back does it still have State Description metadata? If you restart OH does it still have State Description metadata?

I changed it to

value: " "
config:
  pattern: "%.1f %unit%"

and unit to

value: " %"
config: {}

Yes, it’s there after saving…

In the JSON now I see

{"link":"http://smarthome.fritz.box:8080/rest/items/Generic_MQTT_Thing_nodeID_16_battery","state":"1","stateDescription":{"step":1.0,"pattern":"%.4f %unit%","readOnly":true,"options":[]},"unitSymbol":"%","editable":true,"type":"Number:Dimensionless","name":"Generic_MQTT_Thing_nodeID_16_battery","label":"nodeID_16_battery","category":"","tags":["Point"],"groupNames":[]}

Why does the rule tell me no meta data then?

I tested if it has sth. to do for Number:Dimensionless but even when I use the type Number:Power is says

Number:Dimensionless Generic_MQTT_Thing_nodeID_16_battery has a state description not set in metadata

I am confused :face_with_peeking_eye:

This is a item in which everything is correct according to the rule…

Besides the unit I don’t see any differences

Number:Temperature number_weatherflow_temperaturetempest has state description with unit placeholder



{"link":"http://smarthome.fritz.box:8080/rest/items/number_weatherflow_temperaturetempest","state":"2.52 °C","stateDescription":{"pattern":"%.2f %unit%","readOnly":true,"options":[]},"unitSymbol":"°C","editable":false,"type":"Number:Temperature","name":"number_weatherflow_temperaturetempest","label":"Aussentemperatur","category":"thermometer","tags":["Measurement","Temperature"],"groupNames":["group_climate","group_weatherstationmodel"]}

No space.

"%"

Without some logging from the rule :person_shrugging: .

What ever the rule is receiving and parsing doesn’t have the stateDescription.