# Convert Wind direction in degrees to Cardinal points

**URL:** <https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931>\
**Category:** Share Your Projects\
**Created:** [8 May 2019 21:50 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931 "2019-05-08T21:50:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [8 May 2019 21:50 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/1 "2019-05-08T21:50:51Z")

</div>

This change node will convert a payload in decimal degrees to Cardinal points N, NNE, NE.......

It might be useful to others using online weather services to display wind directions in human readable form.

```auto
[{"id":"ab01324c.4824","type":"inject","z":"1d66267b.4c5caa","name":"","topic":"","payload":"270","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":100,"wires":[["3280794c.eb6396"]]},{"id":"3280794c.eb6396","type":"change","z":"1d66267b.4c5caa","name":"Convert Wind Degrees To Text","rules":[{"t":"set","p":"directions","pt":"flow","to":"$exists($flowContext(\"directions\")) ? $flowContext(\"directions\") : [\"N\", \"NNE\", \"NE\", \"ENE\", \"E\", \"ESE\", \"SE\", \"SSE\", \"S\", \"SSW\", \"SW\", \"WSW\", \"W\", \"WNW\", \"NW\", \"NNW\"] ","tot":"jsonata"},{"t":"set","p":"index","pt":"msg","to":"$string($floor((payload / 22.5) + 0.5) % 16)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"directions[\"&index&\"]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":120,"wires":[["10a54176.da8daf"]]},{"id":"10a54176.da8daf","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":120,"wires":[]}]

```

EDIT: Wind direction is passed on as payload as suggested by @Colin

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [8 May 2019 22:17 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/2 "2019-05-08T22:17:59Z")

</div>

A very welcome addition Garry which would make a useful contrib-node, or at least an addition to the node-RED library as a flow.

Nice use of jsonata.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 May 2019 23:52 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/3 "2019-05-08T23:52:51Z")

</div>

+1 for what @Paul-Reed said!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 May 2019 08:17 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/4 "2019-05-09T08:17:23Z")

</div>

A minor quibble, but would it not be more conventional to pass the value on in msg.payload?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [9 May 2019 08:26 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/5 "2019-05-09T08:26:10Z")

</div>

You are right @Colin , edited the code to do just that.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [9 May 2019 08:39 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/6 "2019-05-09T08:39:45Z")

</div>

Thank you @Paul-Reed. Writing a contrib-node is beyond my skill level at the moment. I will however post it to the flow library.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 May 2019 08:42 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/7 "2019-05-09T08:42:46Z")

</div>

If it were to be a node then adding translations would be useful  
(so yes maybe leave it as a useful function for now)

---

<div class="post-metadata">

**Author:** ![scalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scalci/32/20511_2.png) [@scalci](https://discourse.nodered.org/u/scalci)\
**Post date:** [23 April 2020 18:04 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/8 "2020-04-23T18:04:49Z")

</div>

Hi, how do I use this? I have a wind meter via a serial port currently and display the decimals. This could be a great add for me...

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [23 April 2020 18:49 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/9 "2020-04-23T18:49:59Z")

</div>

Welcome to the forum!  
Just import the flow and edit it to feed your results into the change node, in other words, replace the inject node with your serial in results!

---

<div class="post-metadata">

**Author:** ![scalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scalci/32/20511_2.png) [@scalci](https://discourse.nodered.org/u/scalci)\
**Post date:** [23 April 2020 21:10 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/10 "2020-04-23T21:10:06Z")

</div>

Thx let take a look how to do that 🙂 I am learning. Where do  
I get the flow to import?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [23 April 2020 21:14 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/11 "2020-04-23T21:14:14Z")

</div>

First post in this thread

---

<div class="post-metadata">

**Author:** ![scalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scalci/32/20511_2.png) [@scalci](https://discourse.nodered.org/u/scalci)\
**Post date:** [24 April 2020 05:42 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/12 "2020-04-24T05:42:10Z")

</div>

Got it thank you, busy to see how to link it. I am learning so much, thank you everyone. I got it to work !!!, Thx Everyone.

On this, does anyone have a way to display this in a compass rose?

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 April 2020 06:32 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/13 "2020-04-24T06:32:26Z")

</div>

> [@scalci](#):
>
> On this, does anyone have a way to display this in a compass rose?

Hi Scalci,  
Do you mean to display it inside the Node-RED dashboard?

If you mean the dashboard:  
I have not tried this, but I assume it should be possible like this:

1. Add a node-red-contrib-ui-svg node to your flow
2. Download one of the many free available compass rose SVG drawings on the web. Just google for _"compass rose svg"_...
3. Past that SVG drawing in the SVG node's config screen.
4. Add e.g. a red shape (triangle/line/...) on top of that compass rose, which will visualise the wind direction.
5. When you get a new direction from Gary's node, then use e.g. a function node to compose a message that can apply a rotate-transformation to that red shape ... You can find an example [here](https://github.com/bartbutenaers/node-red-contrib-ui-svg/issues/48#issuecomment-581649047). But don't know at the moment how to calculate the angle?
6. When you now inject that message, the red shape should start rotating in the specified direction.

CAUTION: Such (rotate) transformations via input messages are not available yet in the current npm version of the SVG node. It will become available soon in the 2.0.0 version. Will try to make that version available next week! It is nearly finished ...

But perhaps anybody else has a better idea ...  
Bart

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 April 2020 06:43 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/14 "2020-04-24T06:43:32Z")

</div>

Hello Scalci,  
seems there is somebody already doing something similar (I suppose with a ui\_template node): [https://flows.nodered.org/flow/b9a57175ac5a5e240c9916bcce136dca](https://flows.nodered.org/flow/b9a57175ac5a5e240c9916bcce136dca)

---

<div class="post-metadata">

**Author:** ![scalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scalci/32/20511_2.png) [@scalci](https://discourse.nodered.org/u/scalci)\
**Post date:** [24 April 2020 14:04 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/15 "2020-04-24T14:04:20Z")

</div>

Hi Bart,

Yes, ok let me try this....

---

<div class="post-metadata">

**Author:** ![scalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scalci/32/20511_2.png) [@scalci](https://discourse.nodered.org/u/scalci)\
**Post date:** [24 April 2020 14:10 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/16 "2020-04-24T14:10:30Z")

</div>

Thank you, works great....

Thx a lot for the help.

is there way to arrange the "Dashboard" in ones own layout? At the moment it does an auto arrange according to the groups, but one can not arrange with in a group..

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 April 2020 15:30 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/17 "2020-04-24T15:30:38Z")

</div>

Hey, you are welcome.  
Unfortunately don't know that.  
And it is better to create a new discussion, because this one is about wind direction convertion... Moreover people with more dashboard might not see your question, when they focus only on the category "dashboard".

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 April 2020 15:43 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/18 "2020-04-24T15:43:27Z")

</div>

Before starting a new thread read this.

> [@Something for Friday afternoon - Dashboard Layout editor](https://discourse.nodered.org/t/something-for-friday-afternoon-dashboard-layout-editor/12957):
>
> Thanks to our friends at Hitachi a contribution to add a layout editor to the Dashboard has now been merged into master on github - as 2.16.0-beta. Currently this adds a new layout button to each tab layer in the Dashboard sidebar [image] Clicking it will open the new layout editor that will let you move things around within it more easily (I hope). If items are "unlocked" - icon top right of each widget - then they are in Auto size mode as normal - if you lock them then the bottom …

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 April 2020 22:14 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/19 "2020-04-24T22:14:32Z")

</div>

> [@Paul-Reed](#):
>
> A very welcome addition Garry which would make a useful contrib-node

Hey folks,  
for some reason I haven't seen this discussion at the time being.  
But I created tonight a beta version of [node-red-contrib-cardinal-direction](https://github.com/bartbutenaers/node-red-contrib-cardinal-direction/blob/master/README.md).  
Would be nice if you could test it, before I publish it on npm...

> [@dceejay](#):
>
> If it were to be a node then adding translations would be useful

Hey Dave,  
Unless you have found a page somewhere with all translations, this is not that easy due to the large number of translations...

I have added the ability to add [translation files](https://github.com/bartbutenaers/node-red-contrib-cardinal-direction/tree/master/languages). Currently only English and Dutch are supported...

But not sure if I understood it well. I have added two sections in my locale files:

```auto
module.exports = {
    descriptions: {
        "N": "North",
        "NbE": "North by East",
        "NNE": "Noth-northeast",
        ...
    },
    abbreviations: {
        "N": "N",
        "NbE": "NbE",
        "NNE": "NNE",
        ...
    }
}

```

I have translated the descriptions in Dutch, but I haven't translated the abbreviations for Dutch yet. For the simple reason that I'm far from a language expert...  
Or is translations of the abbreviations not want you were talking about??

Hope you guys like it...  
Bart

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [24 April 2020 22:22 UTC](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931/20 "2020-04-24T22:22:38Z")

</div>

translations... well in French West is Ouest so I would expect the abbreviation to be O - but maybe they accept W ??? need a French expert here...

While NbE is technically correct those finer points are usually never used... Just N, NNE, NE, etc

And if that's a ui node we usually expect ui in the name... node-red-contrib-ui-cardinal-direction

[Next page](https://discourse.nodered.org/t/convert-wind-direction-in-degrees-to-cardinal-points/10931.md?page=2)
