Converting wind direction


I’m trying to do some additional work with the darksky api tutorial and I wanted to convert the wind direction in degrees to cardinal direction using conditionals and setting the output to different strings. Could somebody help me out?



Hi Joshua! I’d be happy to help. Could you give more detail on the problem you are having?



I’m trying to convert the incoming wind direction in degrees taken from the darksky api data in the tutorial and turning it into a string to be displayed on the dashboard.


Winddirection : 182
to be displayed as:
Winddirection: South



That make since. I guess I’m trying to figure out where you need help.

Do you have the Wind direction in degrees already displayed on a dashboard?

Or, Do you need help with the conversion in the workflow?

I did find this:

Which may help.



I understand how to do the coding, but I don’t know how to integrate code like that into the Losant workflow.



Ah got it.

So, first, you’ll want to add windDirection as an attribute on your device. This is important because Dashboards graph/display attributes on the device’s state.

Then, you need to do the math. In this step, after you made the HTTP request, you updated the state on the device:

Before we update the state, we want to perform the conversion. You can insert a function node in between the HTTP and Device State node.

In the function node, you can update the value {{ weather.body.currently. windBearing }} to be the cardinal direction.

Then, you’ll update the new attribute you created using the Device State Node.