Change wind direction from degrees to letters i.e. S/W/N/E

Hey Homies!

This topic has been discussed briefly in a thread with another topic, but I thought it is worth it’s own.

I have a weather station using the Oregon protocol that among other things report wind direction. The station has a desk top “central” showing the wind direction with an arrow pointing to eight different directions like N, NE, E, SE…and so on.

In addition to this I still use my previous hub (Tellstick) for 433 MHz sensors and that shows the wind directions in even more increments like NNE, WNW, SSE…and so on.

I know that this is not something that is a Homey feature, but I’m thinking that it might be possible to make a flow that can convert the degrees to directions. Something like this:

IF wind direction is between 335° and 25° display N
IF wind direction is between 155° and 205° display S

I’m neither smart or knowledgeable enough to figure this out (if there even is a way) so now I’m calling on the vast knowledge of the Homey forum to see if someone else can find a solution for this not very crucial request, but perhaps interesting “problem”.

Cheers
Paxman

Some pictures showing Homeys reporting of direction and Tellsticks. These are taken at the same time and the values are from the same sensor.

Homey:
Skärmavbild 2023-03-15 kl. 10.23.37

Tellstick:
Skärmavbild 2023-03-15 kl. 10.23.44
Note that Tellstick (and the “central”) show wind strength as m/s which is the standard unit here in Sweden. In the other thread I mentioned above there is a workaround for this using a virtual device. It still shows km/h unit but the number is m/s. So when I check the virtual device with the numbers in the picture above it shows 4.3 km/h and 5.3 km/h.

I think better logic has some possibilities to make it quite easy, but I hardly use BL.

What i came up is when your are able to get the wind degrees in a number logic variable;

Logic WHEN a variable changed, AND logic number is greater then …. AND logic is smaller than…… THEN logic set a variable…. To N or S or W etc etc

2 Likes

I will try that Marcel…but I just realized one big problem: since I need to have a span of degrees for this to work there will be an issue setting this up for N. The span needs to be from a high degree number to a low one, lets say what I wrote in my first post: 335° to 25°.

All the other directions shouldn’t be any problem, since the span can be from a lower number to a higher.

Then use an extra step:

335° to 360° = N

and

0° to 25° = N

3 Likes

Good thinking basvanderploeg! I’ll do some testing and report back when I have the time.

OK, so I have been trying to figure this out but has not been successful.

My thought was to use a virtual device to be the “display” for the text wind direction but I have only been able to get the virtual device to display the numeric direction.

I have tested to use BL and Logic to set a variable (“Vindriktning”) to the different letters corresponding to the different degrees spans.

For the virtual device I tried:

Skärmavbild 2023-03-28 kl. 16.02.11

This did not work at all.

Is there any device or other way to display a text variable?

Another aproach. Copy the script. Use the name of your variable where the degrees are stored . At line 2 of the script you can add this name on the position where the variable name says 'Winddegree. Save the script and name it winddirections.

//Getting logic id
var varName = ['WindDegree'];//add your logic variable name where the winddegrees are stored.
var logicId = []
var count = 0;

while(count <= varName.length -1)
{
var Logic = await Homey.logic.getVariables();
let idArr = Object.entries(Logic);
let filtered = idArr.filter(([key, value]) => value.name==varName[count]);
let [ [ ,{ id: varNameId }]] = filtered;
logicId.splice(count, 1,varNameId);
count++
}

//Logic variable winddirection
var windDegree = await Homey.logic.getVariable({ id: logicId[0]}) ;
console.log(windDegree)


// Define the wind directions and their corresponding degree ranges
const directions = [
  { name: "N", min: 348.75, max: 360 },
  { name: "N", min: 0, max: 11.25 },
  { name: "NNE", min: 11.25, max: 33.75 },
  { name: "NE", min: 33.75, max: 56.25 },
  { name: "ENE", min: 56.25, max: 78.75 },
  { name: "E", min: 78.75, max: 101.25 },
  { name: "ESE", min: 101.25, max: 123.75 },
  { name: "SE", min: 123.75, max: 146.25 },
  { name: "SSE", min: 146.25, max: 168.75 },
  { name: "S", min: 168.75, max: 191.25 },
  { name: "SSW", min: 191.25, max: 213.75 },
  { name: "SW", min: 213.75, max: 236.25 },
  { name: "WSW", min: 236.25, max: 258.75 },
  { name: "W", min: 258.75, max: 281.25 },
  { name: "WNW", min: 281.25, max: 303.75 },
  { name: "NW", min: 303.75, max: 326.25 },
  { name: "NNW", min: 326.25, max: 348.75 },
];

// Get the wind degrees value from the Homey variable
const windDegrees = windDegree.value ;

// Convert the wind degrees into a wind direction
let windDirection = "";
for (let i = 0; i < directions.length; i++) {
  const direction = directions[i];
  if (windDegrees >= direction.min && windDegrees < direction.max) {
    windDirection = direction.name;
    break;
  }
}

// Set the wind direction value into the Homey tag
await tag('windDirection', windDirection);
console.log(windDirection)

Make a flow when your variable changes, And Homeyscript, run a script. Fill in the name of your script, Then… Whatever you want. The winddirections are in the tag WindDirection and you can use them as you want.

Wow, thank you so much Marcel! :smiley:

I have not dabbled with scripts at all so it’s a little intimidating for me. But since you’ve been so kind to post it I will give it a try…nothing bad can happen and to learn something new you have to give it a go. :+1:

It looks similar to Arduino code and I have been successful in some programming for a few applications (for example a 433 MHz barometer using the Oregon protocol)…however it’s been “monkey see, monkey do” and a ton of trial and error. I never did crack the code so to speak. :joy:

1 Like

I use the following flow