Converting wind direction

#1

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?

0 Likes

#2

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

0 Likes

#3

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.

Example:

Winddirection : 182
to be displayed as:
Winddirection: South

0 Likes

#4

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.

0 Likes

#5

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

0 Likes

#6

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.

https://docs.losant.com/workflows/logic/function/

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.

0 Likes