Noble Bluetooth Presence detector one message on value change


Hey guys,

i'm fairly new to node-red and currently trying to make a flow that detects if a person comes home and then doing something once (open door, turn lights on or something else) but i can't figure out how i make the msg a one time message.

for scanning i use the noble ( Scan BLE) node and then a function block which contains

var msg1 = {};
if(msg.payload.peripheralUuid == "UUID HERE OF DEVICE") {
    msg1.payload = 50;
    return msg1;
else {
    msg1.payload = 25;
    return msg1;

but now i cant figure out how i only get one message when the scanble is finding the device when it previously didnt find it.

i tried to use the rbe node for the payload to check if it changes but i dont rly understand how the node is working internally.




You can keep track of found devices. Use a context/flow/global variable like an array. When a device is found, add it, whennot found, delete. Then you check each found device against the content of the array each time you scan



If you put an RBE after your function node then it should only pass on a message each time it changes from 25 to 30 or back.



thanks for the heads up

i tried the RBE after the function already but the output is toggling between 25 and 30 and back cause of the other device in range. this means that i will get a change in the value every x seconds

for reference here is the flow i currently have

[{"id":"19261bbb.65589c","type":"scan ble","z":"b0a161cd.a1e4d8","uuids":"","duplicates":true,"name":"","x":230,"y":620,"wires":[["dfc8a604.e7b45","3bf25956.b64556","6c7eae88.4341"]]},{"id":"6c7eae88.4341","type":"function","z":"b0a161cd.a1e4d8","name":"abfrage","func":"var msg1 = {};\nvar msg2 = {};\nif(msg.payload.peripheralUuid == \"ID\") {\n    msg1.payload = 50;\n    return msg1;\n}\nelse {\n    msg1.payload = 25;\n    return msg1;\n}\n","outputs":2,"noerr":0,"x":540,"y":620,"wires":[["583f16af.ad9b98","d63c1e5f.4b5e1"],[]]},{"id":"583f16af.ad9b98","type":"rbe","z":"b0a161cd.a1e4d8","name":"","func":"deadband","gap":"40","start":"","inout":"out","property":"payload","x":790,"y":540,"wires":[["e5731a5f.9246"]]},{"id":"e5731a5f.9246","type":"debug","z":"b0a161cd.a1e4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1050,"y":420,"wires":[]},{"id":"d63c1e5f.4b5e1","type":"debug","z":"b0a161cd.a1e4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":930,"y":660,"wires":[]}]

my goal is that a payload / variable is changing only when the device is registred or not registred anymore.



Of course, follow my advice and it will work that way. The weekend is coming up, you have plenty of time to digg into javascripting :wink:



finally tried some more things and got it working like i wanted it. thanks for pointing me in the right direction