This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weather change alert with Node-red
Have the air pressure data shown in the dashboard but would like to implement in addition to showing the Barograph an amber or red warning based on the speed pressure change:
eg AMBER : meaning wind expectancy of bft 6-7
more than 1,3 hPa increase per 1 hr or >4hPa increase in 3 hrs 
or > 1hPa decrease per 1 hr or > 3hPa decrease in 3 hrs 

and RED : meaning wind expectancy of 8-12 bft
> 2hPa increase per hr or > 6hPa increase in 3 hrs
or > 2hPa decrease per 1 hr or > 6hPa decrease in 3 hrs

This seem to be reasonable values for European coast from what I discovered in the web.

Has anyone already implemented something similar in node-red or can advise how to do it

This is what I currently have:

[{"id":"e5c38364.12994","type":"websocket in","z":"f471eda8.b7901","name":"","server":"e4c90bec.5fa188","client":"","x":134.25,"y":39,"wires":[["451e867a.4de5e8"]]},{"id":"2516898a.615516","type":"file","z":"f471eda8.b7901","name":"Chart dump","filename":"/home/pi/.ds-charts/pressure.dump","appendNewline":true,"createDir":true,"overwriteFile":"true","x":756.7500114440918,"y":189.2500057220459,"wires":[]},{"id":"1ac22cae.ef1e53","type":"ui_chart","z":"f471eda8.b7901","name":"","group":"8dd292.ec172d7","order":1,"width":"0","height":"0","label":"Surface Pressure (hPa)","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":"72","removeOlderPoints":"","removeOlderUnit":"3600","cutout":"","colors":["#ffff00","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":654.0000114440918,"y":150.00000381469727,"wires":[["2516898a.615516"],[]]},{"id":"2731bba2.40ab64","type":"function","z":"f471eda8.b7901","name":"Convert to hPa","func":"msg.payload = msg.payload /100 ;\nmsg.payload = msg.payload.toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"x":460.75,"y":151.0000114440918,"wires":[["1ac22cae.ef1e53","301e5b12.5b5234"]]},{"id":"3b896c8.024a794","type":"json","z":"f471eda8.b7901","name":"","x":538.5000190734863,"y":192.2500057220459,"wires":[["1ac22cae.ef1e53"]]},{"id":"710d185d.82de18","type":"file in","z":"f471eda8.b7901","name":"Chart dump pres","filename":"/home/pi/.ds-charts/pressure.dump","format":"utf8","x":393.2500457763672,"y":196.00002479553223,"wires":[["3b896c8.024a794"]]},{"id":"57473e88.b056f","type":"inject","z":"f471eda8.b7901","name":"Startup Pressure","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":209.00000762939453,"y":196.75001335144043,"wires":[["710d185d.82de18"]]},{"id":"12298bf.d0d1974","type":"delay","z":"f471eda8.b7901","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":274.75000762939453,"y":151.25,"wires":[["2731bba2.40ab64"]]},{"id":"a468cc97.41c4d","type":"jsonpath","z":"f471eda8.b7901","expression":"$.updates..values[?(@.path==\"environment.outside.pressure\")]..value","split":true,"name":"environment.outside.pressure","x":295.00000762939453,"y":105.25000381469727,"wires":[["12298bf.d0d1974"]]},{"id":"451e867a.4de5e8","type":"json","z":"f471eda8.b7901","name":"","x":55,"y":105.00000476837158,"wires":[["a468cc97.41c4d","e184c036.78eb4","5bb3cb31.bb1084","d5830fd3.f2b27"]]},{"id":"e4c90bec.5fa188","type":"websocket-listener","z":"","path":"ws://localhost:3000/signalk/v1/stream","wholemsg":"false"},{"id":"8dd292.ec172d7","type":"ui_group","z":"","name":"Pressure","tab":"b2f9c8f1.cf11b8","order":1,"disp":false,"width":"6"},{"id":"b2f9c8f1.cf11b8","type":"ui_tab","z":"","name":"Environment","icon":"dashboard"}]

Thanks for sharing any enhancements!
Hi SkipperEarly,

are u familiar with basic JavaScript, respectively NodeJS? Its just a matter of logging your data and a timestamp to a file or database and writing a small function for the comparison of live and logged data. I don't have the time to write the whole thing for you but I can guide you on your way.

Best Daniel
Thanks Daniel, but am sorry have neither JavaScript nor NodeJS skills, just copy/paste and trying empirical code adaptations. With node-red I seem to have got some modest progress but wouldnt know where to start with setting up a database.

Whats your guestimate is the development effort for simple weatherchange alert ?
Well it's hard to tell because it depends on the persons skills... I have just finished a simplified solution that is working for me but it took me some hours because all of this stuff is not my daily routine and it always takes me some time to get into it.
My test setup is a Wemos D1 mini, which is flashed with ESP Easy. It measures air pressure via a BME280 sensor and forwards the data to a MQTT broker running on my RPi. Node red (also on the RPi) collects the data and writes it to a MySQL database. For the test I've used my own online server but you can run MariaDB or something similar on your pi for an offline version or use a txt-file (but I would prefer a DB). Now select the data from one and three hours ago from the DB and compare them to your live data. To smoothen your data you can use some basic statistical analysis methods like a linear regression. The slope of the regression line tells you how fast the air pressure is changing. You can transform your values e.g. 1,3hPa/h to a certain slope of the line and use the values for alerts as well. Of course this reacts slower to quickly dropping air pressure than the comparison of the raw values. It's just a simple idea for a different approach to analyse your data.
All this can be done in node red but you have to be able to set up a basic database and communicate with it.
Since I've found some time here is a node-red flow in which mqtt data gets logged to a file. Besides that the file can be analysed by the getData node. There are three variables that can be set by you.

min_recording_time = 30 means: You need at least 30 min of pressure data

max_recording_time  = 180 is the maximum amount of minutes that are analysed

trend = 60 prognoses for the upcoming 60 minutes.

If you provide valid data the node returns: the difference in pressure (oldest data point vs last logged data). the linear regression (intercept, slope, etc), the difference in calculated pressure (oldest data point vs current data both calculated by the linear regression) and a trend

My code is quick and dirty!!! You can ask me (specific) questions about it.
[{"id":"a4c1f393.f0b03","type":"file in","z":"b1242926.a388f","name":"test","filename":"c:\\test.csv","format":"utf8","x":243,"y":89,"wires":[["49b3fd20.c5009c"]]},{"id":"aaefae93.fa165","type":"inject","z":"b1242926.a388f","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":110,"y":90,"wires":[["a4c1f393.f0b03"]]},{"id":"cdc04bd8.f5b898","type":"debug","z":"b1242926.a388f","name":"","active":true,"console":"false","complete":"true","x":611,"y":88,"wires":[]},{"id":"49b3fd20.c5009c","type":"function","z":"b1242926.a388f","name":"getData","func":"// in minutes\nvar min_recording_time  = 30;\nvar max_recording_time  = 180;\nvar trend               = 60;\n//--------------------\n\nvar pressure_dif, time_dif;\nvar timestamp =;\nvar pressure = [];\nvar minutes = [];\n\nvar data = msg.payload.split(\"\\n\");\ndata = data.filter(function(e){return e});\ndata.reverse();\n\ndelete msg.payload;\ndelete msg.topic;\n\n\nfor(var i=0;i<data.length;i++){\n    var arr = data[i].split(\";\");\n    arr[0] = Number(arr[0]);\n    arr[2] = parseFloat(arr[2]);\n    var x = timestamp - arr[0];\n    if(x > (max_recording_time*60000)){\n        break;\n    }\n    pressure.push(arr[2]);\n    minutes.push(arr[0]);\n    minutes[i]=(minutes[i]-timestamp)/60000;\n}\nif((minutes.slice(-1)[0]*-1) < min_recording_time || minutes.slice(-1)[0] === undefined){\n    msg.error = \"Error: No valid data available! Please wait for \"+ (min_recording_time + minutes.slice(-1)[0]).toFixed()+\" min.\";\n    return msg;\n}\nvar x = minutes;\nvar y = pressure;\nvar lr = {};\nvar n = y.length;\nvar sum_x = 0;\nvar sum_y = 0;\nvar sum_xy = 0;\nvar sum_xx = 0;\nvar sum_yy = 0;\nfor (var i = 0; i < y.length; i++) {\n\tsum_x += x[i];\n\tsum_y += y[i];\n\tsum_xy += (x[i]*y[i]);\n\tsum_xx += (x[i]*x[i]);\n\tsum_yy += (y[i]*y[i]);\n} \nlr['slope'] = (n * sum_xy - sum_x * sum_y) / (n*sum_xx - sum_x * sum_x);\nlr['intercept'] = (sum_y - lr.slope * sum_x)/n;\nlr['r2'] = Math.pow((n*sum_xy - sum_x*sum_y)/Math.sqrt((n*sum_xx-sum_x*sum_x)*(n*sum_yy-sum_y*sum_y)),2);\nlr['diff'] = lr.intercept - ((lr.slope*minutes.slice(-1)[0])+lr.intercept);\nlr['diff_complete'] = lr['diff'].toFixed(2) + \" hPa / \"+(minutes.slice(-1)[0]*-1).toFixed()+\" min\";\nlr['trend'] = (((lr.slope*trend)+lr.intercept)-lr.intercept).toFixed(2);\npressure_dif = ((pressure[0]*100)-(pressure.slice(-1)[0]*100))/100;\ntime_dif = (minutes[0]-minutes.slice(-1)[0]);\nmsg.pressure_dif = pressure_dif;\nmsg.time_dif = time_dif.toFixed();\ = lr;\n\nreturn msg;","outputs":1,"noerr":0,"x":417,"y":89,"wires":[["cdc04bd8.f5b898"]]},{"id":"325bdac0.8422ce","type":"mqtt in","z":"b1242926.a388f","name":"","topic":"/#","qos":"2","broker":"ac0d0706.7df12","x":109,"y":204,"wires":[["f7808585.15c148"]]},{"id":"39fd5d25.3a174a","type":"file","z":"b1242926.a388f","name":"","filename":"c:\\test.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","x":495,"y":204,"wires":[]},{"id":"f7808585.15c148","type":"function","z":"b1242926.a388f","name":"MQTTtoFile","func":"if(msg.topic == \"/d1mini/bme280/Pressure\"){\n    msg.payload =\";\"+msg.topic+\";\"+msg.payload;\n    return msg;\n}","outputs":1,"noerr":0,"x":294,"y":203,"wires":[["39fd5d25.3a174a"]]},{"id":"ac0d0706.7df12","type":"mqtt-broker","z":"","broker":"","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

Forum Jump:

Users browsing this thread: 1 Guest(s)