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

I use an Orbi netgear system.

Lars

I tried your new version, went from ver 4.13 to 4.26 (only copy/paste the presence.sh file and then
sudo systemctl restart presence.service
Then i get this:

VERSION=0.4.26

location/owner/kitchen/94:65:xx:xx:xx:xx {"confidence":"0","name":"Unknown","scan_duration_ms":"22","timestamp":"Fri Apr 27 2018 09:34:06 GMT+0200 (CEST)"}
location/matte_bt not_home
location/owner/kitchen/60:AF:xx:xx:xx:xx {"confidence":"0","name":"Unknown","scan_duration_ms":"23","timestamp":"Fri Apr 27 2018 09:34:06 GMT+0200 (CEST)"}
location/asa_bt not_home

Changed back to VERSION=0.4.13

location/owner/kitchen/94:65:xx:xx:xx:xx {"confidence":"100","name":"Mc3T","scan_duration_ms":"1190","timestamp":"Fri Apr 27 2018 09:34:11 GMT+0200 (CEST)"}
location/matte_bt home
location/owner/kitchen/60:AF:xx:xx:xx:xx {"confidence":"100","name":"Galaxy S6 edge","scan_duration_ms":"265","timestamp":"Fri Apr 27 2018 09:34:11 GMT+0200 (CEST)"}
location/asa_bt home

Anything ekse that needs to change?

I think you may need to update your behaviour_preferences, see above

1 Like

Hi @andrewjfreyer

I now have three Zero’s running, and have adopted your script way above to keep them all up to date.

One issue to report from the current version - when a node comes up I get the following, perhaps not so useful, MQTT post -

presence& {"status":"online"}

(presence is my chosen mqtt_topicpath). Perhaps lose the & and post a hostname?

EDIT - I looked at the code and it seems that this is certainly a bug. The LWT is not working, I suspect because of it. On the upside the statuses are now retained by the broker - thanks.

1 Like

If you would like a panel like this -

then (after installing CustomUI :slight_smile: ), you need to have six (assuming that you have three nodes tracking two phones) pairs of sensors like this

- platform: mqtt
  name: "upstairsbt_ianiphone"
  state_topic: "presence/owner/[host redacted]/[mac redacted]"
  value_template: "{{ value_json.confidence }}"

- platform: template
  sensors:
    upstairs_ianiphone:
      friendly_name: "Upstairs - Ian iPhone"
      value_template: >-
        {% if is_state('sensor.upstairsbt_ianiphone', '100') %}
          Seen
        {% else %}
          Not seen
        {% endif %}

plus this in your customize_glob.yaml

sensor.*phone:    # hopefully just the BT iphone sensors
  show_last_changed: true
  templates:
    icon_color: "if (state === 'Seen') return 'rgb(100, 200, 30)'; else return 'rgb(200, 100, 30)';"

and then just have a group with the 6 template sensors.

4 Likes

Thanks. I’ll fix this shortly.

Pardon me if this has been asked before.

Why not using fitness tracker such as Mi Band 2 as beacon? They transmit BLE signal and always on your wrist.

1 Like

You may want to check out the first post in the thread …

This is exactly what I’m looking for. Do you know if this method works good with Android phones too?

@PianSom I’m getting ready to roll presence into my AppDaemon environment - have you tweaked this code significantly in the last week?

Thanks for getting me started!

Hi @eBoon

No, I haven’t. A combination of

  • other things to do,
  • waiting to see if AD MQTT gets released,
  • some concerns about bluetooth interference with lots of my IoT devices,
  • waiting for bug fixes for the presence MQTT code
  • indecision about the algorithm I was to adopt in AD

has meant that I have been rather lacking!

Look forward to seeing your code.

2 Likes

BTLE tokens are supported, for owner devices.

Yes, any phone from any manufacturer should work if they have successfully implemented bt4

Hello.

Looking into your solution which looks great, I read recently that iOS does MAC Address randomization for privacy reasons. How does your script circumvent that?

Thanks in advance for your help.

Couple of things:

  • Suggestion: It would be nice to be able to specify a name or alias along with the MAC, this way I can avoid seeing Unknown for devices that have not been seen. (I also sometimes see Unknown for devices that have been successfully scanned).

  • Not too major, but when called with -V, it should return the version per the Usage: blurb (I am seeing “illegal option -V”

    pi@raspberrypi:~/presence $ ./presence.sh -V
    ./presence.sh: illegal option – V
    Usage:
    presence -h show usage information
    presence -d print debug messages and mqtt messages
    presence -b binary output only; either 100 or 0 confidence
    presence -c only post confidence status changes for owners/guests
    presence -t <1,2> trigger mode; only scan in response to MQTT message posted
    to ‘presence/scan’. The payload of the message can
    include a ‘duration’ value to define how long the looping
    detection should continue. Default is 120 seconds.

    Mode 1: require a trigger for each scan
    Mode 2: require a trigger to scan only when at least
    one owner is home. When all owners are gone,
    scanning is periodic (behavior_preferences)
    presence -V print version

I am currently running 0.4.26 using mode -t2 and am triggering on all door opens - seems to be working pretty well!

Thanks again!

1 Like

Randomization happens in response to a different type of request. For these name requests, the by or WiFi MAC has to be known beforehand

1 Like

I must say I really appreciate the work you’ve done on this project @andrewjfreyer. Kudos! I’ve been running it on a dedicated Pi3 for a little while now with great stability. I have, however, one small thing I really appreciate getting some help on. Sometimes the trigger is a little bit slow in detecting people arriving (most important) so I would like to make some automation that triggers the scan when the door sensor is triggered. I would asume this is possible, but I’m not very familiar with MQTT and how to do this. Any help would be much appreciated.

1 Like

You should be able to just use something like this to initiate a scan (assumes that you are running presence with the -t1 or -t2 option):

action:
 service:mqtt.publish
 data:
  topic: presence/scan
1 Like

Just to let you know - problem still there in 0.4.27

Which issue are you referring to?