[monitor] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection

Thx for answer! :slight_smile:

This is how i start the script from CMD on my windows machine after ssh to RPi2

The first time I started, I wrote like this:
sudo bash monitor.sh -x -b -tdr -u

and now like this:
sudo bash monitor.sh

automation:

- initial_state: 'on'
  alias: 'Front door open/closed BT helper atm'
  trigger:
  - platform: state
    entity_id: binary_sensor.pi3_front_door_sensor
    to: 'off'
  action:
  - service: script.scan_bt_depart
  - service: script.scan_bt_arrive

im going to split them up to two automatins like your guide. one when i unlock door from inside (depart) and the other when unlocking with tag/code from outside.

EDIT
now i see i have wrong entity in that automation :'D

changing to this for now:

- initial_state: 'on'
  alias: 'Front door open/closed BT helper atm'
  trigger:
  - platform: state
    entity_id: lock.dorrlaset
    to: 'unlocked'
  action:
  - service: script.scan_bt_depart
  - service: script.scan_bt_arrive

but the tile did still work ?

Well, that sudo command runs it until the session ends. You really need a service file so that it auto starts :wink:

This is just a short version, you should really read up on how to work on ubuntu-like systems that use systemd. :wink:

monitor.sh is the file, that does the work. If you setup a monitor.service file, this is the one that is needed to autostart the monitor.sh file, eg. after a restart. This service file is for the OS to know, how to handle this ā€œautostartā€. As this service is controlled by the OS, you can enable, disable, start or stop this service.

So after setting up monitor.sh you have to make it autostart. Setup the file monitor.service and check the contents. After that enable the service and you are good to go. :+1:

1 Like

OK thank you! :slight_smile: Now it works, when i reboot my rpi and type ā€œsudo systemctl status monitor.serviceā€ it is up and running =)

i added it like this in known_static_beacons:

You mentioned you added the mac in known_static_beacons file. I donā€™t have such as file. Only these.

known_beacon_addresses
known_static_addresses

add tile in: known_beacon_addresses
my file looks like this

# ---------------------------
#
# BEACON MAC ADDRESS LIST; REQUIRES NAME
#
# 	Format: 00:00:00:00:00:00 Nickname #comments
# ---------------------------
F2:A3:TT:98:65:95 tile one
"random"

Ok. My other problem is that I cannot find the mac address. Tried several different free bluetooth ios app, and it doesnā€™t provide mac address.

monitor doesnā€™t see the Tile either. I use this cmd.

sudo bash monitor.sh -trd -x -b

ok then i dont know why, change battery in tile? haha :stuck_out_tongue:

Did you find a app with a -dBm meter? Hold your Tile against your phone while scanning. Then it should get lowest dBm. mMaybe try press the button on the tile to ā€œwake upā€ i dunno :stuck_out_tongue:

That app is for android correct? I use apple. The app I use for my iphone, I can see the Tile, but the data info does not show the mac address. Just bunch of useless info I donā€™t need.

From here: BluetoothLE Tile - Detect on raspberry Pi? - #6 by happybubbles

Ok. I finally managed to find the Tile Mate mac address after many failed attempts using various scripts and ios mobile apps by using this Switchbot-MQTT-ESP32 code tweaking it along with the help from its author.

Plug the ESP32 into the pc after uploading the code and using the monitor serial console to look for all scanned devices. You will need to change this line in the code before uploading it.

# find
pScan->start(initialScan, scanEndedCB, true);

# change to
pScan->start(initialScan, scanEndedCB);

It will scan for 300 seconds. If you are lucky, not like me, you should see in the log Tile next to name. That will be the mac you are seeking.
If there is no Tile next to name, compare this UUID as it is from a Tile Mate (removable battery model) non Pro version.

Advertised Device found: Name: , Address: d6:u9:41:6d:a4:52, manufacturer data: 4c0002159d41000035d6f4ddba60e7bd8dc491c04a25f111cf
Processing Rescan MQTT...
Scan Ended

Hi,

Iā€™m sorry as Iā€™m sure this has been asked already. I use the appdeamon script with monitot but what would be the optimal monitor arguments for a single node that is placed at the front door and a contact sensor
at the front door being the only gateway sensor. We only ever leave/enter through the front door.

I struggle to understand how -tad or -tdr works (especially with 1 node).

I asked in that forum but no luck

Thanks

each individual letter is a switch that changes a setting in monitor.sh, you need -tad for your setup.

Hi fellas
Iā€™ve been running monitor on a rpi zero for a few years now, but recently Iā€™ve noticed it hasnā€™t been keeping track on my devices.

I logged into the pi and watched it working and noticed this error

[+] 0.2.197 18-04-2021 02:48:38 pm [CMD-MQTT] 
warning: network is down. 
enqueuing command to try
again after a delay

Has anyone come across this before and know what maybe causing it?

Also after I while I canā€™t post arrive or depart, yet when I tried restart I saw this message


/support/btle: line 430: packet_pipe: No such file or directory

Coming back to this Iā€™ve noticed my commands to scan arrive or depart doesnā€™t work, yet restart does.

My Monitor on my rpi0 suddenly stopped working. I keep getting:
ā€œ[CMD-MQTT] warning: issue connecting to mqtt server (lookup error). enqueuing command to try again after a delayā€
ā€œ[CMD-ERRO] fatal mqtt error - messages may not be delivered as intended (issue connecting to mqtt server (lookup error). enqueuing command to try again after a delay / 4)ā€.

I am running HA broker add-on with password. I can ping the broker IP.

Any ideas? Thanks!

Hi,

First of all, thank you so much for building this, I really appreciate it!

Iā€™m having a weird issue where the Pi zeros I have around our house have a much harder time picking up my wifeā€™s phone versus mine. Iā€™ve attached some example graphs so you can see what I mean.

We have identical iPhone 11s, so Iā€™m struggling to see what could be leading to the differenceā€¦ I have 4 Pi zeros around the house - they all reflect a similar difference in sensitivity, and it occurs even when weā€™re sitting next to each other with our phones essentially equidistant from the sensors.

Any idea what could cause her iphone 11 to be so much harder to pick up than mine?

Thanks so much again!!

There are a couple things you could do to try and get more detail on this problem. Are the phones paired to the nodes? So you can get a reading of the rssi signal of each phone.

You could also enable the ibeacon in the HA mobile app and see if you get the same result when tracking that.

Got this working today and it seems to solve most of my presence detection problems. Need to distribute this further around the house, but I can already say this is very promising! BIG THANKS @andrewjfreyer and to others who have contributed to this project!

1 Like