Do map transformation have to account for all possible values?

I would like to use a map transformation for the rain fall channel in the Weather Underground binding as sometimes, the binding returns a non numeric value (-, null). I even got a negative value once. The channel returns a number and a map returns a string. So it seems to me that all possible values would have to be mapped, which is impractical. Does this make sense? Alternatively, I could try a JS transformation, return a parseable value (parseInt), or some default, (0.00) if it can’t be parsed (-, null, etc.).

For number values, you can map ranges to strings such as

[08:12:33] root@openhabianpi:/etc/openhab2/transform# cat airquality_outer.scale
[101..150]=Ungesund fuer Sensitive
[201..300]=Sehr ungesund
-=keine Daten

I wanted to point you at the transformation docs but quickly looking at these I didn’t see that mentioned. Must have gotten lost somehow during docs rework.


The solution given by @mstormi is a SCALE transform

Right, sorry I should have mentioned that.

Number AirQuality "Air Quality Index [SCALE(airquality_outer.scale): %s]" <carbondioxide> (Status,Lueftung)

Thanks for the reply and I also looked at the docs and couldn’t find an answer. I’d rather not map or scale ranges to different values, so I think I’ll use a JS transformation.

SCALE tranformation is a mapping of number ranges to a output string only used in UIs, so you would in my example see “Air Quality Index … Mässig” in sitemap/UI whenever the item value is anywhere from 51 to 100.
Which I thought is what you were looking for. That’s no scaling, it does not change the values. Just try it.
It is just a prebuilt JS scriptlet. But if you do can and want to code JS yourself, feel free.

Ok, I understand. I’ll give it a try.