And as you turn it, is it giving expected results?
Well, not sure what is expected,
But the value changes, yes.
Seems lie a real pain in the @ss for some sensor data that you can just import from a local weather api. Sure, you won’t get precise wind speed and rain measurement for your front yard but, it’s pretty accurate where I am. Plenty accurate to skip this headache. Just saying. Easier to buy a gallon of milk than it is to buy the cow and milk it.
From the esp log output.
I used my phone compass to point the vane to a known heading, eg N, then read the value printed by X axis.
Yea but I have this weather station, got it free, might aswell use it.
For a start, the Cardinal direction will only update every 10s, maybe increase to 1s for testing.
Next, the first if has an or operator ||, the rest have an and operator &&. I am having trouble getting my head around that.
yes I did change to 1s for instant updates
Looking again at
N - start: 318.10000 finish 2700.00000
NE - start: 7200.10000 finish 3320.00000
E - start: 3320.10000 finish 1600.00000
SE - start: 1600.10000 finish -815.00000
S - start: -815.10000 finish -2530.00000
SW - start: 2530.1000 finish -3330.00000
W - start: 3330.10000 finish -2140.00000
NW - start -2140.10000 finish 318.00000
Doesn’t make much sense. EG SW finishes at -3330, but W starts at 3330. Same with the S/SW transition. N/NE transition 2700 vs 7200.
Maybe some kind of decilination or offset?
There could even be a way to calibrate this think IDK.
Could we somehow offset it in code?
This is the magnetometer
So your observation definitely shows a jump from -3330 to +3330 when you go from SW to W?
Yes, here is a test done with everything facing N, and slowly turning the vane 360 degrees.
That is inconsistent with N being between 318 and 2700. Your first 2 readings are 78 snd 94.
Heres another with the weather station rotated. Not sure what is the front.
Both of those create a basically sinusoidal graph.
First one
Second
So your table above, and therefore the logic in your code, is faulty.
Further, a lot of your logic is just wrong. Consider
if (id(x).state >= 7200.10000 && id(x).state < 3320.00000)
How can something be greater than 7200 and less than 3200. This will never be true.
if (id(x).state >= 3320.10000 && id(x).state < 1600.00000)
Same here, something cannot be bigger than 3320 and less than 1600. This will never be true.
Negative numbers can fool you too, viz:
if (id(x).state >= -815.10000 && id(x).state < -2530.00000)
If something is greater than -815 (ie -814 and upwards) it cannot also be less than -2530 (ie -2531 and below. This will never be true.
Thanks for the help! I ended up going with this code and special shout out and thanks to @FredTheFrog for all the help getting everything with this weather station nailed down in a PM.
It took a while but I certainly could not have gotten the wind direction working without his help!
####Wind Direction Start####
- platform: mlx90393
address: 0x0c
id: mlx
x_axis:
name: "mlx_x"
id: "mlx_x"
y_axis:
name: "mlx_y"
id: "mlx_y"
z_axis:
name: "mlx_z"
update_interval: 60s
- platform: template
id: 'wind_direction'
name: 'Wind Direction'
update_interval: 2s
lambda: |-
float w1 = id(mlx_x).state; // magnetometer X
float w0 = id(mlx_y).state; // magnetometer Y
float w = atan2(w0, w1); // arctangent2 = radians
w = (w * 180) / M_PI; // radians to degrees
w += 19.50; // magnetic declination
w += 68.00; // seems to be off by 90
if ( w < 0 ) w += 360.0; // adjust for negatives
return w;
####END Wind Direction####