Even after all 3 inputs have reported? You’ll get NaN before the 3rd but then they are all saved and you shouldn’t see it again.
I know you’d rather have just 1 report every 3s and I can add that if you want. I preferred it the way it is because I refreshed the sensor that needed a higher reporting rate and left the other alone because it reports “responsibly”.
That’s easy enough to add to what I sent you and I can do it as well.
1 or 3 is not really a big deal, they get filtered buy the batch. The only reason it’s an issue is the VD will only take 1 set command per second, so it takes the first which is not the average. I use the batch/switch to filter out the other. No biggie, not like I personally sit here and it (once finish that is lol)
yep. I get 6 debug logs every time I click it and they say (can’t get them all but they all say NaN)
Ah, but it will be after 13s because the first round of reports are stored so every new message IN will generate a new message OUT with the updated average. There is NO reset.
Here’s my simple test flow. Perhaps I oversimplified?
yeah IDK what is wrong between the example that work and the actually one that gives NaN. All I can think of is it not see the deviceId correct so it is not setting the variably. Again coding is not my wheel house so this is just a guess. Your example works fine.
I used to make a living coding but that was almost 11 years ago and JavaScript is new to me so I’m far from an expert. Just one of the reasons I took the easy route with this function.
I see what’s wrong. I fat-fingered one of the deviceId numbers.
Here ya go
if (msg.payload.deviceId == "78") context.set('78',msg.payload.value);
if (msg.payload.deviceId == "2535") context.set('2535',msg.payload.value);
if (msg.payload.deviceId == "2471") context.set('2471',msg.payload.value);
msg.payload.average = ((context.get('78') + context.get('2535') + context.get('2471')) / 3 );
return msg;
I’ve lost a ton of skills by not doing any programming for 11 years (some would say I never had them to lose ) but I’ve always been tenacious and I love to give back to folks like you who contribute SO much.
Ha, I tried this a few months ago and abandoned it because it felt wonky. My approach was to monitor the Hubitat Event Socket for temperature updates to the device I want to average and then pass the msg through the Hubitat nodes for those devices, forcing each to output their value. Then average them.
It worked, but i ended up sticking the the Average Apps in Hubitat.
As I mentioned previously, my function code could/should be a good starting point to do it all in a single node. It’ll take a fair amount of logic additions to git 'er done and I have more pressing things to attend to for the foreseeable future. Maybe someone faster than me with JS code will jump in.