Convert wind direction to compass direction

String = Text

UGGHā€¦

Thanks for helping @Nezmo!

When posting an expression, itā€™s usually best to wrap it in a code block. You can use the </> button in the toolbar or wrap the content in triple backticks to treat it as preformatted text

```
"Content here"
```

That preserves the formatting, spacing, and characters as-is.

1 Like

Thanks Josh. I couldnā€™t remember if you could then copy and paste from a code block here but you can.

1 Like

Thanks Josh. We are now having another issueā€¦ invalid variable.
@josh

This has me foxed. I have no idea how that is happening. Did you delete the previous instance of that variable before recreating it as a text variable?

Yepā€¦ There was no way to edit it. Deleted and started fresh.

Of course.

I need to defer to Josh on this one. I canā€™t recreate that.

I just deleted the entire rule and started over. Same resultā€¦

@Nezmo -

I really appreciate your help. Iā€™m closer than I was before. Iā€™ll keep tinkering with it.

What does the expression look like? If there is an invalid variable in the expression when it is run, thatā€™s what the result of it will be.

Edit: for example, it looks like you mean for $degrees to be a local variable. In that case, it shouldnā€™t be prefixed with a $ as that tells the system, itā€™s a global variable.

This is it, with a slight correction of one of the cardinals:

$degrees = $context.response.data.hourly.0.wind_deg
$degrees > 337 ? "NNW" : $degrees > 314 ? "NW" : $degrees > 292 ? "WNW" : $degrees > 269 ? "W" : $degrees > 247 ? "WSW" : $degrees > 224 ? "SW" : $degrees > 202 ? "SSW" : $degrees > 179 ? "S" : $degrees > 157 ? "SSE" : $degrees > 134 ? "SE" : $degrees > 112 ? "ESE" : $degrees > 89 ? ā€œEā€ : $degrees > 67 ? "ENE" : $degrees > 44 ? "NE" : $degrees > 22 ? "NNE" : "N"
1 Like

Ah, my bad!

Sometimes you just need fresh eyes.

1 Like

Deleted $ Same result.

Scratch that. I only deleted one of them. Waiting for the triggerā€¦

No good. Same result.

Is this the correct expression?

degrees = $context.response.data.hourly.0.wind_deg
degrees > 337 ? "NNW" : $degrees > 314 ? "NW" : $degrees > 292 ? "WNW" : $degrees > 269 ? "W" : $degrees > 247 ? "WSW" : $degrees > 224 ? "S" : $degrees > 202 ? "SSW" : $degrees > 179 ? "S" : $degrees > 157 ? "SS" : $degrees > 134 ? "SE" : $degrees > 112 ? "ESE" : $degrees > 89 ? "S" : $degrees > 67 ? "ENE" : $degrees > 44 ? "NE" : $degrees > 22 ? "NNE" : "N"

EDIT: do I need to delete all 16 $ ( I guess that only makes sense )

1 Like

No. It still has the references to $degrees in several places. All of them have to be updated so they reference the same local variable.

They would all need to be replaced:

degrees = $context.response.data.hourly.0.wind_deg
degrees > 337 ? "NNW" : degrees > 314 ? "NW" : degrees > 292 ? "WNW" : degrees > 269 ? "W" : degrees > 247 ? "WSW" : degrees > 224 ? "S" : degrees > 202 ? "SSW" : degrees > 179 ? "S" : degrees > 157 ? "SS" : degrees > 134 ? "SE" : degrees > 112 ? "ESE" : degrees > 89 ? "S" : degrees > 67 ? "ENE" : degrees > 44 ? "NE" : degrees > 22 ? "NNE" : "N"
1 Like

Try this:

degrees = $context.response.data.hourly.0.wind_deg
`degrees > 337 ? "NNW" : degrees > 314 ? "NW" : degrees > 292 ? "WNW" : degrees > 269 ? "W" : degrees > 247 ? "WSW" : degrees > 224 ? "SW" : degrees > 202 ? "SSW" : degrees > 179 ? "S" : degrees > 157 ? "SSE" : degrees > 134 ? "SE" : degrees > 112 ? "ESE" : degrees > 89 ? ā€œEā€ : degrees > 67 ? "ENE" : degrees > 44 ? "NE" : degrees > 22 ? "NNE" : "N"`

And > 89 should be E

That put me back to this: