# Noble Bluetooth Presence detector one message on value change

**URL:** <https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271>\
**Category:** General\
**Created:** [22 February 2019 12:05 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271 "2019-02-22T12:05:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsdasd](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@tsdasd](https://discourse.nodered.org/u/tsdasd)\
**Post date:** [22 February 2019 12:05 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/1 "2019-02-22T12:05:43Z")

</div>

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

```auto
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.

greetings

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 February 2019 12:17 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/2 "2019-02-22T12:17:53Z")

</div>

> [@tsdasd](#):
>
> now i cant figure out how i only get one message when the scanble is finding the device when it previously didnt find it

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 February 2019 12:18 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/3 "2019-02-22T12:18:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tsdasd](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@tsdasd](https://discourse.nodered.org/u/tsdasd)\
**Post date:** [22 February 2019 12:28 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/4 "2019-02-22T12:28:05Z")

</div>

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

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 February 2019 12:39 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/5 "2019-02-22T12:39:08Z")

</div>

> [@tsdasd](#):
>
> 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 😉

---

<div class="post-metadata">

**Author:** ![tsdasd](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@tsdasd](https://discourse.nodered.org/u/tsdasd)\
**Post date:** [1 March 2019 08:59 UTC](https://discourse.nodered.org/t/noble-bluetooth-presence-detector-one-message-on-value-change/8271/6 "2019-03-01T08:59:29Z")

</div>

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