I had a go at a function to calculate an adjustment factor based on wind.
It allows for any wind in the northern half of the compass, using the sin function to give increasing weight as the wind approaches North.
It's slightly less scientific and reliable than the back of an envelope...
function windfactor(bearing, speed) {
// Let's use the sin function to allow for how near to 360 the wind direction is.
// sin wave is 0 at 0, max at 90, 0 at 180.
let weighting = 0.01 // Arbitrary weighting to give wind
bearing = (bearing + 90) % 360 // Add 90 degrees to map "northerly" directions (270 - 90) to (0 - 180)
let radians = bearing * Math.PI / 180;
let sine = Math.sin(radians);
if (sine < 0) { // ie wind East through South to West
sine = 0
}
return speed * sine * weighting
}
msg.payload.windFactor = windfactor(msg.payload.winddirection, msg.payload.windspeed)
return msg;
A test flow:
[{"id":"f3e02add17e4b873","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"27b992e4cc367d89","type":"function","z":"f3e02add17e4b873","name":"Simulated OWM data","func":"msg.payload = {\"id\": 800,\"weather\": \"Clear\",\"detail\": \"clear sky\",\"icon\": \"01d\",\"tempk\": 305.43,\"tempc\": 32.2,\"temp_maxc\": 32.2,\"temp_minc\": 32.2,\"humidity\": 43,\"pressure\": 1004,\"maxtemp\": 305.43,\"mintemp\": 305.43,\"windspeed\": 1.34,\"winddirection\": 342,\"location\": \"Port Elizabeth\",\"sunrise\": 1669172530,\"sunset\": 1669223179,\"clouds\": 5,\"description\": \"The weather in Port Elizabeth at coordinates: -33.918, 25.5701 is Clear (clear sky).\"}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":140,"wires":[["e01e7c442df56946"]]},{"id":"535799bb8f1cf187","type":"inject","z":"f3e02add17e4b873","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":140,"wires":[["27b992e4cc367d89"]]},{"id":"16460505b7ec7dd0","type":"debug","z":"f3e02add17e4b873","name":"debug 63","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":140,"wires":[]},{"id":"e01e7c442df56946","type":"function","z":"f3e02add17e4b873","name":"Calculate adjustment for wind","func":"function windfactor(bearing, speed) {\n// Let's use the sin function to allow for how near to 360 the wind direction is. \n// sin wave is 0 at 0, max at 90, 0 at 180.\n let weighting = 0.01 // Arbitrary weighting to give wind\n bearing = (bearing + 90) % 360 // Add 90 degrees to map \"northerly\" directions (270 - 90) to (0 - 180) \n let radians = bearing * Math.PI / 180;\n let sine = Math.sin(radians);\n if (sine < 0) { // ie wind East through South to West\n sine = 0\n }\n return speed * sine * weighting\n}\n\nmsg.payload.windFactor = windfactor(msg.payload.winddirection, msg.payload.windspeed)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":140,"wires":[["16460505b7ec7dd0"]]}]