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

I had to disable device in the Nut app and it started working without disconnecting.

But how do you deal with HA restarts? When I restart HA, it shows device trackers (both phone and nut mini) as “not_home” even though they were home before restart and still are. One option is to go out and then back, but that’s not a practical solution.

MQTT sensors are without value after restart. I use device_tracker.see service in my automation as in the monitor documentation.

1 Like

Would it be ok to power the Pi Zero vis USB? I’d like to buy another Pi but it annoys me that the power adapters cost more than the pi itself :smiley:
If it’s ok to power via USB that’ll solve my issue as I have power sockets in my place with built in USB ports.

Should be ok. I’m powering one of my Pi Zeros using the USB port on a PC.

hi,

i’ve issue with monitoring my Xiaomi phones. It seems like that MI9 doesn’t reply to name query, and this cause the monitor to report confidence 0.

I want to use this program essentialy to disarm my alarms when go back, but how can improve it to avoid this behaviour?

this is my current configuraiton, i’m using a Broadcom USB Dongle and monitor.sh under docker:

---------------------------

BEHAVIOR PREFERENCES

---------------------------

#MAX RETRY ATTEMPTS FOR ARRIVAL
PREF_ARRIVAL_SCAN_ATTEMPTS=1

#MAX RETRY ATTEMPTS FOR DEPART
PREF_DEPART_SCAN_ATTEMPTS=2

#SECONDS UNTIL A BEACON IS CONSIDERED EXPIRED
PREF_BEACON_EXPIRATION=120

#MINIMUM TIME BEWTEEN THE SAME TYPE OF SCAN (ARRIVE SCAN, DEPART SCAN)
PREF_MINIMUM_TIME_BETWEEN_SCANS=3

#ARRIVE TRIGGER FILTER(S)
PREF_PASS_FILTER_ADV_FLAGS_ARRIVE="."
PREF_PASS_FILTER_MANUFACTURER_ARRIVE=".
"

#ARRIVE TRIGGER NEGATIVE FILTER(S)
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE=“NONE”
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=“NONE”

Monitor is launched with these parameters:

monitor.sh -r -b -x -V -D /config

thanks in advance!

1 Like

(The following is on both the master and beta branches)

Looks like there are some limitations on using TLS with the monitor script. I found the following issues:

These prevent connecting securely via TLS to the MQTT server. I didn’t see open issues for these and wasn’t sure if you’d like an issue opened in Github, or just this post.

Thanks for the great work,

//Tomi B.

1 Like

Maybe someone on this thread can give me some pointers on this one?

(I did a search, but just point me to a post if I missed a good one please)

I’m interested in a really quick arrival presence detection for my front door using ESPHome, the BLE tracker, and my Mi Band 3 (< 5 sec).

I’d prefer not to dive into Monitor just yet (which looks very impressive by the way). It’s really just quick arrival at the door that is important to me.

I would also be very interested in any answers to this one.

Thanks!

@andrewjfreyer I have monitor working reliably with our iPhones on two floors now thanks to your help. I’m trying to understand your automations, but I can’t get them to trigger. If I trigger them manually, they seem to work OK though. I’ve checked and they are enabled.
Also, how does the input_boolean.occupancy get reset to off?

I added Monitor last night after issues with owntracks. So far so good. Would like Mahko_Mahko, like to find a way to get it to scan if the door is opened and all devices away. Had a couple of very late triggers, but I am slowly removing all mention of owntracks so guessing that maybe that is the issue

1 Like

I’m struggling to get my iPhone to behave reliably and quickly at the moment. Departures particularly seem to not fire reliably (I have it set to scan for departures when my front door lock changes state):

Those of you who have it working well, could you post your behaviour config file and anything else relevant you might have changed?

You can handle that in an automation, assuming you’ve got a sensor on the door. All you need to do is have it trigger when the door opens, with a condition of nobody being home, and then publish an empty payload to monitor/scan/arrive, as covered here.

1 Like

I thought I read that from top to bottom. I will do that now and see how I go

Actually that helped with with restarts of HA as it always said I was away. I did on an start automation added that and hey presto. sorted :slight_smile:

This wasn’t working for me because the input_boolean wasn’t being turned off on departure. I added an automation to do this:

- alias: pat off
  initial_state: 'on'
  hide_entity: true
  trigger:
    platform: numeric_state
    entity_id: sensor.pat_occupancy_confidence
    below: 90.0
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'input_boolean.pat_occupancy'
        state: 'on'
      - condition: template
        value_template: "{{ (as_timestamp(now()) - as_timestamp(state_attr('automation.pat_off', 'last_triggered') | default(0)) | int > 5)}}"
  action:
    - service: notify.alexa_media
      data:
        target:
        - media_player.attic_echo_dot
        title: "Home Assistant"
        data:
          type: announce
          method: all
        message: "Pat has left the building. He was here for {{relative_time(states.input_boolean.pat_occupancy.last_updated)}}"
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.pat_occupancy

Along with @areks Node RED flow, I finally have reliable presence and occupancy detection. Thanks!

1 Like

@Tony321 The restart behavior of HA is frustrating. Some users retain messages. Personally, I just restart my monitor nodes by posting a restart message 30 seconds after an HA restart.

Have you connected this phone to any bluetooth other device before?

Both of these are correct. monitor is essentially a wrapper for mosquitto_sub/pub so some features not often requested are lower priority. Please open an issue for mosquitto features important to you and I’ll support them.

1 Like

it seems like only on these devices.

Now i’ve solved in another way:

put monitor in -tad. The Departure Scan is triggered by “arm away” mode of my Alarm system, while Arrive Scan is triggered by a Magnet Sensor on my main door.

Tested today, and in 3 seconds monitor recognized my Xiaomi phone and disarm system :smiley:

Amazing!

2 Likes

Yes, I’ve made an automation that restarts monitor immediately when HA starts. Device trackers sometimes change state to away but within 1 minute they are back home. Though I had to use boolean for disabling welcome automations after HA restart.

How are you doing that out of interest? Through node-RED still? I already have it checking for HA restarts, but I haven’t looked into how to ssh into a VM and run a command yet. Perhaps it’s easier to do from the Monitor instance itself?

EDIT: I shouldn’t post before I have my coffee. There’s a restart MQTT command haha.

1 Like

Yup! That’s it.