Min, Max & Avg in single message

Hi All, I am working on a project that involves monitoring and logging analogue data using MCP3008. To save logging every second, I plan to use the calculate node to provide minimum, maximum and average over a 1 minute time period. My testing has been done using a shorter period of 15 seconds so I don't have to wait as long to see the results. What I am trying to achieve is to have a single message output with the Min, max and avg, but not sure quite how to achieve it. I have attached a small test flow but the output is separate messages. Can someone point me in the right direction for joining these into a single message?

[{"id":"381de29c.cc835e","type":"calculate","z":"a57e828d.689cc","name":"Min","pauseType":"timed","calculation":"min","timeout":"15","timeoutUnits":"seconds","rate":"10","x":1560,"y":900,"wires":[["4e1f0f54.aa3c3"]]},{"id":"28743cf1.a2fe54","type":"calculate","z":"a57e828d.689cc","name":"Average","pauseType":"timed","calculation":"average","timeout":"15","timeoutUnits":"seconds","rate":"10","x":1570,"y":940,"wires":[["4e1f0f54.aa3c3"]]},{"id":"477b2cae.de7ac4","type":"calculate","z":"a57e828d.689cc","name":"Max","pauseType":"timed","calculation":"max","timeout":"15","timeoutUnits":"seconds","rate":"10","x":1560,"y":980,"wires":[["4e1f0f54.aa3c3"]]},{"id":"7569850d.d95c9c","type":"calculator","z":"a57e828d.689cc","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"rand","constant":"","round":false,"decimals":0,"x":1300,"y":940,"wires":[["381de29c.cc835e","28743cf1.a2fe54","477b2cae.de7ac4"]]},{"id":"ddab9f6a.2c7d8","type":"inject","z":"a57e828d.689cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1110,"y":940,"wires":[["7569850d.d95c9c"]]},{"id":"4e1f0f54.aa3c3","type":"debug","z":"a57e828d.689cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1910,"y":920,"wires":[]}]

See this article in the cookbook for an example of how to join messages into one object.

Try the amazingly named Join node :wink:

I actually just figured it out earlier today to join incoming MQTT payloads into a single line output for an LCD display.

The Join node was a no brainer, what I had to figure out was the parsing of the relevant data and adding in some descriptive text (function node and some JS) and the timing to get the incoming signals in the correct order (Delay node for one or more of the incoming messages).

Seems others got in before me.

Have a look at this as a gentle nudge.

[{"id":"7691f25c.94cac4","type":"change","z":"8bb4de19.f72c88","name":"","rules":[{"t":"set","p":"average","pt":"msg","to":"average","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3220,"y":4090,"wires":[["52a5c1dd.984578"]]},{"id":"28743cf1.a2fe54","type":"calculate","z":"8bb4de19.f72c88","name":"Average","pauseType":"timed","calculation":"average","timeout":"15","timeoutUnits":"seconds","rate":"10","x":3070,"y":4090,"wires":[["7691f25c.94cac4"]]},{"id":"52a5c1dd.984578","type":"join","z":"8bb4de19.f72c88","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":3450,"y":4090,"wires":[["4e1f0f54.aa3c3"]]},{"id":"7569850d.d95c9c","type":"calculator","z":"8bb4de19.f72c88","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"rand","constant":"","round":false,"decimals":0,"x":2900,"y":4090,"wires":[["381de29c.cc835e","28743cf1.a2fe54","477b2cae.de7ac4"]]},{"id":"4e1f0f54.aa3c3","type":"debug","z":"8bb4de19.f72c88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3450,"y":4140,"wires":[]},{"id":"97692fc9.4db4a8","type":"change","z":"8bb4de19.f72c88","name":"","rules":[{"t":"set","p":"minimum","pt":"msg","to":"minimum","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3230,"y":4050,"wires":[["52a5c1dd.984578"]]},{"id":"24e5cc43.64b24c","type":"change","z":"8bb4de19.f72c88","name":"","rules":[{"t":"set","p":"maximum","pt":"msg","to":"maximum","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3230,"y":4130,"wires":[["52a5c1dd.984578"]]},{"id":"381de29c.cc835e","type":"calculate","z":"8bb4de19.f72c88","name":"Min","pauseType":"timed","calculation":"min","timeout":"15","timeoutUnits":"seconds","rate":"10","x":3060,"y":4050,"wires":[["97692fc9.4db4a8"]]},{"id":"477b2cae.de7ac4","type":"calculate","z":"8bb4de19.f72c88","name":"Max","pauseType":"timed","calculation":"max","timeout":"15","timeoutUnits":"seconds","rate":"10","x":3060,"y":4130,"wires":[["24e5cc43.64b24c"]]},{"id":"ddab9f6a.2c7d8","type":"inject","z":"8bb4de19.f72c88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2910,"y":4000,"wires":[["7569850d.d95c9c"]]}]

Thanks Guys. I tried to use the join node before posting but didn't have it configured correctly. Thanks for the examples it has really helped

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.