# Change wind direction degrees into N, W, S or E

Hey Everyone,

I appreciate your help. Could you please guide me trough the following.

I want to convert the ‘wind direction, degree’ to a text value like N, W, S or E.

For example when the weather module output value is between 310° and 320° I would like to convert it to NW (north west). Or when the value is between 350° and 10° it supposed to be N (north).

could someone show me a function example or a different approach to this?

This is my Kitesurf forecast scenario at the moment:

When the wind direction is correct and windspeed is above a threshold it will send a message in Discord. That we can Kitesurf. But at the moment for the wind direct, I can only send a degree value. and I want this to be just N or N/NW or NW etc. etc.

Hello Aymen,

You could use “Set a variable” in the Tools, and build a function like this one:

.
This one is limited to N, E, S, W, but the idea is here (the main problem is the north).

After you can use this new variable where you want.

I hope it helps you.

BR

Philippe

2 Likes

Hey Philippe, Thank you for your help!

Hello Aymen,

If it is OK for you, could you change the status of your question to solved?

PBI

P.S.: I think that a better solution could be developed using Euclidean division and a switch…

2 Likes

Hey Philipe,

Thanks again, I managed to make it work.

Instead of a Tools module to set a variable I choose to just adjust the wind direction variable inside the discord message field. as shown in the print screen. it saves me an operation.

For everyone that is looking for a similar solution I’ll paste the functions right here:

``````{{if(346 < 1.wind.deg & 1.wind.deg <= 360 | 0 <= 1.wind.deg & 1.wind.deg <= 15; "N"; if(16 < 1.wind.deg & 1.wind.deg <= 35; "N/NE"; if(36 < 1.wind.deg & 1.wind.deg <= 55; "NE"; if(56 < 1.wind.deg & 1.wind.deg <= 75; "E/NE"; if(76 < 1.wind.deg & 1.wind.deg <= 105; "E"; if(106 < 1.wind.deg & 1.wind.deg <= 125; "E/SE"; if(126 < 1.wind.deg & 1.wind.deg <= 145; "SE"; if(146 < 1.wind.deg & 1.wind.deg <= 165; "S/SE"; if(166 < 1.wind.deg & 1.wind.deg <= 195; "S"; if(196 < 1.wind.deg & 1.wind.deg <= 215; "S/SW"; if(216 < 1.wind.deg & 1.wind.deg <= 235; "SW"; if(236 < 1.wind.deg & 1.wind.deg <= 255; "W/SW"; if(256 < 1.wind.deg & 1.wind.deg <= 285; "W"; if(286 < 1.wind.deg & 1.wind.deg <= 305; "W/NW"; if(306 < 1.wind.deg & 1.wind.deg <= 325; "NW"; if(326 < 1.wind.deg & 1.wind.deg <= 345; "N/NW"; ))))))))))))))))}}
``````

Cheers!

1 Like