# How to drop msg.payload from specific topics?

**URL:** https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859
**Category:** General
**Created:** [22 June 2024 12:10 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859 "2024-06-22T12:10:18Z")
**Posts on this page:** 9
**Page:** 2

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [23 June 2024 20:05 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/23 "2024-06-23T20:05:32Z")

</div>

What is the expected output ?

If one is found within the array, output true  
if none are found within the array, output false ?

---

<div class="post-metadata">

### Author: ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)
#### Post date: [23 June 2024 20:06 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/24 "2024-06-23T20:06:15Z")

</div>

@bakman2 [How to drop msg.payload from specific topics? - #17 by daxliniere](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/17) 😊

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [23 June 2024 20:24 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/25 "2024-06-23T20:24:59Z")

</div>

You can use a function like:

```auto
const incoming_mac = msg.payload.flat().map(x=>x.mac)

const people = {
    "presence/Phone1": "12:74:67:94:37:36",
    "presence/Phone2": "64:c2:f9:91:2b:36",
    "presence/Phone3": "19:0e:59:18:66:a0",
    "presence/Phone4": "d9:46:07:f8:42:e8",
    "presence/Phone5": "74:6a:18:26:5e:77"
};

const macs = Object.values(people)
const result = macs.filter(x=>incoming_mac.includes(x))

let payload = false

if(result.length){
    payload = true
}

msg.payload = payload

return msg;

```

The incoming payload is expected to be an array of arrays with objects (hence the `flat()`)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [23 June 2024 21:40 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/26 "2024-06-23T21:40:38Z")

</div>

I suspect @bakman2 has solved the whole issue for you but here is a flow you could have used to obfuscate your huge data file. 😃

I think it's not an example of good coding!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cf8ef091e911f7924e408335e13faa6f1189f1a.png)

```auto
[{"id":"327d39389904b661","type":"tab","label":"Flow 7","disabled":false,"info":"","env":[]},{"id":"60e6fbf0b07a73a0","type":"group","z":"327d39389904b661","name":"1. Make a lookup table of obfuscated mac addresses","style":{"label":true},"nodes":["6799e1159c4d4c62","9266251ee4973d25","e7e9415c9c6e452f","fecb0fae6e364199","382c26adbd463e9a"],"x":34,"y":79,"w":592,"h":142},{"id":"9c1d4a86f6d068b8","type":"group","z":"327d39389904b661","name":"Obfuscate fields","style":{"label":true},"nodes":["3ec28c381ffb74b1","2a8751aafdce91bb","10997b967bdc1f32","a97e03ab743e8f18","830e158d3898143c","636c5995cebc573c"],"x":24,"y":239,"w":702,"h":142},{"id":"6799e1159c4d4c62","type":"change","z":"327d39389904b661","g":"60e6fbf0b07a73a0","name":"Mac Address","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.mac","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":180,"wires":[["9266251ee4973d25"]]},{"id":"9266251ee4973d25","type":"function","z":"327d39389904b661","g":"60e6fbf0b07a73a0","name":"Make lookup table","func":"let cnt = flow.get(\"macAddressCount\") || 0\nlet addresses = flow.get (\"macAddresses\") || {}\nfunction pad(num, size) {\n var s = \"00\" + num;\n return s.substr(s.length - size);\n}\nif (msg.payload in addresses){\n //node.warn (msg.payload + \" is in\")\n}\nelse {\n //node.warn (msg.payload + \" added\")\n cnt ++\n addresses[msg.payload] = pad(cnt, 2) + \":xx:xx:xx:xx:xx\"\n flow.set(\"macAddresses\", addresses)\n flow.set (\"macAddressCount\", cnt)\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":180,"wires":[[]]},{"id":"fcd909588aa49513","type":"inject","z":"327d39389904b661","name":"delete flow vars","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":40,"wires":[["748c1e253faceb92"]]},{"id":"748c1e253faceb92","type":"change","z":"327d39389904b661","name":"","rules":[{"t":"delete","p":"macAddresses","pt":"flow"},{"t":"delete","p":"macAddressCount","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":40,"wires":[[]]},{"id":"e7e9415c9c6e452f","type":"split","z":"327d39389904b661","g":"60e6fbf0b07a73a0","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":430,"y":120,"wires":[["fecb0fae6e364199"]]},{"id":"fecb0fae6e364199","type":"split","z":"327d39389904b661","g":"60e6fbf0b07a73a0","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":550,"y":120,"wires":[["6799e1159c4d4c62"]]},{"id":"3ec28c381ffb74b1","type":"split","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":530,"y":280,"wires":[["10997b967bdc1f32"]]},{"id":"2a8751aafdce91bb","type":"split","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":410,"y":280,"wires":[["3ec28c381ffb74b1"]]},{"id":"10997b967bdc1f32","type":"function","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"Obfuscate all fields","func":"const macaddresses = flow.get(\"macAddresses\") || {}\nlet obfuscmac = macaddresses[msg.payload.mac] || \"ee:ee:ee:ee:ee:ee\"\nmsg.payload.mac = obfuscmac\nmsg.payload.site_id = \"yyyyyyyyyyyyyyyyyyy\"\nmsg.payload.user_id = \"yyyyyyyyyyyyyyy\"\nmsg.payload._id = \"yyyyyyyyyyyyyyy\"\nmsg.payload.wlanconf_id = \"yyyyyyyyyyyyyyy\"\nmsg.payload.network_id = \"yyyyyyyyyyyyyyy\"\nmsg.payload.fixed_ip = \"yyyyyyyyyyyyyyy\"\nmsg.payload.ap_mac = \"AP:AP:AP:AP:AP:AP\"\nmsg.payload.bssid = \"BS:BS:BS:BS:BS:BS\"\nmsg.payload.user_group_id_computed = \"yyyyyyyyyyyyyyy\"\nmsg.payload.anon_client_id = \"yyyyyyyyyyyyyyy\"\nmsg.payload.ip = \"yyyyyyyyyyyyyyy\"\nmsg.payload.name = \"namenamename\"\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":340,"wires":[["a97e03ab743e8f18"]]},{"id":"a97e03ab743e8f18","type":"join","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":410,"y":340,"wires":[["830e158d3898143c"]]},{"id":"830e158d3898143c","type":"file","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"","filename":"bigObfuscatedDataFile","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":600,"y":340,"wires":[[]]},{"id":"636c5995cebc573c","type":"link in","z":"327d39389904b661","g":"9c1d4a86f6d068b8","name":"Input your data here","links":[],"x":140,"y":280,"wires":[["2a8751aafdce91bb"]],"l":true},{"id":"382c26adbd463e9a","type":"link in","z":"327d39389904b661","g":"60e6fbf0b07a73a0","name":"Input your data here","links":[],"x":150,"y":120,"wires":[["e7e9415c9c6e452f"]],"l":true}]

```

---

<div class="post-metadata">

### Author: ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)
#### Post date: [4 July 2024 00:25 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/27 "2024-07-04T00:25:36Z")

</div>

@bakman2 Thank you so, so much for this code! I finally managed to get around to adding it today and it seems to be working a charm!

I was proud of myself as I realised I could achieve the desired delay response with a trigger node, which is also reset by receiving a TRUE.  
This means as soon as someone is detected, hot water system is turned on, but after 20 minutes of everyone going out, hot water system and air-con are turned off, UNLESS someone comes back in.

This is the perfect scenario I was hoping for. Next step is to get the Tuya switches to respond, but I think that should be straight-forward now.

---

<div class="post-metadata">

### Author: ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)
#### Post date: [4 July 2024 00:26 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/28 "2024-07-04T00:26:37Z")

</div>

Ahh, very cool, @jbudd.  
Occasionally I have need to sort tables of data and that might be a great way to achieve it! Thanks for your help, too. 🙂

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [4 July 2024 02:58 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/29 "2024-07-04T02:58:21Z")

</div>

Be careful - many phones have the default option of variable mac addresses now - to counter walk by presence detection.

Craig

---

<div class="post-metadata">

### Author: ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)
#### Post date: [5 July 2024 19:45 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/30 "2024-07-05T19:45:13Z")

</div>

Thanks @craigcurtin, yes, I had to disable that on my phone.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [19 July 2024 19:45 UTC](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859/31 "2024-07-19T19:45:59Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/how-to-drop-msg-payload-from-specific-topics/88859.md?page=1)
