Message count to attribute

Hello, amazing Node-Red Forum! I'd like to update a home assistant entity id (wifi access point) with the state being the amount of currently connected devices.

I have a reoccurring Get request that contains messages about all of my wifi clients. In each payload contains an Access Point name. I am capable of filtering the messages down to only those associated to the ap. And updating home assistant once I am able to get a count.

After this filter of the AP, I would like to somehow pause and collect how many messages come through in 5 seconds or so and then use that number as the current number of associated devices of that Access Point.

I want to use the "number of messages that came through" as a state for an entity in hassio.

mayb this node can help?

Thanks, I did find that. It seems to count the messages coming in and I can trigger off of that count and even reset. But What do I do when the count is 0? I'd like to still update homeassistant that the state is zero, but if it is a zero count then that means no messages came through. So possibly if function?

[{"id":"98dc9b7b.23b0f8","type":"http request","z":"1de7eec2.8cc6d1","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"https://10.254.1.19/api/v1/station","tls":"b2a5958c.289118","persist":false,"proxy":"","authType":"basic","x":770,"y":200,"wires":[["16073025.eefe4"]]},{"id":"16073025.eefe4","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Station_result","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":200,"wires":[["e0120d42.392a8"]]},{"id":"571983b4.2dc57c","type":"inject","z":"1de7eec2.8cc6d1","name":"","topic":"","payload":"","payloadType":"str","repeat":"300","crontab":"","once":true,"onceDelay":"15","x":510,"y":220,"wires":[["98dc9b7b.23b0f8","f15f2146.d5476"]]},{"id":"e0120d42.392a8","type":"split","z":"1de7eec2.8cc6d1","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":1130,"y":200,"wires":[["ae45b632.ee8138"]]},{"id":"ae45b632.ee8138","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.msg","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":200,"wires":[["a280d80d.b5fd18"]]},{"id":"963acbb1.4474b8","type":"debug","z":"1de7eec2.8cc6d1","name":"????","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1870,"y":1080,"wires":[]},{"id":"1f3baa4f.6a5bf6","type":"function","z":"1de7eec2.8cc6d1","name":"","func":"var payload=msg.payload;\nmsg.payload = { \n        \"mac_address\": payload.sta_eth_mac.addr,\n        \"role\": payload.role}\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":540,"wires":[["1859216d.f68b1f","27c7f325.fa2cdc","e7ebfff.4ba7b","904b04f1.e417c8","b3272010.14a7","31697add.474ff6","edf7eefe.cd58a","6e6639c9.cfe448","9f18aab2.614908"]]},{"id":"bbfb1266.38732","type":"function","z":"1de7eec2.8cc6d1","name":"changemsgpayload","func":"var payload=msg.payload;\nmsg.topic = msg.payload.ap_name;\nreturn msg;","outputs":1,"noerr":0,"x":1730,"y":220,"wires":[["d670ff37.021a8"]]},{"id":"6ba02d9f.55efc4","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":420,"wires":[["bc75958b.3fb488"]]},{"id":"12ab9186.cee0fe","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":420,"wires":[["6ba02d9f.55efc4"]]},{"id":"bc75958b.3fb488","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":420,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"1859216d.f68b1f","type":"filter","z":"1de7eec2.8cc6d1","name":"Downstairs","property":"topic","filter":"downstairs_c_easo","ignorecase":true,"x":1030,"y":420,"wires":[["12ab9186.cee0fe"]]},{"id":"a280d80d.b5fd18","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"change","p":"payload.ap_name","pt":"msg","from":"DS-AP-555","fromt":"str","to":"downstairs_c_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"BD-AP-335-MP","fromt":"str","to":"back_deck_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"WS-AP-335-MP","fromt":"str","to":"work_shop_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"MB-AP-335-MP","fromt":"str","to":"master_bedroom_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"TS-AP-555-MP","fromt":"str","to":"tech_shop_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"LB-AP-335","fromt":"str","to":"l_bedroom_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"LR-AP-325-Point","fromt":"str","to":"living_room_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"FY-AP-275","fromt":"str","to":"front_yard_easo","tot":"str"},{"t":"change","p":"payload.ap_name","pt":"msg","from":"BP-AP-277","fromt":"str","to":"back_porch_easo","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":200,"wires":[["bbfb1266.38732"]]},{"id":"c0fdfaf4.87bfa8","type":"ha-api","z":"1de7eec2.8cc6d1","name":"","server":"c9987224.12e8f","debugenabled":false,"protocol":"http","method":"post","path":"states/sensor.{{topic}}","data":"{\"state\":\"{{payload}}\",\"entity_id\":\"sensor.{{topic}}\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":2030,"y":880,"wires":[["963acbb1.4474b8"]]},{"id":"d773f16a.46514","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":460,"wires":[["35e1cac5.1330b6","963acbb1.4474b8"]]},{"id":"80b6992e.f07be8","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":460,"wires":[["d773f16a.46514"]]},{"id":"35e1cac5.1330b6","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":460,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"27c7f325.fa2cdc","type":"filter","z":"1de7eec2.8cc6d1","name":"back_deck","property":"topic","filter":"back_deck_easo","ignorecase":true,"x":1030,"y":460,"wires":[["80b6992e.f07be8"]]},{"id":"b83e0354.78295","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":500,"wires":[["111bca93.cadaa5"]]},{"id":"e0481eff.82fa9","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":500,"wires":[["b83e0354.78295"]]},{"id":"111bca93.cadaa5","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":500,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"e7ebfff.4ba7b","type":"filter","z":"1de7eec2.8cc6d1","name":"work_shop","property":"topic","filter":"work_shop_easo","ignorecase":true,"x":1030,"y":500,"wires":[["e0481eff.82fa9"]]},{"id":"384b724f.23c5ae","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":540,"wires":[["e16f0ba1.92e7e8"]]},{"id":"99e4a80.4d9b658","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":540,"wires":[["384b724f.23c5ae"]]},{"id":"e16f0ba1.92e7e8","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":540,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"904b04f1.e417c8","type":"filter","z":"1de7eec2.8cc6d1","name":"master_bedroom","property":"topic","filter":"master_bedroom_easo","ignorecase":true,"x":1010,"y":540,"wires":[["99e4a80.4d9b658"]]},{"id":"79874ee.70ed9b","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":580,"wires":[["2b682767.8de318"]]},{"id":"9facba11.5f5708","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":580,"wires":[["79874ee.70ed9b"]]},{"id":"2b682767.8de318","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":580,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"b3272010.14a7","type":"filter","z":"1de7eec2.8cc6d1","name":"tech_shop","property":"topic","filter":"tech_shop_easo","ignorecase":true,"x":1030,"y":580,"wires":[["9facba11.5f5708"]]},{"id":"3033b551.c9c8aa","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":620,"wires":[["5f1dc4df.6e2b9c"]]},{"id":"48cd07.b7eae2f8","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":620,"wires":[["3033b551.c9c8aa"]]},{"id":"5f1dc4df.6e2b9c","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":620,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"31697add.474ff6","type":"filter","z":"1de7eec2.8cc6d1","name":"l_bedroom","property":"topic","filter":"l_bedroom_easo","ignorecase":true,"x":1030,"y":620,"wires":[["48cd07.b7eae2f8"]]},{"id":"cabb9349.d3796","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":660,"wires":[["d89ffcb0.4b199"]]},{"id":"4a35f364.84985c","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":660,"wires":[["cabb9349.d3796"]]},{"id":"d89ffcb0.4b199","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":660,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"edf7eefe.cd58a","type":"filter","z":"1de7eec2.8cc6d1","name":"living_room","property":"topic","filter":"living_room_easo","ignorecase":true,"x":1030,"y":660,"wires":[["4a35f364.84985c"]]},{"id":"c68331e8.0fef1","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":700,"wires":[["17828099.dd090f"]]},{"id":"9d7bd96c.80ac18","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":700,"wires":[["c68331e8.0fef1"]]},{"id":"17828099.dd090f","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":700,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"6e6639c9.cfe448","type":"filter","z":"1de7eec2.8cc6d1","name":"front_yard","property":"topic","filter":"front_yard_easo","ignorecase":true,"x":1020,"y":700,"wires":[["9d7bd96c.80ac18"]]},{"id":"7d108c0a.6b02d4","type":"join","z":"1de7eec2.8cc6d1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":740,"wires":[["c4be2176.4bd6e"]]},{"id":"2a6d824.9e21a7e","type":"counter","z":"1de7eec2.8cc6d1","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":1200,"y":740,"wires":[["7d108c0a.6b02d4"]]},{"id":"c4be2176.4bd6e","type":"change","z":"1de7eec2.8cc6d1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":740,"wires":[["c0fdfaf4.87bfa8"]]},{"id":"9f18aab2.614908","type":"filter","z":"1de7eec2.8cc6d1","name":"back_porch","property":"topic","filter":"back_porch_easo","ignorecase":true,"x":1030,"y":740,"wires":[["2a6d824.9e21a7e"]]},{"id":"d670ff37.021a8","type":"filter","z":"1de7eec2.8cc6d1","name":"employee","property":"payload.role","filter":"employee","ignorecase":true,"x":1020,"y":340,"wires":[["1f3baa4f.6a5bf6"]]},{"id":"b1439d53.5a929","type":"function","z":"1de7eec2.8cc6d1","name":"changemsgpayload","func":"var payload=msg.payload;\nmsg.topic = \"living_room_easo\";\nmsg.reset = \"0\";\nmsg.count = \"0\";\nmsg.payload = \"0\";\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":960,"wires":[["4a35f364.84985c"]]},{"id":"da61c3dd.8b1cb","type":"function","z":"1de7eec2.8cc6d1","name":"changemsgpayload","func":"var payload=msg.payload;\nmsg.topic = \"back_deck_easo\";\nmsg.reset = \"0\";\nmsg.count = \"0\";\nmsg.payload = \"0\";\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":920,"wires":[["80b6992e.f07be8"]]},{"id":"f15f2146.d5476","type":"delay","z":"1de7eec2.8cc6d1","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":900,"wires":[["da61c3dd.8b1cb","b1439d53.5a929","e625079e.e144c8"]]},{"id":"e625079e.e144c8","type":"function","z":"1de7eec2.8cc6d1","name":"changemsgpayload","func":"var payload=msg.payload;\nmsg.topic = \"master_bedroom_easo\";\nmsg.reset = \"0\";\nmsg.count = \"0\";\nmsg.payload = \"0\";\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":880,"wires":[["99e4a80.4d9b658"]]},{"id":"76308c46.acff34","type":"combine-if","z":"1de7eec2.8cc6d1","topic":"if (msg.payload = \"\"){ msg.payload = \"0\"; } else { msg.payload = \" \"; } return msg.payload;","name":"a","timeout":0,"x":1270,"y":940,"wires":[[],[]]},{"id":"b2a5958c.289118","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false},{"id":"c9987224.12e8f","type":"server","z":"","name":"HASSIO","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I think, I see what you mean. Well, a way could be to have the counter do the counting per topic.You can then do the bookkeeping of the messages per topic in a function node, in context variables per topic.
Set the initial value of every variable to zero and then act accordingly.

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