Convert Wind Direction (degrees) to Compass Points

got it. My item didn’t like being changed to a number to string.

Make sure you have the correct transformation services enabled, I can’t remember which one is needed for this, but here’s my transform setup, it’s in the ‘OPENHAB_CFG"/openhab2/services/addons.cfg’ file.

transformation = map,jsonpath,exec,javascript,regex,scale,xpath,xslt

It is much easier to just use the Scale transformation…

1 Like

That’s what I use since April last year now.

windDir.scale

[0..11.25] = N
]11.25..33.75] = NNE
]33.75..56.25] = NE
]56.25..78.75] = ENE
]78.75..101.25] = E
]101.25..123.75] = ESE
]123.75..146.25] = SE
]146.25..168.75] = SSE
]168.75..191.25] = S
]191.25..213.75] = SSW
]213.75..236.25] = SW
]236.25..258.75] = WSW
]258.75..281.25] = W
]281.25..303.75] = WNW
]303.75..326.25] = NW
]326.25..348.75] = NNW
]348.75..360] = N
[..] = Unknown Value
NaN="N/A"

Items file

String windDir          "Wind Direction [SCALE(windDir.scale):%s]"      <wind>          (Home,Weather)  ["Data"]                {channel="mqtt:topic:mosquitto2:weather:windDir"}
String windGustDir      "Wind Gust Direction [SCALE(windDir.scale):%s]" <wind>          (Home,Weather)  ["Data"]                {channel="mqtt:topic:mosquitto2:weather:windGustDir"

Dear All,

for OH3 user I create my first widget for personal weather station
You can find it here

you can use also with other weather binding, but wind direction must be in degrees…
Any improvements and comment are welocme

I just came across the need to do this.
My version (in jruby)

# Given the direction in degrees, return the direction abbreviation
def direction_name(degree)
  degree = (degree + 11.25) % 360
  index = (degree.to_f / 22.5).floor
  %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW][index]
end