Simple compass to display wind direction

I was in the fast need to display a wind direction compass in the dashboard, with standard nodes.
The easiest way was to use the "compass" mode of a gauge node. I have also added @ghayne node to convert degrees to cardinal points (thanks Garry!).
The inject can be replaced what whatever sensor sends a number in msg.payload, while msg.topic is filled with the Cardinal string representation.

This is the flow:

[{"id":"7954150f.8bb6cc","type":"inject","z":"fd95058a.48e3e8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"242","payloadType":"num","x":170,"y":380,"wires":[["ff02c176.98bbb"]]},{"id":"ff02c176.98bbb","type":"change","z":"fd95058a.48e3e8","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":"topic","pt":"msg","to":"$flowContext(\"directions[\"&index&\"]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":420,"wires":[["37a9c647.e58c8a"]]},{"id":"37a9c647.e58c8a","type":"ui_gauge","z":"fd95058a.48e3e8","name":"Wind direction","group":"d538f03c.af247","order":0,"width":"3","height":"3","gtype":"compass","title":"{{msg.topic}}","label":"degrees","format":"{{value}}","min":0,"max":"359","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":600,"y":380,"wires":[]},{"id":"d538f03c.af247","type":"ui_group","name":"Wind","tab":"5b337e3b.68826","order":3,"disp":true,"width":"6","collapse":false},{"id":"5b337e3b.68826","type":"ui_tab","name":"Test","icon":"home","order":6,"disabled":false,"hidden":false}]

And this is the result:

Schermata 2021-06-10 alle 17.47.57

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.