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: