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

@ih8gates, I identified (what I believe to be) the culprit of this bug and posted an updated version. Please let me know if you continue to see it.

Noticed a side-effect: when I run Presence my Harmony hub becomes unresponsive (led turns red). Besides that the Pi Zero responds very slow to keystrokes: press a key an it takes up to 10 seconds before the Pi responds.

Installed it on a Pi 3, works fine!

Noticed the response lag re keystrokes here also.

Lars

1 Like

Hi,
firstly thanks a lot for sharing this.
I run this project on a dedicated Pi 0.

I just have one question is it possible to make it comatible with this component?


or this

Actually I just need the information that I’m at home or not :slight_smile:
BR
1 Like

The combined sensor I recommended (average) gives you just that! :slight_smile:

Interesting. Any logs to report?

The Harmony issue was mentioned earlier in this topic, the led turns red and it doesn’t respond to commands. The Pi itself becoming very slow in a SSH sessions was also mentioned before. I assume by logging you meant the output of Presence.sh ?

presence 0.4.11  - Started. Performance predictions based on current settings:

Est. to verify all (3) owners as ‘away’ from all ‘home’: 90 seconds to 300 seconds.
Est. to verify one owner is ‘away’: 30 to 122 seconds.
Est. to recognize one owner is ‘home’: 0.15 seconds to 13 seconds.
location/owner/Woonkamer/88:6B:6E:7F:–:-- { confidence : 0, name : , scan_duration_ms: 5055, timestamp : Mon Apr 23 2018 06:07:18 GMT+0000 (UTC)}
location/owner/Woonkamer/88:75:98:C6:–:-- { confidence : 100, name : Galaxy S8, scan_duration_ms: 1159, timestamp : Mon Apr 23 2018 06:07:19 GMT+0000 (UTC)}
location/owner/Woonkamer/F4:5C:89:D5:–:-- { confidence : 100, name : iPhone van --------, scan_duration_ms: 931, timestamp : Mon Apr 23 2018 06:07:20 GMT+0000 (UTC)}
DEBUG Scanning for 0 guest devices between owner scans, when at least one device is present.
DEBUG Appropriate Delay: 30
location/owner/Woonkamer/88:6B:6E:7F:–:-- { confidence : 0, name : , scan_duration_ms: 5060, timestamp : Mon Apr 23 2018 06:07:59 GMT+0000 (UTC)}
location/owner/Woonkamer/88:75:98:C6:–:-- { confidence : 100, name : Galaxy S8, scan_duration_ms: 1217, timestamp : Mon Apr 23 2018 06:08:00 GMT+0000 (UTC)}
location/owner/Woonkamer/F4:5C:89:D5:–:-- { confidence : 100, name : iPhone van --------, scan_duration_ms: 1463, timestamp : Mon Apr 23 2018 06:08:02 GMT+0000 (UTC)}
DEBUG Scanning for 0 guest devices between owner scans, when at least one device is present.
DEBUG Appropriate Delay: 30

Hi @andrewjfreyer

I too have noticed a dramatic slowness in performance on a Pi Zero compared to a Pi B. I wonder if a reason may be a difference in implementation of timeout (single-core v multi-core, perhaps)?

If this is the issue, could this link help?

Hey all, I couldnt see this mentioned but how does this get around the fact that android and iphones will have their mac address changed for privacy reasons?

Does it just look for a broadcasting name and assume that if its the same over multiple times then that is the same device regardless of mac addresses?

Ok from my point of view the mqtt device tracker would work better as I’d be able to use it with other device trackers (example: owntracks for GPS location).
In my opinion another sensor messes up the configuration as different entities are needed for automation rules.
Or maybe I just don’t understand the concept and you can help me out.

Here is my take on making a sensor with the state “home” if confidence is more then 50%
and “not_home” if less then 50%.
This sensor i then put in my personal “device_trackers group”
Right now 1 pi covers my whole apartment, so i dont need multiple.

############################################################################
## Device Tracker Bluetooth_Presence (Separate Pi with https://github.com/andrewjfreyer/presence on it)
############################################################################
## Sensor
############################################################################
sensor:
  - platform: mqtt
    state_topic: 'location/owner/kitchen/94:65:XX:XX:XX:XX'
    value_template: '{{ value_json.confidence }}'
    unit_of_measurement: '%'
    name: 'Matte BT Presence'

  - platform: mqtt
    state_topic: 'location/matte_bt'
    name: 'Matte BT'
    icon: mdi:bluetooth

############################################################################
## Automations
############################################################################
automation:
  - alias: 'Matte BT Set Location Home'
    initial_state: 'on'
    trigger:
      platform: mqtt
      topic: location/owner/kitchen/94:65:XX:XX:XX:XX
    condition:
      condition: numeric_state
      entity_id: sensor.matte_bt_presence
      above: 50
      value_template: '{{ state.state }}'
    action:
      - service: mqtt.publish
        data_template:
          topic: 'location/matte_bt'
          retain: true
          payload: 'home'

  - alias: 'Matte BT Set Location Not_Home'
    initial_state: 'on'
    trigger:
      platform: mqtt
      topic: location/owner/kitchen/94:65:XX:XX:XX:XX
    condition:
      condition: numeric_state
      entity_id: sensor.matte_bt_presence
      below: 50
      value_template: '{{ state.state }}'
    action:
      - service: mqtt.publish
        data_template:
          topic: 'location/matte_bt'
          retain: true
          payload: 'not_home'
4 Likes

Thanks mcfrojd!

1 Like

If you create a binary sensor that handles all of the rules for your various trackers. Then that gives you a single sensor to use in your various automations.

In this snippet, device_tracker.scottpixel is an nmap tracker. sensor.scott_phone_presence is the data from Presence. I can adjust the rules for binary_sensor.scott_home whenever I need to without touching the automations that depend on it.

binary_sensor:
  - platform: template
    sensors:
      scott_home:
        value_template: "{{ states.device_tracker.scottpixel.state == 'home' or states.sensor.scott_phone_presence.state | float > 10 }}"
        friendly_name: Scott Home
2 Likes

So far, so good with the update. But we’ve both been home so far… I’ll report back after today where we’re both leaving and returning.

One thing that the update did fix is that I’m not seeing as many zeros. Like in that image I showed before. Now, the confidence graph shows some dips overnight, but nothing that made it to zero.

I’m still seeing issues where my Pi Zero and my HomeAssistant Pi will slow down.

Are you noticing adverse affects outside of your Pi that is running presence? I can live with the dedicated Pi that is running presence being slow, but I’m seeing weird slow downs on my network outside of just the Pi.

Hi @eBoon

So I now have two Pi’s running it - a Zero and a B (which is also running a bunch of other stuff). The Zero is (obviously) on wifi, the B and my HA machine are wired.

I have not noticed anything adverse network-wise. But I would probably not have noticed if there was anything, to be fair.

It should be easy enough to start up Wireshark or another packet sniffer to see what is going on with your network?

If only I knew how to use such a tool to look at my network … :disappointed:

:slight_smile:

It’s really not that scary (though it is very powerful). And it’s free.

Give it a go! What’s the worst that can happen? Quit and delete if it all looks too hard.

hahaha … you have shamed me into giving it a go :-). Any hints for me to get started?

Thanks

It’s been. while since I last had to use it, but I seem to recall that it is all too easy to get bogged down in the detail (“ooh - I wonder what that is …”). Keep your eye on the goal, which is watching for the big movements

Have fun!