Map Transformation in profile items

Hello, I’m new to OpenHAB (I started with version 5.2). I’m trying to learn, but I’ve run into a problem that’s been driving me crazy for a few days. As a learning exercise, I’m trying to create yet another widget to display weather forecasts from Open-Meteo. My issue is that the WMO code isn’t converting to an icon when I define the transformation within the Item itself.

I’m using the binding available in add-on store (Open Meteo weather forecast binding).

Items file definition:

Number OM_WMO_code_Today "[%.1f]" (gOpenMeteoWheaterForecast)  [""] { channel="openmeteo:forecast:openmeteobridge:OpenMeteoSocket:forecastToday#weather-code" [profile="transform:MAP", function="WMO.map", sourceFormat="%.1f"]}

Excerpt from the mapfile:

3=cloud
3.0=cloud
“3,0”=cloud
3,0=cloud

I’ve tried entering every possible combination.

Here is what get in the Item (no transformation):

{"state":"3.0","displayState":"3,0","numericState":3,"type":"Decimal"}

From the log:

WARN	org.openhab.transform.map.internal.profiles.MapTransformationProfileCould not transform state '3.0' with function 'WMO.map' and format '%.1f'

I’ve tried every formatting combination (%.1f, %s, %d); even %u (as a last resort :grinning_face: ). No success.

Note that if I define transformation in Metadata: stateDescription

Il works like a charm

I would simply like to manage everything via files.

Thank you

Alberto

As far as I understand, the profile functionality actually assigns to the item the value given by the MAP function, and it fails because you cannot assign a string to Number Item.

On the other hand, when you define the transformation MAP in the displayState metadata in the UI, you are not changing the item value , which remains a number, but only the way it is displayed.

When dealing with widgets you should then use displayState and not state.

IMHO using profiles in linking things channels to items may be confusing while learning because there are edge cases which are legitimate but are not dealt properly by the UI (but the implementation in the various versions of oh is improving so that forum comments valid for an older version may not apply to a newer one).

Anyway, I would suggest you to use the UI and learn the various copy functionalities which are now available in oh 5.2. You define things and items in the UI but then you can have them converted to DSL format, which is the way files are written.

As I previously wrote, your particular case of setting up a profile during the linking of a thing channel to an item may be an exception. I am not sure whether the UI will allow you to assign a numeric channel to a string item, even though you define a legitimate transformation that output a string.

Thanks Lionel,

You made me think about the specific return type. Having used JS for years, I never really worried too much about variable types. I believed (and still do …) that any transformation should be applied to the output format (e.g., printf or format).
Anyway, following you, I modified the item as follows:

String OM_WMO_code_Today "[%s]" (gOpenMeteoWheaterForecast)  [""] { channel="openmeteo:forecast:openmeteobridge:OpenMeteoSocket:forecastToday#weather-code" [profile="transform:MAP", function="WMO.map"]}

and got this result:

{"state":"sun_max","type":"String"}

I completely lost the displayState. But I can live with that.

BTW, I copied the DSL definition from an item that was configured via the UI (and thus working):

Number OM_WMO_code_DayX "[MAP(WMO.map):%s]" (gOpenMeteoWheaterForecast) [""] { channel="openmeteo:forecast:openmeteobridge:OpenMeteoSocket:forecastToday#weather-code"}

I pasted it into the file and removed the metadata, but no way it still working (even with “String” return).

There’s something I’m not quite grasping. But I have to accept it…

Thank you

Alberto

A profile applied to a channel modifies the actual data that the item receives.

Thing -> channel-----> profile  ---- > Item
                  num -> MAP -> string    

Your item receives the output of the profile which is literally sun_max, cloud, etc. The input to the profile (the number) is completely gone / translated / replaced with the profile output.

There are other types of profile that can deal with or manipulate numeric data, e.g. multiplies it, averages it, etc.

A Map profile can only translate an input string to an output string.

Whereas the display format in the label or in stateDescription is just something that applies to the item state before it is displayed. It doesn’t change the underlying state of the item.