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

Was just poking around this thread as I’m going to attempt to replace my BLEscan python script with this tool and while I can detect my wife’s iPhone with “hcitool name…” my Android Oreo 8.0 wouldn’t detect even when set discovery mode. I crawled around Google and found this:

hcitool cc 00:00:00:00:00:00 && hcitool auth 00:00:00:00:00:00 && hcitool dc 00:00:00:00:00:00

Replace 00:00:00:00:00:00 with your device actual MAC address.

When I had my Bluetooth settings opened, I was prompted on my phone to pair with my server (USB BT dongle) and once I did that and it became a known device to my phone, “hcitool name…” worked thereafter. Just thought I’d toss this out there in case anyone else might get theirs working the same way.

2 Likes

I pu tthe . following in my sensors.yaml file and nothing is popping up

i got the presence detection somewhat working, but it doesn’t show the confident level

throwing this in configuration.yaml throws an error, not exactly sure where to put it

  - platform: mqtt
    state_topic: 'location/first floor/E4:E4:AB:80:14:92'
    value_template: '{{ value_json.confidence }}'
    unit_of_measurement: '%'
    name: 'First Floor'

  - platform: min_max
    name: "Home Occupancy Confidence of E4:E4:AB:80:14:92"
    type: max
    round_digits: 0
    entity_ids:
      - sensor.first_floor

how do you get it to display the confident level? mine doesn’t do that when i run monitor.sh

The log stuff I posted was just a cleaned up version of the MQTT messages as they came across. I just connected to and subscribed to # to watch the events.

Got it, I tried configuring the mqtt preferences and nothing is sending across, I used the username/password from inside the https://www.cloudmqtt.com/ portal but nothing is connecting…

Not to hijack this thread but it may help some folks who ran into issues like I did (I don’t have multiple Pi’s to work with which is probably why my use-case didn’t work out.)

I really liked the idea of this tool but unfortunately for me, it didn’t work well with my Tile(s) and smartphones (tiles would always have confidence=0 and my smartphones would always end up at confidence=0 like @MisterWil encountered.)

I ended up extending some work I did using some of the concepts from here and I appreciate the work @andrewjfreyer did here as it taught me a lot about Bluetooth:

Is it somehow possible to change the MQTT clientid? One of my pi zero’s is using a pipe symbol which is fine (e.g. mosqsub|19910-raspberry). But I also use monitor.sh on xbian which is using a slash in its client id (e.g. mosqpub/17508-xbian). The Mosquitto add-on on home assistant does not allow that: “ACL denying access to client with dangerous client id ‘mosqsub/1447-xbian’”.

How reliable are the Raspberry pi zero w. I am currently trying to use 7 ESP32s but they are crashy and pretty much too inconsistent to be used. Would 7 Raspberry Pi zero w (One per room) be stable?

My pi zero is running very stable. No problems at all.

@andrewjfreyer can you please add this to the github page?
Option to publish: monitor/scan/restart

I didn’t know about it but need it in my setup. So putting it in the guide is a good idea.

Just to let everyone know you can also run this on a Vero4k. I have one upstairs so didn’t need to add a new pi there :).

1 Like

That’s a very cool idea - I have a few old Android boxes kicking around that I converted over to Linux boxes, never occurred to me to use it for such (I was doing other things) and have sat there abandoned for some time. Nice way to re-purpose!

I just got mqtt running and the pi is connected to it, however none of my sensors are showing up…
I’ve rebooted home assistant and cleared the cache, but nothing is working…
this is in my sensors.yaml file

  - platform: mqtt
    state_topic: 'monitor/rasberrypi/E4:E4:AB:80:14:92'
    value_template: '{{ value_json.confidence }}'
    unit_of_measurement: '%'
    name: 'Media Room'

  - platform: min_max
    name: "Home Occupancy Confidence of E4:E4:AB:80:14:92"
    type: max
    round_digits: 0
    entity_ids:
      - sensor.first_floor

  - platform: mqtt
    state_topic: 'monitor/raspberrypi/status'
    name: 'Media Room Bluetooth Status'

Use mosquitto_sub to test what is actually being received by your mqtt server.

Did you define sensor.first_floor somewhere?
Do you see the sensor.media_room in your entities list?
If not can you try to name it media_room. So: name: ‘Media_Room’

And as nickrout says, see whats being received. Easiest way I use is:
mosquitto_sub -t "#" -u username -P password –v

how do you do that?

If i use this, how does it know which mac address to use?

- alias: Occupancy 
  hide_entity: true
  trigger:
    - platform: numeric_state
      entity_id: sensor.home_occupancy_confidence
      above: 10
  action:
    - service: homeassistant.turn_on
      data:
        entity_id: input_boolean.occupancy

Nope, i do not see this

Nothing is being sent over :frowning:

Then you possibly don’t have mqtt properly set up in your monitor configuration.