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

Well yesterday the Error, was “Error”, but I changed the code.

Now I have a different issue. Having these values:

first_floor -20db
second_floor -99db (out of reach if I understood correctly)
third_floor Unknown (to take out this state I do have to restart monitor, that’s another question)

then the above value_template gives result

John_second_floor_rssi_raw , ( but it should instead give the John_first_floor_rssi_raw (-20 more probable then -99).

So I thought that maybe I need to put a max (instead of min) in value_template, but it gives the same result …

Sorry I really do not understand templating …

  - platform: template
    sensors:
      lowest_rssi:
        friendly_name: Lowest Rssi
        value_template: >
          {% set sensors = [ 'sensor.john_first_floor_rssi_raw', 'sensor.john_second_floor_rssi_raw', 'sensor.john_third_floor_rssi_raw' ] %}
          {% set max = states('sensor.max') %}
          {% set selection = states.sensor | selectattr('entity_id', 'in', sensors) | selectattr('state', 'eq', max) | map(attribute='name') | list %}
          {% if selection | length > 0 %}
            {{ selection[0] }}
          {% else %}
            Error
          {% endif %}
1 Like

Or maybe its possible to change the code, to have an mqtt topic for room detection? Basically getting all the rssi value, get the highest (lowest negative number) , and then with that value publish where the phone is? Something like that.

That will give you room detection, pretty cool

The issue is that you’re not converting these strings to integers before comparing them, so at best you’ll find the first alphabetical string. Try converting to integers first with | int

WIll try thanks, but also your example is not working the input_boolean always stays off.

I tried the automation with and without
value_template: ‘{{ state.attributes.last | int }}’

automation:
  - alias: John Occupancy On
    initial_state: 'on'
    hide_entity: true
    trigger:
      - platform: numeric_state
        entity_id: sensor.john_home_occupancy_confidence  
        value_template: '{{ state.attributes.last | int }}'           
        above: 10 
    action:
      - service: homeassistant.turn_on
        data:
          entity_id: input_boolean.john_home_occupancy
1 Like

Make sure to use domain-specific service calls if they’re available to avoid problems. I’ll update the docs, since this recently changed for input_booleans (good catch!)

service: input_boolean.turn_on

1 Like

Ahhh ok got it,

so I do not need this I guess
value_template: ‘{{ state.attributes.last | int }}’

no, not for this trigger. the integer comparison comment above references the jinja sorting you’re trying to do.

Problem is I don’t like to use the above sensor, since when you restart HASS it goes to Unknown, I would rather use the rssi value above -99 below 0

what do you think?

A lot of folks follow @benjimatt’s suggestion to rely on retained messages from the monitor nodes.

1 Like

Any idea how we can start integrating the new person: component with Monitor? It seems it only takes device_tracker domains.

Checking templates there’s no one for device_tracker :frowning:

EDIT: oh wait, there’s MQTT device_tracker!! https://www.home-assistant.io/components/device_tracker.mqtt/

There’s an open feature request for a device tracker output for monitor. I’m on it.

3 Likes

in previous versions availability was published from the monitor, I have created another pi zero with latest monitor on it and now not getting online from the pi, where can I enable that or what am I missing?

1 Like

Feature was removed in the most recent version because, simply, Home Assistant wasn’t reliably using it. That said, I’ll probably roll back since 0.88 seems to be slightly more reliable. Sorry for the inconvenience.

Updated. Add the option PREF_DEVICE_TRACKER_REPORT=true to behavior preferences and restart monitor.

Then:

device_tracker:
  - platform: mqtt
    devices:
      andrew_first_floor: 'monitor/first floor/[device address or alias]'

Messages will be home or not_home

3 Likes

Fixed in the most recent version.

Also note that the monitor log prints out what messages you can use to control its behavior.

Thank you very much for developing this tool!
It seems that RSSI is not sent when PREF_DEVICE_TRACKER_REPORT=true is used.
Are these options mutually exclusive?

Yes, they are mutually exclusive for beacons right now. For known_devices that have connected, rssi should still send.

1 Like

OMG! Thanks a lot Andrew!. Will test it out!

Just added the device_tracker on Home Assistant, it seems to work nice! We lose confidence value tho as the message only contains home or not home, but I guess you either want to use one or the other?. Thanks a lot!

For now turning this off as I need to modify all my automations, but I believe using the device_tracker option is the way to go! Thanks once again!