Errors after Upgrade to OH4 (unit conversion and icon file)

HI there,

after upgrading to OH4 i have Unit conversion errors in the logfile

2023-07-29 10:17:33.293 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours01_Visibility' because '80 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.347 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours02_Visibility' because '74 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.428 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours03_Visibility' because '72 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.539 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours04_Visibility' because '97 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.624 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours05_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.728 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours06_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.884 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours07_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.933 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours08_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:33.992 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours09_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:34.083 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours10_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:34.154 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours11_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:34.242 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours12_Visibility' because '89 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.553 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours01_Visibility' because '80 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.623 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours02_Visibility' because '74 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.680 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours03_Visibility' because '72 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.735 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours04_Visibility' because '97 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.786 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours05_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.867 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours06_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:36.938 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours07_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:37.016 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours08_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:37.063 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours09_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:37.119 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours10_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:37.195 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours11_Visibility' because '100 %' could not be converted to the item unit 'm'
2023-07-29 10:17:37.266 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item 'ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastHours12_Visibility' because '89 %' could not be converted to the item unit 'm'

I checked the channel and the item. both are set to length. Where does the “%” come from?

Second error is about a icon file:

2023-07-29 10:17:23.592 [ERROR] [org.openhab.core.items.GenericItem  ] - Tried to set invalid state raw type (image/png): 3793 bytes (StringType) on item ABWetterOneCallAPILokalesWetterundWettervorhersage_ForecastDay4_Icon of type ImageItem, ignoring it

What to do about this one?

br

Have you set unit metadata on these Items?

And also, what’s updating this item - a state in some binding, MQTT, REST? If you could add a little more context, I think that could be useful. Please also include item definition.

Hi!
Thanks for your answers!

@rlkoshak:
There is no unit in metadata defined:

@laursen:
The item is updated through the OpenWeathermap binding

br

It looks okay from the binding side:

and the update:

strange. What else would do an update to that item? There is no MQTT/API or rule which update those items.

The item currentVisibility is working without errors. This is configured exactly the same as the forecast items are.

Deleted all the ERROR items and recreated only one of them.

Immediatly the error came up in openhab.log:

even when i change the item name (that should exclude all external updates)

Well, have you tried defining it? All Number:X type Items must have unit metadata defined or else the system default is assumed. The default for Number:Length in SI units is m.

Note, in this one case a screen shot is OK. But in general always click on the Code tab and paste in the text you find there when trying to show the configuration of and entity within OH. For Items you can click the “edit” option and find the code tab from there.

Use code fences.

```
code goes here
```

Also use code fences for logs. Screen shots of logs are pretty much useless.

That should address part of the problem at least.

No, haven tried that.

But this does not explain why “Current Visibility” is working with the same configuration. There is no unit configured also…
This makes no sense that one thing/item works and the others do not :confused:

Youre absolutely right about screenshots and logs. Will do it better!

All I know is that in OH 4, if you don’t supply unit metadata, the system default is used. So the first thing you should do when experiencing problems is define unit metadata.

The fact that is works with one Item and not another means there is something different. Without being able to tell what is different, you may as well start setting up the not-working Item the way it’s supposed to be set up, which means defining unit metadata. If that fixes it, great! If not, at least we’ve eliminated a whole class of potential problems.

But i think in this case “meter” is the right one. So the item type is correct with number.length.

If something is sending “%” to the item and i define the unit “m”, will OH convert the value to “m”?

eg: 14 % → 14 m

No because there is no conversion from % to meters. That’s mathematically nonsensical so OH will generate an error. It would convert 50 cm to 0.5 m or even 3.28 ft to 1 m, but 14 % isn’t a length so there’s no conversion possible.

Just in case it helps I was testing a binding prior to publishing anything in the community, and opening the PR.

I had:
01:55:54.618 [WARN ] [openhab.core.library.items.NumberItem] - Failed to update item ‘ForecastLondonVisibility’ because ‘17484 m’ could not be converted to the item unit ‘one’

In my case the units in the binding were correct Number:Length, I messed up the sample entries in the readme I was testing with, I had the incorrect type of Number:Dimensionless… So could it be a type mapping error possibly, if using file based config? Just wondering if you add it from the UI does it work?

I had the same Problem between the two items:

  1. OneCallAPIweatherandforecast_Current_Visibility
  2. OneCallAPIweatherandforecast_ForecastToday_Visibility

The first item didn’t need a change (Number:Length (m), no Unit defined).
The second item has the same definition (Number:Length (m), no Unit defined) … but cause the following errors:

2023-07-31 19:47:25.084 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item ‘OneCallAPIweatherandforecast_ForecastToday_Visibility’ because ‘3 %’ could not be converted to the item unit ‘m’
2023-08-06 10:51:13.899 [WARN ] [penhab.core.library.items.NumberItem] - Failed to update item ‘OneCallAPIweatherandforecast_ForecastToday_Visibility’ because ‘100 %’ could not be converted to the item unit ‘m’

Changing the Unit to % didn’t help. Changing the item definition from Number:Length to Number:Dimensionless and setting the Unit to % solved the issue.

It is strange that “visibility” has different messure / number types.

OneCallAPIweatherandforecast_Current_Visibility

{
“link”: “http://openhab:8080/rest/items/OneCallAPIweatherandforecast_Current_Visibility”,
“state”: “10000 m”,
“stateDescription”: {
“pattern”: “%.1f %unit%”,
“readOnly”: true,
“options”: []
},
“unitSymbol”: “m”,
“metadata”: {
“semantics”: {
“value”: “Point”,
“config”: {
“isPointOf”: “WetterAktuell”
}
}
},
“editable”: true,
“type”: “Number:Length”,
“name”: “OneCallAPIweatherandforecast_Current_Visibility”,
“label”: “Sichtweite”,
“category”: “”,
“tags”: [
“Point”
],
“groupNames”: [
“WetterAktuell”
]
}

OneCallAPIweatherandforecast_ForecastToday_Visibility before the change

{
“link”: “http://openhab:8080/rest/items/OneCallAPIweatherandforecast_ForecastToday_Visibility”,
“state”: “NULL”,
“stateDescription”: {
“pattern”: “%.1f %unit%”,
“readOnly”: true,
“options”: []
},
“unitSymbol”: “m”,
“metadata”: {
“semantics”: {
“value”: “Point”,
“config”: {
“isPointOf”: “WetterHeute”
}
}
},
“editable”: true,
“type”: “Number:Length”,
“name”: “OneCallAPIweatherandforecast_ForecastToday_Visibility”,
“label”: “Sichtweite”,
“category”: “”,
“tags”: [
“Point”
],
“groupNames”: [
“WetterHeute”
]
}

OneCallAPIweatherandforecast_ForecastToday_Visibility after the change

{
“link”: “http://openhab:8080/rest/items/OneCallAPIweatherandforecast_ForecastToday_Visibility”,
“state”: “100 %”,
“stateDescription”: {
“pattern”: “%.1f %unit%”,
“readOnly”: true,
“options”: []
},
“unitSymbol”: “%”,
“metadata”: {
“unit”: {
“value”: “%”
},
“semantics”: {
“value”: “Point”,
“config”: {
“isPointOf”: “WetterHeute”
}
}
},
“editable”: true,
“type”: “Number:Dimensionless”,
“name”: “OneCallAPIweatherandforecast_ForecastToday_Visibility”,
“label”: “Sichtweite”,
“category”: “”,
“tags”: [
“Point”
],
“groupNames”: [
“WetterHeute”
]
}

There might be other items in the OpenWeatherMap binding or OH4 which have the same problem and solution.

But what is the logical “right” unit for visibility?
I think the worst case is to mix up the units (current = m ; forcast = %).

This has to be changed in the binding, right?

Yes, I agree, the unit for all visibility values should be the same.
Do you know what the unit of the visibility values was in OH2 / OH3 - “m” or “%”?

I wonder that the higest value of Current_Visibility was “10000 m” … possibly 100.00% ???
Without knowing the details of OpenWeatherMap it is difficult to interpret the numbers into the right value with the right unit

Maybe the API returns a % while a meter is expected by the binding ? That would be something to fix in the binding in case it is confirmed that this value is systematically returned in %.

On the website visibility is length unit so I think percent is wrong.

This shows that the current visibility is number:length. At least what I could see in the forecasts, it didn’t provide visibility, so I’m not sure we know what they are providing for the forecast. It is not sensible to use different units, but at this point I can’t tell if it is the API or the binding. I’m not really using the forecast visibility, so I’m going to unlink it until this is resolved to get the warnings out of my log.

There power of UoM is it doesn’t matter what the Channel is reporting. Set the unit metadata on the Item to the units you want to see visibility in and what ever the binding reports will be converted to that.

If you are in the US, miles is ornament what you’d want (I think the unit is “mi” but you’ll have to confirm). Everywhere else will probably want to use “km”.

Visibility is how far you can see due to haze, so a 10000 m reading is perfectly reasonable.