[Node-RED] BLE Presence Detection flow

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

[Node-RED] BLE Presence Detection flow

Post by emme »

Ciao,

Here is my brand new flow for detecting BLE presence and apply changes to domoticz server.

REQUIREMENTS
  • NodeRed
  • node-red-contrib-bleacon installed via palette management
  • MQTT server installed
  • MQTT Hardware installed in Domoticz (and setted to receive domoticz/in)
  • Domoticz server (of course ;) )
HOW FLOW LOOKS LIKE
Cattura-4.jpg
Cattura-4.jpg (87.92 KiB) Viewed 3522 times
node Seek and set HOME is the current backup configuration, it will not appear in the final release :P :P

HOW FLOW WORKS
On NodeRed startup the inject Config will create the needed context variables and config (you don't need to press it for now).
You will need to edit the Initial Config node to include the correct configuration of your BLE devices (see CONFIG section). After each change you will need to deploy the flow to commit the changes

From this point on the flow is completely automated:
The inject Impulse will send a signal every 45 seconds (you can edit the node and set) that scan Toggle convert to a true/false toggle (nomen omen). This is used to start and stop the BLE Scan.

BLE Scan will discover EVERY BLE device in range and will send a message for each device detected (with no duplicates) and pass it to the new_MqttSetHome node. It will look for the device mac address and if it match with the configuration it will prepare the MQTT telegram to be sent to domoticz

When scan Toggle send False the BLE Scan sto scanning and new_MqttSetAway check the configuration and look for those devices that have not been found during the last scan.
If so, it will send the OFF telegrams to Domoticz via MQTT

That's all...

CONFIG
Initial Config needs to be edited with the array of BLE you want to seek for and you have to follow this structure:

Code: Select all

var deviceConfig = [
        ["BLE Mac Address", "DeviceNameWithNoSpaces",  Domoticz Switch IDX, Domoticz Switch Update, Domoticz Variable IDX, Domoticz Variable Update, Domoticz Variable Update with RSSI]
    ];
example:

Code: Select all

var deviceConfig = [
        ["001122334455", "nut1Device",  10, true, 0, false, false],
        ["AABBCCDDEE", "nut2Device",  11, true, 1, true, true],
        ["AABBCCDDEE", "nut3Device",  11, false, 2, true, false]
    ];
With this configuration we can say that:
nut1Device: switch ON/OFF device 10, no variable working
nut2Device: switch ON/OFF device 11, update variable 1 with RSSI value (when found it will have RSSI value, when not it will show AWAY)
nut2Device: no switch operation (idx is useless at this point), update variable 2 only with HOME/AWAY value (note last parameter is false)

This is it!
I'm now finalizing few things and clean up the code... then I will update this topic with the flow to paste to nodeRed
Hope you will enjoy it and willing to ear your opinion about :P
ciao
M

P.S.
of course this can be applied to any BLE device, not only related to personal presence...
ie: check if a ble smartTV is on... a BLE tag on the car key in in the house... and stuff like that...
The most dangerous phrase in any language is:
"We always done this way"
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Node-RED] BLE Presence Detection flow

Post by emme »

after few fine tunes the flow is completely defined...

I publish it on node-red repository at the following address:
https://flows.nodered.org/flow/7343f804 ... 221e9ed3b9

ciao
M
The most dangerous phrase in any language is:
"We always done this way"
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: [Node-RED] BLE Presence Detection flow

Post by D'rMorris »

Cool! I will add this to my setup for testing :-)! Which BLE tokens do you use?
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Node-RED] BLE Presence Detection flow

Post by emme »

nutMini and Tile
works like a charm...
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest