Compare 5 values

Hi everyone,
In my family we use the HA app which can track the amount of steps per day. I can read these values in Node-Red but how can I compare these amounts/values/steps of 5 different entities and send back the highest value/entity to announce a ‘winner’ at the end of the day in Home Assistant?
Thanks for your suggestions!

Save each persons total in a flow variable then have an inject node run at a set time, grab all the flow variables, compare them and announce the winner

Thanks, that workflow I had figured out as well, just don't know how to compare them (what script or node to use)

Hard to say as you give no indication of how you collect the data, and how it is formatted

Here is an example, each value is in msg.steps."persons_name". The change node returns the object/s with the highest value.

[{"id":"f3b9f5bd.7d9d58","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sift(steps, function($v, $k){ $v = $max(steps.*) ? $k})","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3020,"wires":[["4dff0770.25d2c"]]},{"id":"8a069626.50a548","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":3020,"wires":[["ca2b4171.07a988"]]},{"id":"ca2b4171.07a988","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"steps.harry","pt":"msg","to":"4500","tot":"num"},{"t":"set","p":"steps.tom","pt":"msg","to":"6000","tot":"num"},{"t":"set","p":"steps.dick","pt":"msg","to":"6000","tot":"num"},{"t":"set","p":"steps.mary","pt":"msg","to":"7000","tot":"num"},{"t":"set","p":"steps.jill","pt":"msg","to":"4000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3020,"wires":[["f3b9f5bd.7d9d58"]]},{"id":"4dff0770.25d2c","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":2860,"wires":[]}]
2 Likes

Great! This is something I can use!
Much appreciated!

Unfortunately I can't seem to get it to work. It's not showing the one winner as in your example.

[{"id":"8fba0b92.a70058","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sift(\t   steps,\t   function($v, $k){ $v = $max(steps.*) ? $k}\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":320,"wires":[["f72b5595.7e8758"]]},{"id":"2aa421e5.3433de","type":"poll-state","z":"3957733d.0b7e8c","name":"Boris","server":"295f2353.45836c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"minutes","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.boris_steps","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":200,"wires":[["a38aba87.53b188"]]},{"id":"27ff9670.84618a","type":"poll-state","z":"3957733d.0b7e8c","name":"Nova","server":"295f2353.45836c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"minutes","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.iphone_van_nova_steps","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":260,"wires":[["25a737d7.d8e618"]]},{"id":"f82af7b1.4d8a58","type":"poll-state","z":"3957733d.0b7e8c","name":"Reza","server":"295f2353.45836c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"minutes","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.iphone_steps","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":320,"wires":[["5336ac64.740154"]]},{"id":"f223b85b.fb48e8","type":"poll-state","z":"3957733d.0b7e8c","name":"Maaike","server":"295f2353.45836c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"minutes","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.imaai_steps","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":380,"wires":[["77ccfc78.f1aca4"]]},{"id":"c91d6586.5f4138","type":"poll-state","z":"3957733d.0b7e8c","name":"Tobias","server":"295f2353.45836c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"minutes","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.iphone_van_tobias_steps","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":440,"wires":[["7e7fdd9a.a9f9b4"]]},{"id":"a38aba87.53b188","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"steps.boris","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":200,"wires":[["8fba0b92.a70058"]]},{"id":"25a737d7.d8e618","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"steps.nova","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":260,"wires":[["8fba0b92.a70058"]]},{"id":"5336ac64.740154","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"steps.reza","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":320,"wires":[["8fba0b92.a70058"]]},{"id":"77ccfc78.f1aca4","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"steps.maaike","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":380,"wires":[["8fba0b92.a70058"]]},{"id":"7e7fdd9a.a9f9b4","type":"change","z":"3957733d.0b7e8c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"steps.tobias","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":440,"wires":[["8fba0b92.a70058"]]},{"id":"f72b5595.7e8758","type":"debug","z":"3957733d.0b7e8c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":950,"y":320,"wires":[]},{"id":"295f2353.45836c","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Messages do not arrive at the same time, you would need to join them. I also switched the change nodes and every thing to msg.payload.

[{"id":"96f56fca.7adc9","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.tobias","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3480,"wires":[["c397da1d.010228"]]},{"id":"c397da1d.010228","type":"join","z":"8d22ae29.7df6d","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":3360,"wires":[["b931b3bf.e6737"]]},{"id":"4c6078d1.5527b","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":166,"y":3481.666748046875,"wires":[["96f56fca.7adc9"]]},{"id":"b493e5bb.24317","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.nova","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3300,"wires":[["c397da1d.010228"]]},{"id":"4ce40565.071a4c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.reza","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3360,"wires":[["c397da1d.010228"]]},{"id":"b6c02591.79a16","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.maaike","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3420,"wires":[["c397da1d.010228"]]},{"id":"b9772465.f7a3e8","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.boris","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3240,"wires":[["c397da1d.010228"]]},{"id":"b931b3bf.e6737","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sift(\t   payload,\t   function($v, $k){ $v = $max(payload.*) ? $k}\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":3360,"wires":[["2938bce0.08afa4"]]},{"id":"c6cf930.b4572f","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":148,"y":3292.666748046875,"wires":[["b493e5bb.24317"]]},{"id":"a6c8ce73.9164e8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":153,"y":3349.666748046875,"wires":[["4ce40565.071a4c"]]},{"id":"32912587.5f479a","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":3420,"wires":[["b6c02591.79a16"]]},{"id":"195ee8eb.657787","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":3240,"wires":[["b9772465.f7a3e8"]]},{"id":"2938bce0.08afa4","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":3360,"wires":[]}]
1 Like

Brilliant! It works now, but is there also a way to export only the name somehow? :wink:

Sure

[{"id":"78a4b94.ac66f48","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":110,"y":3220,"wires":[["a45896c6.f70a5"]]},{"id":"a45896c6.f70a5","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.boris","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3220,"wires":[["435ab38c.7b340c"]]},{"id":"435ab38c.7b340c","type":"join","z":"8d22ae29.7df6d","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":3340,"wires":[["11917b78.b687ed"]]},{"id":"ef455b30.893398","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.tobias","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3460,"wires":[["435ab38c.7b340c"]]},{"id":"11917b78.b687ed","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$join($keys($sift(\t   payload,\t   function($v, $k){ $v = $max(payload.*) ? $k}\t)), \" and \")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":3340,"wires":[["54b6b276.8a12e4"]]},{"id":"41f1ad2a.8a7c4c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.nova","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3280,"wires":[["435ab38c.7b340c"]]},{"id":"aafede5d.9995e8","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.reza","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3340,"wires":[["435ab38c.7b340c"]]},{"id":"800d01c9.cfc6d","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.maaike","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3400,"wires":[["435ab38c.7b340c"]]},{"id":"bb9449b4.31d73","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":3460,"wires":[["ef455b30.893398"]]},{"id":"54b6b276.8a12e4","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":3340,"wires":[]},{"id":"1334d6f.c38b1a9","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"44","payloadType":"num","x":110,"y":3280,"wires":[["41f1ad2a.8a7c4c"]]},{"id":"33cb997c.df4db6","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":3340,"wires":[["aafede5d.9995e8"]]},{"id":"f815ff79.177ee8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":3400,"wires":[["800d01c9.cfc6d"]]}]

ìt will output name "bill", or if draw the names "bill and ted"

Thanks a lot!