How to determine total amount of running machines

Hi all,

I am currently working on a project where i am receiving the state of different machines (state 1= machine on, state 2= machine running).
The machines send their state every 10 seconds.
There is roughly 25 machines in total.

I would like to be able to display running vs non-running machines on a guage, this would be a super quick over view of the plant.

I have been unable to figure out how to "add together" running and non running states to calculate the total running vs non running.

Any guidance would be appreciated

Thanks in advance

Store the machine details in a context variable, using the machine name or id as the key.
Then every time a machine reports or every 10 seconds you can search the context var for total number of machines where state equals "machine running".
A JSONata expression in a change node should do this e.g
$count($flowContext("var_name").*[state = "machine running"])

If you want to add up the numbers, use the global variable.
such as:

var temp = flow.get('machineRunning') || 0;
if (machine1.state == 'running'){
    temp ++;
    flow.set('machineRunning', temp); 
}
else if (machine1.state == 'on'){
    //do something you need
}

Hi, I have a slightly different proposal using the m-queue node.

output_collecting_state_01

Fairly simple and if you trigger peek (can be done periodically) you get an array at the end that has all states in one object.

[{"id":"720f7dd99f962075","type":"m-queue","z":"f0296260535ccbc8","name":"","queueSelect":"topic","controlFlag":"control","defaultQueue":"default","allQueues":"all","triggerCmd":"trigger","statusCmd":"status","pauseCmd":"pause","resumeCmd":"resume","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","maximumCmd":"maximum","newestCmd":"newest","protectCmd":"protect","deleteCmd":"delete","paused":false,"protect":false,"keepNewestDefault":true,"maxSizeDefault":"1","protectDefault":false,"persist":false,"newValue":"value","storeName":"memoryOnly","statusOutput":true,"outputs":2,"x":920,"y":140,"wires":[["027d529eda18e2a0"],["d7772691142da56a"]]},{"id":"d7772691142da56a","type":"debug","z":"f0296260535ccbc8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":240,"wires":[]},{"id":"6cfb2d6280d7881e","type":"inject","z":"f0296260535ccbc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"control","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"all","payload":"reset","payloadType":"str","x":750,"y":360,"wires":[["720f7dd99f962075"]]},{"id":"027d529eda18e2a0","type":"join","z":"f0296260535ccbc8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1090,"y":140,"wires":[["91e550e29b099f9b"]]},{"id":"2d222a55e9dcd068","type":"inject","z":"f0296260535ccbc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"machine1","payload":"1","payloadType":"num","x":630,"y":120,"wires":[["c75a6353e5e8d105"]]},{"id":"2255342a5bd95ecc","type":"inject","z":"f0296260535ccbc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"machine2","payload":"2","payloadType":"num","x":630,"y":180,"wires":[["c75a6353e5e8d105"]]},{"id":"e8c75a221e5f6175","type":"inject","z":"f0296260535ccbc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"machine3","payload":"2","payloadType":"num","x":630,"y":240,"wires":[["c75a6353e5e8d105"]]},{"id":"91e550e29b099f9b","type":"debug","z":"f0296260535ccbc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":140,"wires":[]},{"id":"edcf661ebe964dc1","type":"inject","z":"f0296260535ccbc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"control","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"all","payload":"peek","payloadType":"str","x":750,"y":320,"wires":[["720f7dd99f962075"]]},{"id":"49ca7fa8bc88eb96","type":"comment","z":"f0296260535ccbc8","name":"https://discourse.nodered.org/t/how-to-determine-total-amount-of-running-machines/78330","info":"https://discourse.nodered.org/t/how-to-determine-total-amount-of-running-machines/78330","x":1000,"y":60,"wires":[]},{"id":"c75a6353e5e8d105","type":"junction","z":"f0296260535ccbc8","x":800,"y":140,"wires":[["720f7dd99f962075"]]}]

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