Calculate rainfall per 24h

(english below)

Hallo,

ich empfange von einer Wetterstation das Payload (payload.rainfall.total.value) für die aktuelle Regenmenge. Leider besteht keine Möglichkeit, die Regenmenge für einen Tag (24h) zu erfassen und dann an das Dashboard zu übergeben.

Hat jemand einen Idee, wie so ein Flow aussehen müsste? Leider habe ich keine Programmierkentnisse .

Vielen Dank!

PS: bin schon älter … bitte verständlich erklären :slight_smile:

Hello,

I receive from a weather station the payload (payload.rainfall.total.value) for the current rainfall. Unfortunately it is not possible to record the amount of rain for one day (24h) and then transfer it to the dashboard.

Does anyone have an idea how such a flow should look like? Unfortunately I don't have any programming knowledge .

Thanks a lot!

PS: I am older ... please explain :slight_smile:

Do you need the rainfall historically or just for the current day?

To do as a one-off, all you need is to accumulate each incoming value to a global/flow variable then use that in your dashboard.

Of course, that only really works if you want to reset the value at a given point in time (e.g. midnight), you will need a separate flow for that.

If you want a running 24hr total, you will have to keep all of the values that occured in the last 24hrs and recalculate the total on each new entry after dropping the oldest. There are array helpers in JavaScript that will help. I think you can do it with JSONata too.

If, however, you want historic data, you should look at using InfluxDB which is a timeseries database. With that, you can dump your new values into the database and it will automatically calculate the running totals for you.

Also can you clarify what that means as it apparently means different things to @TotallyInformation and myself. Does it mean the total rain that has fallen since the weather station was first switched on?

I'd be happy for the current day, Colin.

No. The weather station only reports the current amount of rain. Starting with the insertion of the battery with Zero. Starts at zero and adds each rain to it. For example the value in the payload is 740 and if it rains 2 litres then it is 742. So I always have only the total value of the rain, but I want to know how much it has rained in the last 24 hours.

In the last 24 hours or since midnight?

Yes, Colin

So you will need to store the value. You can store values using context variables see:

https://nodered.org/docs/writing-functions#storing-data

Try importing this flow and see how you go

[{"id":"9a549ce5.8953","type":"inject","z":"9726fcf.8cbf3","name":"Start of the day","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 00 * * *","once":false,"onceDelay":0.1,"x":170,"y":400,"wires":[["4cdf847.94f0afc"]]},{"id":"4cdf847.94f0afc","type":"change","z":"9726fcf.8cbf3","name":"Get last days rain, and reset dailyrain","rules":[{"t":"set","p":"payload","pt":"msg","to":"dailyrain","tot":"global"},{"t":"set","p":"dailyrain","pt":"global","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":400,"wires":[["1905712c.98e9f7"]]},{"id":"96447045.2e2438","type":"debug","z":"9726fcf.8cbf3","name":"Last Days Rain","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":900,"y":380,"wires":[]},{"id":"6e94878e.cf0e38","type":"debug","z":"9726fcf.8cbf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":200,"wires":[]},{"id":"ccb4cf8b.5dd2c","type":"inject","z":"9726fcf.8cbf3","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["4cf1d5d4.d4a894"]]},{"id":"bc23345e.cd6118","type":"function","z":"9726fcf.8cbf3","name":"","func":"\n//grab previous value from global variable for total rain\npreviousrainfall = global.get(\"totalrainfall\")||0;\n\n//how much rain since the last update\nperiodrainfall = msg.payload - previousrainfall;\n\n//grab previous value from global variable for daily rain\ndailyrainfall = global.get(\"dailyrain\")||0;\n\ndailyrainfall = dailyrainfall + periodrainfall;\n\n//update the global variables.\nglobal.set(\"dailyrain\",dailyrainfall );\nglobal.set(\"totalrainfall\", msg.payload);\n\nmsg.payload = \" Total Rain =\"+msg.payload+\" Period Rain\"+periodrainfall+\" Rain Today\"+dailyrainfall\n\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":240,"wires":[["6e94878e.cf0e38"]]},{"id":"4cf1d5d4.d4a894","type":"function","z":"9726fcf.8cbf3","name":"total rainfall input","func":"\n//mimicing teh total rainfall input\n\npreviousrainfall = global.get(\"previousrainfall\")||0;\nmsg.payload = msg.payload + previousrainfall;\nglobal.set(\"previousrainfall\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":240,"wires":[["bc23345e.cd6118","5721e159.00dc4"]]},{"id":"5721e159.00dc4","type":"debug","z":"9726fcf.8cbf3","name":"\"Total Rainfall input\"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":500,"y":280,"wires":[]},{"id":"a98eaf45.542de","type":"comment","z":"9726fcf.8cbf3","name":"Click input to simulate rain guage total rainfall input","info":"","x":230,"y":180,"wires":[]},{"id":"5d4f1eaa.04b2b8","type":"comment","z":"9726fcf.8cbf3","name":"Click to simulate start of day calculation","info":"","x":210,"y":360,"wires":[]},{"id":"1905712c.98e9f7","type":"function","z":"9726fcf.8cbf3","name":"msg.payload = \"Total rain today is \"+msg.payload","func":"msg.payload = \"Total rain today is \"+msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":900,"y":480,"wires":[["96447045.2e2438"]]}]
1 Like

Which, last 24 hours or since midnight?

Thank you!

With this flow I receive the values of the rain meter:

[{"id":"98c56e21.f629a","type":"rfx-sensor","z":"facd4112.fe1c28","name":"","port":"61217f11.fab2d","topicSource":"single","topic":"RAIN3/0x800C","x":393.0173797607422,"y":238.01042366027832,"wires":[["39b7b0ce.8015b"]]},{"id":"39b7b0ce.8015b","type":"change","z":"facd4112.fe1c28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.rainfall.total.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":636.0173530578613,"y":236.01039028167725,"wires":[["e1441486.f59e78","24e737f9.491348","cfb8bd18.694d"]]},{"id":"61217f11.fab2d","type":"rfxtrx-port","port":"/dev/ttyUSB0"}]

How would I have to integrate that into your flow, that every day at 0.01 o'clock the starting value is taken over and then with rain the value is calculated each time? "("Total Rain is current :"). So start with a value at 0 o'clock and then update again and again with rain until 23:59 o'clock ...
Complicated, I know :wink:

Take a look at the inject and see what it is injecting and then look at the "total rainfall input" function node.
The first two lines mimic a message that is always increasing ( eg your total rainfall)

The best way to learn is for you to have a go and see how far you get.

Theres a great guide for how to work with messages here: https://nodered.org/docs/user-guide/messages

2 Likes

The learning process is not so easy because English is not my native language and I always have to translate everything with difficulty.
I thank you for your help so far!

I'm just experiencing the same problem, as I'm moving my flow from Wunderground to Darksky.

When pulling forecast data for the following 7 days, there is nothing in the Darksky api to indicate the accumulated rainfall over the 24hr period.
I thought I'd found the answer in precipAccumulation but apparently it relates to snow accumulations.

Florian,

With a problem like this it is easiest to break it down into steps and write it out in Pseudo code, then you can code/design each step as you go

  1. Every minute check time
  2. If time = 00:01 - reset global variable - RainValueatStartofDay, get value from Weatherstation for TotalRainfall, store in Global Vairable RainValueatStartofDay
  3. Every other minute - talk to the weather station and get the total rainfall
  4. If TotalRainfall > RainValueatStartofDay, then Subtract RainValueatStartofDay from TotalRainfall present result to user - we have had X amount of rain so far today
  5. At 00:00 Do final calculation for day and Store in file - We have had a total of X amount of Rain today.

Then loop as above

Craig

Obviously once you understand this - you can look at Nodes that are available to do the heavy lifiting for you

The inject node will let you make something happen at a specific time each day, another inject node can repeat and action every x minutes

Then either a function node or a change node would do most of the rest for you

Craig

Hello all helpers.

thank you for your help, but if you can't program at all and the english knowledge is not available due to age, it gets too complicated.

Thank you very much for your help and all the best!

hello ukmoose,

your code works great! The amount of rain is recognized correctly for the last 24h. Super work from you!

In the debug window it looks like this:

2.11.2018, 08:46:38node: fdddfc10.68cde8
RAIN3/0x800C : msg.payload : string[43]
" Total Rain =772.1 Period Rain7 Rain Today7"

Now it would be great if I could get my own "gauge" for each of the values "Total Rain", "Period Rain" and "Rain Today" via the dashboard. How can I separate and output the individual values?

Thanks for your help! I start to understand it and now it's fun again! Despite the age :slight_smile:

2 Likes

The "writing functions" page in the docs https://nodered.org/docs/writing-functions, explains how to have multiple outputs from the function node. So you could send each different value to a different output and on to a dashboard graph node.

1 Like

Thank you!

Looks very complicated the function "writing-functions"!

Can you give me an example for a value? With this I could follow the steps.

That would be very nice!