OH 3 Scale profile exception while formatting value

Hello.
I have DarkSky weather location.
Wind Direction channel added.
Linking Number:Angle · Point>Measurement item. Done:

Item 'DarkSkylocalweather_WindDirection' changed from NULL to 171.0 °

Linking String · Point item with scale transformation. Err:

[WARN ] [e.internal.SseItemStatesEventBuilder] - Exception while formatting value '171.0 °' of item DarkSkylocalweather_WindDirectionString with format '%.0f %unit%': Conversion = 'u'
[WARN ] [.profiles.ScaleTransformationProfile] - Could not transform state '171.0 °' with function 'winddir.scale' and format '%.0f'

winddir.scale:

[349..360]=N
[0..12]=N
[13..33]=NNE
[34..56]=NE
[57..78]=ENE
[79..101]=E
[102..123]=ESE
[124..146]=SE
[147..168]=SSE
[169..191]=S
[192..213]=SSW
[214..236]=SW
[237..258]=WSW
[259..282]=W
[283..303]=WNW
[304..326]=NW
[327..348]=NNW
[..]=UNKNOWN

What i’m doing wrong?

[ I’m not sure SCALE works at all with Quantity Types with units.
If it does, you would need to supply the units in your scale file … it couldn’t know if you mean degrees or radians etc. ]

EDIT oh wait, that’s all nonsense. SCALE sould work with Quantities, but you have to hope your Item is in the correct units first, degrees in your case.
Your problem is that the output of any transformation used in state description is always a string.
So -
with format '%.0f %unit%'
will not work - there ar no decimals or units in WSW anyway.
Use %s in your state description. If your Item is defined in an xxx.items file, that is the part in [ ]

1 Like

I have exactly the same problem when trying to transform an OpenWeatherMap’s wind direction angle to a string representation.

Item definition is:

    String OneCallAPIweatherandforecast_Current_Winddirection_Msg 
    	"Windrichtung" 
    	<wind> 
    	{ channel="openweathermap:onecall:e6ba78b3ab:local:current#wind-direction"[profile="transform:JS", function="windDir.js" ] }

transform/windDir.js is (minimized example for debugging!):

    (function(i) {
    	return "test: " + i;
    })(input)

Log output is:
16:58:51.212 [WARN ] [se.internal.SseItemStatesEventBuilder] - Exception while formatting value 'test: 230 °' of item OneCallAPIweatherandforecast_Current_Winddirection_Msg with format '%.0f %unit%': Conversion = 'u'

I do not get where this format string comes from. It doesn’t matter if I add ‘[%s]’ to the label, the message stays the same. It seems to me that OH3 somehow inherits the format string from the channel…?!

Btw, please note the ‘°’ in the error message. This means that the transformation does not get the raw decimal value but the formatted one as parameter.

Thanks, adding %s parameter helped to fix the problem.

It’s not exactly the same problem, because your version involves channels and profiles and not UI. Similar parts involved.

The transformation profile has been enhanced for OH3 (to work with non-String Item types), it is possible some problem has been introduced. This is recent work, your OH3 version will be important.

I’ll guess it is from the channel, pre-defined by the binding as a default format in case you don’t give one in your Item definition (and you don’t).

It seems reasonable for the framework to use that to format the channel output into the string that is needed to feed into your transformation.

However, the error message suggests it is using that format to try and format the output of your transformation before passing to the Item state. It blows up because transform output is always a string and cannot be formatted with %.0f

I think you may have run into a bug involving combination of default format or ‘pattern’ with transform profile.

No - it means it gets the full Quantity Type output of the binding channel, as a string. The binding channel type is number:angle, and absolutely should look like “230 °” when it arrives at your transformation. The units are part of the value from the binding.

Thanks for you answer. I was able to solve this using a rule meanwhile, but of course the usage of a transformation would be a smarter solution.

The version is 3.0.0-1 from the openhab.jfrog.io debian repo, running on Raspberry Pi 3b.

This is the optional “[%s]” part behind the Item’s label, isn’t it? I’ve tried that, but it doesn’t made any difference.

Maybe this is a newbie question, but is there any method to get the unformated raw value from a Item? At the moment I’ve solved this by passing the value into parseInt(), which ignores any characters after the last number.

Yes, but the original question was about bindings and channels before we get to any Item.

What context are you looking to do this in - a rule, transformation or script of some kind, what kind? Or for display, using sitemap, HABpanel?

Same issue here, but I defined the item within the MainUI.

The item is linked to the according channel and using a scale file

which is basically identical to one in the initial post here.

Exception while formatting value 'NO' of item Wind_Direction with format '%.0f %unit%': Conversion = 'u'

That is the error message I receive, though the content of the item is correct.
So, where do I fix this in OH3 when an item is created via the MainUI?

I don’t think it makes any difference how you create your target String type Item.
Your problem does look the same as @Cybso , although you’ve not shown us the crucial part - the profile you selected for your channel link.

@Cybso did not find a fix for this problem,but a circumvention (doing the transformation elsewhere)

The nature of the problem appears to be that the transform profile framework attempts to use a binding supplied default state presentation format on the output of a transform.

This blows up when a numeric channel’s format is used on a string output.

Not all bindings supply a default state presentation format for any given channel, so it’s not an obvious problem.

There is an open issue (bug) which is about all this but originating from a different profile type

so hopefully it will get fixed in the framework at some point.

Meantime, the workaround is to use two Items and a rule that transforms from raw numeric Item to alpha Item.

Not sure though, what the profile is on OH3 - still new and need to get used to it. :grinning:
The item is linked as displayed below:

Although “Err” is displayed, the item shows everything correct in the widget.
The linked channel is actually defined as follows,

Reading the bug description, it looks like I pretty much have the same issue.

Okay,for background. Terminology is non-obvious.

Bindings supply different single bits of data via channels.
Each channel can be linked to an Item; essentially piping the data to the Item state.
But there are different types - we’d usually link a dimmer type channel to a Dimmer type Item etc.

In this case, the binding supplies a quantity, a numeric but with units included. Specifically a number:angle type channel.
Invisibly, this binding also supplies a default formatting suggestion - %.0f %unit% meaning “show this state with no decimal places and do show the units”. Reasonable, and if you don’t like that you can override the default in your Item or UI.

So far, so good.
Profiles in openHAB are optional add-ons that manipulate the data that a channel supplies before it gets put into the Item state - you can pull tricks like convert 2231 to 22.31 or “fred” into “Fred Smith”.
There are various types of profile - you’re using a transform of type SCALE. It’s a fancy lookup table, in your case turning 180.7 degrees into “S”.

Now, that “S” is not going to fit in a numeric Item type, so here we break the usual rules and link a number:angle channel type to a String type Item. That’s all fine, the number:angle quantity goes into your SCALE profile but a string comes out, ready to be piped to your Item state.

The problem is that the framework picks up that default formatting suggestion, and tries to apply it to the transformed output of the profile.
Here, it tries "show no decimal place but do show units"on a string “S”.
There ain’t no decimal, it’s not numeric. It fails.
They’ve got to fix the framework, maybe ignore the format suggestion.

Hi Maxim,

i´ve the same problem. Can you pls provide your ITEM configuration?

Thats mine and it does not work.

String localCurrentWindDirectionS "Direction [%s]" <wind> {channel="openweathermap:weather-and-forecast:api:local:current#wind-direction"[profile="transform:SCALE", function="winddirection.scale",sourceFormat="%s"]}

reagrds

Your openhab.log may provide more details on why not.

Hi rossko,

it seems to be an caching problem. I start tracing the openhab.event.ItemStateEvent and after reloading the hole .item file i see this entry in the log.

2021-01-13 17:14:59.974 [TRACE] [openhab.event.ItemStateEvent        ] - Received event of type 'ItemStateEvent' under the topic 'openhab/items/localCurrentWindDirectionS/state' with payload: '{"type":"String","value":"W"}'

2021-01-13 17:14:59.975 [INFO ] [openhab.event.ItemStateEvent        ] - Item 'localCurrentWindDirectionS' updated to W

So, solution is as you mentioned. Putting [%s] in the state description did the trick

best regards

After reboot:

[WARN ] [e.internal.SseItemStatesEventBuilder] - Exception while formatting value 'NW' of item DarkSkylocalweather_WindDirectionString with format '%.0f %unit%': Conversion = 'u'

Item settings:

I changed %s to [%s]:

[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'DarkSkylocalweather_WindDirectionString' changed from NW to

Then I returned %s:

2021-02-05 20:53:12.484 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'DarkSkylocalweather_WindDirectionString' changed from  to NW

2021-02-05 20:53:12.485 [WARN ] [e.internal.SseItemStatesEventBuilder] - Exception while formatting value 'NW' of item DarkSkylocalweather_WindDirectionString with format '%.0f %unit%': Conversion = 'u'

Problems again.

Hi,
with OH 3.0.1 Milestone 2 I am facing the same problems. Are there any updates on this issue? @makon do you have a workaround for this issue?
Br, Thomas

Here (again) is the issue, which you can read for updates

Thanks. That workaround did it!
I had the pattern at transformation level and not at item-level.

I’m running now on openHAB 3.1.0.M3.

Just tried this one also, but without success.
Initial setting is:

which returns in the openhab.log:
[WARN ] [e.internal.SseItemStatesEventBuilder] - Exception while formatting value '2' of item Wind_Speed_Beaufort with format '%.1f %unit%': Conversion = 'u'

Now changing to the square brackets

I receive the following in the log,

[WARN ] [e.internal.SseItemStatesEventBuilder] - Exception while formatting value '-1' of item Wind_Speed_Beaufort with format '%.1f %unit%': Conversion = 'u'

Hi,
for me, it helped to set the %s as state formater in the Scale of the thing AND the %s as well as state description in the item.