What is the expected output ?
If one is found within the array, output true
if none are found within the array, output false ?
What is the expected output ?
If one is found within the array, output true
if none are found within the array, output false ?
You can use a function like:
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()
)
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!
[{"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}]
@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.
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.
Be careful - many phones have the default option of variable mac addresses now - to counter walk by presence detection.
Craig
Thanks @craigcurtin, yes, I had to disable that on my phone.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.