<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Presence_detection_%28Bluetooth_4.0_Low_energy_Beacon%29</id>
	<title>Presence detection (Bluetooth 4.0 Low energy Beacon) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Presence_detection_%28Bluetooth_4.0_Low_energy_Beacon%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)&amp;action=history"/>
	<updated>2026-09-18T20:45:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.domoticz.com/index.php?title=Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)&amp;diff=11707&amp;oldid=prev</id>
		<title>Xpavli44: /* Beacon */</title>
		<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Presence_detection_(Bluetooth_4.0_Low_energy_Beacon)&amp;diff=11707&amp;oldid=prev"/>
		<updated>2019-02-02T12:03:03Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Beacon&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[File:Nut_mini_beacon.jpg]] [[File:Nut_beacon.jpg]] &amp;lt;br&amp;gt;&lt;br /&gt;
=Purpose=&lt;br /&gt;
Check the presence of a list of beacons (BlueTooth Low Energy V4.0) and update uservariables in Domoticz accordingly.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Required in Domoticz, a uservariable of type String for each BLE Tag&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Beacon_uservariable.jpg]]&lt;br /&gt;
&lt;br /&gt;
Script operates in 2 mode. Choose for each beacon which one you want :&amp;lt;br&amp;gt;&lt;br /&gt;
- REPEAT MODE : For beacon in range, update the uservariable every 3 seconds with the RSSI (strength Signal). And &amp;quot;AWAY&amp;quot; otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
- SWITCH_MODE : For beacon in range, update only 1 time the uservariable with &amp;quot;HOME&amp;quot;. And &amp;quot;AWAY&amp;quot; otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
The detection is very fast : around 4 seconds. And the absence is verified every 5 seconds by comparing the hour of the last presence with a time out for each beacon.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is it For=&lt;br /&gt;
You can use this to see if a person (who always carries his/her beacon) is at home or not, and trigger events based on this.&amp;lt;br&amp;gt;&lt;br /&gt;
I plan to equip all the family keys with beacon and automatically arm/disarm my Domoticz alarm system by checking the presence of a beacon. Domoticz will trigger the alarm on when the last beacon leaves the home.&lt;br /&gt;
&lt;br /&gt;
=Hardware &amp;amp; Beacon=&lt;br /&gt;
&lt;br /&gt;
This Howto is made for RaspberryPi&lt;br /&gt;
&lt;br /&gt;
===BLE Adapter===&lt;br /&gt;
You will need a Bluetooth 4.0 compatible USB adapter to use with the Pi. The following devices have been tested:&amp;lt;br&amp;gt;&lt;br /&gt;
- I have this one : http://www.amazon.fr/SODIAL-Adaptateur-Bluetooth-Dongle-Ordinateur/dp/B00L317IL4/277-2648083-3402713?ie=UTF8&amp;amp;redirect=true&amp;amp;ref_=pe_386181_37038081_TE_3p_dp_1&amp;lt;br&amp;gt;&lt;br /&gt;
- https://www.amazon.co.uk/gp/product/B00XTU53A0/ref=oh_aui_detailpage_o09_s00?ie=UTF8&amp;amp;psc=1&amp;lt;br&amp;gt;&lt;br /&gt;
- Plugable USB-BT4LE adapter: http://plugable.com/products/usb-bt4le (uses BCM20702 chipset)&amp;lt;br&amp;gt;&lt;br /&gt;
- CSR chipset adapter http://www.amazon.co.uk/Version-Bluetooth-Adapter-Compatible-Windows/dp/B00A0CBOTE&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Beacon===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;This beacon works fine :&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
You may find them for around 5€&amp;lt;br&amp;gt;&lt;br /&gt;
- lowest price: https://www.gearbest.com/home-gadgets/pp_123380.html?wid=21&amp;amp;lkid=13488564&amp;lt;br&amp;gt;&lt;br /&gt;
- https://www.aliexpress.com/item/Mini-Smart-Tag-GPS-Tracker-Nut-3-Bluetooth-Anti-lost-Alarm-Key-Finder-Locator/32789403043.html&amp;lt;br&amp;gt;&lt;br /&gt;
- https://www.aliexpress.com/item/mini-Smart-Tracker-Nut3-Bluetooth-GPS-Smart-Finder-Anti-lost-Alarm-Lost-Reminder-Tag-Itag-Key/32947701257.html?spm=2114.search0104.3.1.1f6551e3fd5PlC&amp;amp;ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_319_317_10696_10084_453_10083_454_10618_10304_10307_10820_10821_537_10302_536_10902_10059_10884_10887_321_322_10103,searchweb201603_51,ppcSwitch_0&amp;amp;algo_expid=4a4e1e22-32a2-4575-af8f-7e4234648e0d-0&amp;amp;algo_pvid=4a4e1e22-32a2-4575-af8f-7e4234648e0d&amp;amp;transAbTest=ae803_4&amp;lt;br&amp;gt;&lt;br /&gt;
- http://www.aliexpress.com/item/2015-Nut-2-Smart-Tag-Bluetooth-Tracker-Child-Pet-Key-Finder-Locator-Alarm-for-iphone-Android/32477066584.html &amp;lt;br&amp;gt;&lt;br /&gt;
- http://eu.banggood.com/Wholesale-Warehouse-Mini-Smart-Patch-Alarm-Tag-Bluetooth-GPS-Tracker-Locator-For-iPhone-Android-etc-wp-Uk-988462.html&amp;lt;br&amp;gt;&lt;br /&gt;
Presence is detected in 4 to 8 seconds. (Thus on the contrary, the absence may be decided in less than 15 seconds when the tracker goes out of range...). The SODIAL BLE adapter detects it to a distance of 12m (in direct view) or upstairs across 2 floors.&amp;lt;br&amp;gt;&lt;br /&gt;
- https://www.aliexpress.com/item/Bluetooth-4-0-Anti-lost-Alarm-Key-Chain-Locator-Child-Bag-Wallet-Smart-Tracker-Finder-for/32417849350.html&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- http://www.banggood.com/Mini-Smart-Patch-Alarm-Tag-Bluetooth-GPS-Tracker-Locator-For-iPhone-Android-etc-p-988462.html&amp;lt;br&amp;gt;&lt;br /&gt;
- https://www.amazon.co.uk/gp/product/B014P9VK5K/ref=oh_aui_detailpage_o01_s00?ie=UTF8&amp;amp;psc=1&amp;lt;br&amp;gt;&lt;br /&gt;
- Xiaomi Mi Band (make it discoverable via the Mi app, then it can be found)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Doesn&amp;#039;t Work yet&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
I haven&amp;#039;t succeeded yet in using it. It stops emitting when it is disconnected from its Phone apps.&amp;lt;br&amp;gt;&lt;br /&gt;
- http://www.banggood.com/Sfd-p-985626.html . &amp;lt;br&amp;gt;&lt;br /&gt;
- http://www.banggood.com/Bluetooth-4_0-Self-Portrait-Remote-Control-Anti-Lost-Electronic-Finder-p-974320.html &amp;lt;br&amp;gt;&lt;br /&gt;
- http://www.banggood.com/Wifi-Smart-Bluetooth-4_0-Tracker-GPS-Locator-Tag-Alarm-Anti-lost-Device-GPS-Track-for-iPhone-Android-p-1028944.html&lt;br /&gt;
- TI SensorTag&lt;br /&gt;
&lt;br /&gt;
=Installation instructions=&lt;br /&gt;
&lt;br /&gt;
The script is hosted here : https://github.com/jmleglise/mylittle-domoticz/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Plug your BLE adapter.&lt;br /&gt;
&lt;br /&gt;
==Bluez - the linux bluetooth stack==&lt;br /&gt;
(for synology, check here : http://www.jadahl.com/synology6/?arch=x86)&lt;br /&gt;
&lt;br /&gt;
Bluez requires a 3.5+ kernel&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First install Dependencies that the bluez library uses.  &lt;br /&gt;
    sudo apt-get update&lt;br /&gt;
    sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev&lt;br /&gt;
&lt;br /&gt;
And BLE need a &amp;gt;5.3 bluez stack version.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the version available with apt-get&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Beacon_bluez_install.jpg]]&lt;br /&gt;
&lt;br /&gt;
When the version will be higher , you could do a simple : sudo apt-get install bluez &amp;lt;br&amp;gt;&lt;br /&gt;
But now, the available version is under 5.3, then you must compile from the source.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the last version here : http://www.kernel.org/pub/linux/bluetooth/ (and change the filename below accordingly. Mine was 5.9 ). The compilation take around 20 minutes and at the end, you will need to reboot.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 sudo mkdir bluez ; cd bluez ; sudo wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.9.tar.xz&lt;br /&gt;
 sudo tar -xJf bluez-5.9.tar.xz ; cd bluez-5.9 ; sudo ./configure --disable-systemd ; sudo make ; sudo make install ; sudo apt-get install python-bluez python-requests&lt;br /&gt;
 sudo cp attrib/gatttool /usr/local/bin/&lt;br /&gt;
 sudo shutdown -r now&lt;br /&gt;
TODO check the right of gatttool. (set execution right chmod +x ?) &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===First Test===&lt;br /&gt;
To ensure the USB Bluetooth device is being seen, run&amp;lt;br&amp;gt;&lt;br /&gt;
 lsusb &lt;br /&gt;
&lt;br /&gt;
With the Pluggable adapter shown above, the result will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.&lt;br /&gt;
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub&lt;br /&gt;
 Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.&lt;br /&gt;
 Bus 001 Device 004: ID 04d8:f55e Microchip Technology, Inc.&lt;br /&gt;
 Bus 001 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;Bus 001 Device 006: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For me, the adapter is the one on Bus 001 Device 006, close by my audio card, RFXCOM, USB relay card ... To show more information about it, do:&amp;lt;br&amp;gt;&lt;br /&gt;
 sudo lsusb -v -d 0a12:&lt;br /&gt;
&lt;br /&gt;
If this is working, run the hciconfig tool:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pi@raspberrypi ~ $ hciconfig&lt;br /&gt;
 hci0:	Type: BR/EDR  Bus: USB&lt;br /&gt;
 	BD Address: 00:02:72:14:27:0E  ACL MTU: 1021:8  SCO MTU: 64:1&lt;br /&gt;
 	DOWN &lt;br /&gt;
 	RX bytes:2715 acl:1 sco:0 events:146 errors:0&lt;br /&gt;
 	TX bytes:2500 acl:0 sco:0 commands:133 errors:0&lt;br /&gt;
&lt;br /&gt;
 !!!  The python script will work only if your adapter is on hci0:  If not, you will have to adapt the script !!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get this test script : &lt;br /&gt;
 wget https://raw.githubusercontent.com/jmleglise/mylittle-domoticz/master/Presence-detection-beacon/test_beacon.py&lt;br /&gt;
&lt;br /&gt;
 sudo python test_beacon.py&lt;br /&gt;
&lt;br /&gt;
It shall activate the hci0 port, and detect all beacons around. It&amp;#039;s important to note the MAC Address and the frequency with which the beacon emits, in order to understand what happened next&lt;br /&gt;
&lt;br /&gt;
==Install Script ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo wget https://raw.githubusercontent.com/jmleglise/mylittle-domoticz/master/Presence-detection-beacon/check_beacon_presence.py&lt;br /&gt;
sudo mv check_beacon_presence.py /usr/local/bin/&lt;br /&gt;
sudo chmod 755 /usr/local/bin/check_beacon_presence.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Edit the script==&lt;br /&gt;
(Read the comment in the script)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Log&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
- For manual launch and testing, display Log to console with debug verbose&amp;lt;br&amp;gt;&lt;br /&gt;
 logLevel=logging.DEBUG&lt;br /&gt;
 #logLevel=logging.CRITICAL&lt;br /&gt;
 #logOutFilename=&amp;#039;/var/log/check_beacon_presence.log&amp;#039;&lt;br /&gt;
&lt;br /&gt;
- For production : log in file, only critical&amp;lt;br&amp;gt;&lt;br /&gt;
 #logLevel=logging.DEBUG&lt;br /&gt;
 logLevel=logging.CRITICAL&lt;br /&gt;
 logOutFilename=&amp;#039;/var/log/check_beacon_presence.log&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Beacon Data&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Configure your Beacons in the TAG_DATA table with : [Name,MacAddress,Timeout,0,idx,mode]&amp;lt;br&amp;gt;&lt;br /&gt;
- Name : the strictly exact name of the uservariable used in Domoticz. Case sensitive !&amp;lt;br&amp;gt;&lt;br /&gt;
- macAddress : of the beacon. Case insensitive&amp;lt;br&amp;gt;&lt;br /&gt;
- Timeout is in seconds the elapsed time  without a detection for switching the beacon AWAY. Ie :if your beacon emits every 3 to 8 seconds usually, a timeout of 15 seconds seems good.&amp;lt;br&amp;gt;&lt;br /&gt;
- 0 : used by the script (will keep the time of the last broadcast) &amp;lt;br&amp;gt;&lt;br /&gt;
- idx of the uservariable in Domoticz for this beacon&amp;lt;br&amp;gt;&lt;br /&gt;
mode : SWITCH_MODE = One update per status change / REPEAT_MODE = continuous updating the RSSI every 3 seconds&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 TAG_DATA = [  &lt;br /&gt;
             [&amp;quot;Tag_Orange&amp;quot;,&amp;quot;Fb:14:78:38:18:5e&amp;quot;,15,0,6,REPEAT_MODE],&lt;br /&gt;
             [&amp;quot;Tag_Green&amp;quot;,&amp;quot;ff:ff:60:00:22:ae&amp;quot;,15,0,7,REPEAT_MODE]&lt;br /&gt;
            ]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Domoticz :&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Change your IP and Port here : &amp;lt;br&amp;gt;&lt;br /&gt;
For the most common case, you use your localhost&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 URL_DOMOTICZ = &amp;#039;http://localhost:8080/json.htm?type=command&amp;amp;param=updateuservariable&amp;amp;idx=PARAM_IDX&amp;amp;vname=PARAM_NAME&amp;amp;vtype=2&amp;amp;vvalue=PARAM_CMD&amp;#039;&lt;br /&gt;
 DOMOTICZ_USER=&amp;#039;&amp;#039;&lt;br /&gt;
 DOMOTICZ_PASS=&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or for those who have strengthened their installation with SSL, certificate, password ...&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 URL_DOMOTICZ = &amp;#039;https://domain.com:XXXX/json.htm?type=command&amp;amp;param=updateuservariable&amp;amp;idx=PARAM_IDX&amp;amp;vname=PARAM_NAME&amp;amp;vtype=2&amp;amp;vvalue=PARAM_CMD&amp;#039;&lt;br /&gt;
 DOMOTICZ_USER=&amp;#039;xxxxxxx&amp;#039;&lt;br /&gt;
 DOMOTICZ_PASS=&amp;#039;xxxxxxx&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
===Second Test : Run the script manually===&lt;br /&gt;
&lt;br /&gt;
 sudo python /usr/local/bin/check_beacon_presence.py&lt;br /&gt;
&lt;br /&gt;
The output will be displayed on screen , or in log file according to the parameter in the script:&amp;lt;br&amp;gt;&lt;br /&gt;
Display the log file with : &amp;lt;br&amp;gt;&lt;br /&gt;
 sudo more /var/log/check_beacon_presence.log&lt;br /&gt;
&lt;br /&gt;
If uservariables are updating correctly, go head with the installation and edit the script to log to file.&lt;br /&gt;
&lt;br /&gt;
==Autorun as a service ==&lt;br /&gt;
And now the installation of the service (and auto run at start of the raspberryPi)&lt;br /&gt;
&lt;br /&gt;
It Depends of your system. Do you use wheezy or jessie ? Check with :&lt;br /&gt;
 echo $(lsb_release -is) $(lsb_release -cs) $(lsb_release -rs)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Method 1 for Debian wheezy system===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo wget https://raw.githubusercontent.com/jmleglise/mylittle-domoticz/master/Presence-detection-beacon/check_beacon_presence&lt;br /&gt;
sudo mv check_beacon_presence /etc/init.d/&lt;br /&gt;
sudo chmod 755 /etc/init.d/check_beacon_presence&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check with starting the service manually : &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;sudo /etc/init.d/check_beacon_presence start&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check with :&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;sudo /etc/init.d/check_beacon_presence status&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
other commands : start, stop, restart, status&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And Finally, register the service to autorun the script when the Raspberry Start :&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;sudo update-rc.d check_beacon_presence defaults&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Memo removing the autorun :&amp;lt;br&amp;gt;&lt;br /&gt;
 sudo update-rc.d -f check_beacon_presence remove&lt;br /&gt;
&lt;br /&gt;
===Method 2 for Debian jessie system (thanks to justin81) ===&lt;br /&gt;
The autostart has to be modified to use systemctl instead of the update-rc.d method to run at the end of all initializations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 sudo nano /lib/systemd/system/check_beacon_presence.service&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Paste:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Unit]&lt;br /&gt;
Description=check_beacon_presence Service&lt;br /&gt;
After=multi-user.target&lt;br /&gt;
&lt;br /&gt;
[Service]&lt;br /&gt;
User=root&lt;br /&gt;
Type=idle&lt;br /&gt;
ExecStart=/usr/local/bin/check_beacon_presence.py&lt;br /&gt;
&lt;br /&gt;
[Install]&lt;br /&gt;
WantedBy=multi-user.target&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
run:&lt;br /&gt;
&lt;br /&gt;
 sudo chmod 644 /lib/systemd/system/check_beacon_presence.service&lt;br /&gt;
 sudo systemctl daemon-reload&lt;br /&gt;
 sudo systemctl enable check_beacon_presence.service&lt;br /&gt;
 sudo reboot&lt;br /&gt;
&lt;br /&gt;
Check if it is running:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl status check_beacon_presence.service -l&lt;br /&gt;
&lt;br /&gt;
==Final test==&lt;br /&gt;
(with autorun enabled)&amp;lt;br&amp;gt;&lt;br /&gt;
 sudo reboot&lt;br /&gt;
 ps -ef | grep python&lt;br /&gt;
You should get check_beacon_presence.py running&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Use in Domoticz=&lt;br /&gt;
&lt;br /&gt;
==Lua==&lt;br /&gt;
Write script based on the uservariable. &amp;lt;br&amp;gt;&lt;br /&gt;
For using user variables in Lua scripts, there are three tables available: uservariables, uservariables_lastupdate and uservariablechanged. The uservariablechanged table (with only the variable that triggered the event) is only available in your event scripts (script_variable_name.lua), the other two are always available. Reference your variable by name, e.g. if uservariables[&amp;quot;MyVar&amp;quot;] = ... Have a look here : https://www.domoticz.com/wiki/Events&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example a &amp;#039;&amp;#039;&amp;#039;variable script&amp;#039;&amp;#039;&amp;#039; : &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;script_variable_autoArmAlarm.lua&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
--Variable scripts receive 7 tables from Domoticz: &lt;br /&gt;
-- otherdevices, otherdevices_lastupdate, otherdevices_svalues, otherdevices_idx, uservariables, uservariables_lastupdate and uservariablechanged&lt;br /&gt;
&lt;br /&gt;
commandArray = {}&lt;br /&gt;
&lt;br /&gt;
beaconHome=0&lt;br /&gt;
for variableName, variableValue in pairs(uservariables) do&lt;br /&gt;
    if string.sub(variableName,1,3)==&amp;quot;Tag&amp;quot; and variableValue ~= &amp;quot;AWAY&amp;quot; then&lt;br /&gt;
      beaconHome=beaconHome+1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
if otherdevices[&amp;#039;Alarm&amp;#039;] == &amp;#039;On&amp;#039; and beaconHome&amp;gt;=1 then   -- switch Off Alarm because 1 beacon come back Home&lt;br /&gt;
    table.insert (commandArray, { [&amp;#039;Alarm&amp;#039;] =&amp;#039;Off&amp;#039; } )&lt;br /&gt;
elseif otherdevices[&amp;#039;Alarm&amp;#039;] == &amp;#039;Off&amp;#039; and beaconHome==0 then  -- switch On Alarm because all beacon are away&lt;br /&gt;
    table.insert (commandArray, { [&amp;#039;Alarm&amp;#039;] =&amp;#039;On&amp;#039; } )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return commandArray&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other example on the forum topic : https://www.domoticz.com/forum/viewtopic.php?f=28&amp;amp;t=10640&amp;amp;start=100#p86310&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Blockly==&lt;br /&gt;
https://www.domoticz.com/forum/viewtopic.php?f=28&amp;amp;t=10640&amp;amp;start=140#p86725&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
The forum topic about this script is here:https://www.domoticz.com/forum/viewtopic.php?f=28&amp;amp;t=10640&amp;lt;br&amp;gt;&lt;br /&gt;
Review page for ble beacons : https://www.beaconzone.co.uk/allbeacons &amp;lt;br&amp;gt;&lt;br /&gt;
https://wiki.tizen.org/wiki/Bluetooth&amp;lt;br&amp;gt;&lt;br /&gt;
https://storage.googleapis.com/google-code-archive-source/v2/code.google.com/pybluez/source-archive.zip  =&amp;gt; pybluez\examples\advanced\inquiry-with-rssi.py&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Other command=&lt;br /&gt;
Reset the bluetooth adapter (hci0 in the above example) with:&amp;lt;br&amp;gt;&lt;br /&gt;
 sudo hciconfig hci0 down&lt;br /&gt;
 sudo hciconfig hci0 up&lt;br /&gt;
&lt;br /&gt;
Find the MacAdress of your beacon with hcitool (from bluez installation)&lt;br /&gt;
 pi@raspberrypi ~ $ whereis hcitool&lt;br /&gt;
 hcitool: /usr/local/bin/hcitool&lt;br /&gt;
 pi@raspberrypi ~ $ sudo hcitool lescan&lt;br /&gt;
 LE Scan ...&lt;br /&gt;
 FB:14:78:38:18:5E nut&lt;br /&gt;
 FB:14:78:38:18:5E (unknown)&lt;/div&gt;</summary>
		<author><name>Xpavli44</name></author>
	</entry>
</feed>