Convert Wind direction in degrees to Cardinal points

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.

[{"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

7 Likes

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.

+1 for what @Paul-Reed said!

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

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

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.

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

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...

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!

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

First post in this thread

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?

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. 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

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

Hi Bart,

Yes, ok let me try this....

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..

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".

Before starting a new thread read this.

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.
Would be nice if you could test it, before I publish it on npm...

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. Currently only English and Dutch are supported...

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

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

2 Likes

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