I have a flow that works on an array of Acurite thermo-hygrometer sensors. Everything to utilize these as I need works, but I have not properly implemented the battery low notification. Where I am stuck is in reducing the number of instances of the notifications being sent.
The portion in the "battery notification" region is intended to take the sensor json object and remove the values that change (temperature, humidity, time, etc) and just leave the critical things like unit ID, location, and battery_ok value. If battery_ok is less than 1, it means the battery is below Acurite's threshold and should be serviced soon. Since the individual sensors transmit at ~30 second intervals, I have a deduplicate node to filter out extraneous messages and only email periodically. This works fine if there is a single sensor that has a low battery. However, since I installed the batteries at basically the same time, I imagine that more than one sensor could be low at the same time. If that happened, then the deduplicate node would not trigger as intended. It would see sensor A with a low battery and notify, then sensor B would be detected as also unique and notify. Rinse, repeat and I end up with 2 emails every 30 seconds until I replace at least one sensor's batteries.
So, I'm wondering what my alternative would be to keep this module (not calling out each individual sensor in independent code blocks). The only thing I have come up with is to alter my approach to collect a list of bad sensors and email that list at scheduled times. I would have to check the list to remove sensors that have been fixed but at least I'd only have 1 email per period rather than the current flood.
Here's the snippet in the battery notification section if it helps.
[{"id":"95956d64.1c802","type":"switch","z":"b76701c5.7313f","name":"","property":"payload.battery_ok","propertyType":"msg","rules":[{"t":"lt","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":340,"wires":[["9eee43be.5f0678","b55efabd.41ed8"]]},{"id":"47061126.bf4668","type":"comment","z":"b76701c5.7313f","name":"battery notification","info":"","x":410,"y":260,"wires":[]},{"id":"8682be55.2bce78","type":"debug","z":"b76701c5.7313f","name":"email","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":340,"wires":[]},{"id":"9eee43be.5f0678","type":"debug","z":"b76701c5.7313f","name":"battery<1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":380,"wires":[]},{"id":"47cfdca2.e40a04","type":"function","z":"b76701c5.7313f","name":"create email","func":"let newmsg = {topic: \"Acurite-Tower battery low: (\" + msg.payload.location + \")\" }\nnewmsg.payload = \"Acurite tower battery has dropped below lower threshold. Replace at soonest convenience. \\n\\nLocation = \" + msg.payload.location + \"\\nID = \" + msg.payload.id;\n\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":340,"wires":[["8682be55.2bce78","5d6db6.3652ca4c"]]},{"id":"f6e008da.ac0fc","type":"change","z":"b76701c5.7313f","name":"","rules":[{"t":"delete","p":"payload.time","pt":"msg"},{"t":"delete","p":"payload.tempF","pt":"msg"},{"t":"delete","p":"payload.temperature_C","pt":"msg"},{"t":"delete","p":"payload.humidity","pt":"msg"},{"t":"delete","p":"payload.moisture","pt":"msg"},{"t":"delete","p":"payload.moisture_offset","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":280,"wires":[["95956d64.1c802","8d57caa8.77f6b8"]]},{"id":"5466546f.eb0d74","type":"debug","z":"b76701c5.7313f","name":"unique","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":420,"wires":[]},{"id":"dba2da92.e77c88","type":"debug","z":"b76701c5.7313f","name":"duplicate","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":480,"wires":[]},{"id":"8d57caa8.77f6b8","type":"debug","z":"b76701c5.7313f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":300,"wires":[]},{"id":"b55efabd.41ed8","type":"deduplicate","z":"b76701c5.7313f","name":"Deduplicate","keyproperty":"","expirypolicy":"keep","registryclass":"","noderole":"standalone","expiry":"3600","x":510,"y":340,"wires":[["47cfdca2.e40a04","5466546f.eb0d74"],["dba2da92.e77c88"]],"inputLabels":["Eingang"],"outputLabels":["Einmal","Duplikat"]}]
And this is an example input into the change node:
{"time":"2023-01-04 20:28:47","model":"Acurite-Tower","id":9170,"channel":"C","battery_ok":0,"temperature_C":20.7,"humidity":35,"mic":"CHECKSUM","tempF":69.25999999999999,"moisture":6.299686434605598,"tag":"D","location":"Thermostat","moisture_offset":5.2711662003842745}