Wallaceburg, Ontario

Tracking devices in the home

Tracking devices in the home

I received a Google Home for Christmas last year, and after checking to see if some rumours are true, such as it is always recording and sending data to Google which seems to be very false, I decided to buy one for each room in my house.

It seemed like it might be a good idea to take advantage of the Bluetooth discovery aspect of Google Home to see if I can track items and which room they are in the home. I started off with one Tile on my keys. The question was how to link all the devices in Home Assistant – my smart home automation hub.

After connecting my Google Homes to Home Assistant using the Google Home component, turning on device tracking – I received a list of devices that could be tracked. I simply turned tracking on for those devices. Next, all I had to do was build a sensor.

A few considerations I had to make was how to build it. I named all the tracked devices (since there is one for each Google Home) in a standardized way. I decided it would be “Key Tile (Room Name)”. Then I let the Google Home component poll each device as it normally would, then determine by the Bluetooth Signal strength which room it was in.

Below is an example of my “Key Tile Location”. The entity IDs, including IP addresses and MAC addresses, were changed for security purposes.

key_tile_room:
  friendly_name: "Key Tile Location"
  entity_id:
    - device_tracker.192_168_1_100_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_101_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_102_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_103_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_104_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_105_ff_ff_ff_ff_ff_ff
    - device_tracker.192_168_1_106_ff_ff_ff_ff_ff_ff
  value_template: >-
    {% set ns_room = namespace(room='Not Found') %}
    {% set ns_signal = namespace(signal=-10000) %}
    {% set room = "Not Home" %}
    {% set signal = -10000 %}
    {% for state in states.device_tracker %}
    {% if ('Key Tile' in state.name) and (state.state == 'home') and (state.attributes.source_type == 'bluetooth') %}
    {% if (state.attributes.rssi != null) %}
    {% if (state.attributes.rssi | float > ns_signal.signal) %}
    {% set ns_room.room = state.name %}
    {% set ns_signal.signal = state.attributes.rssi | float %}
    {% endif %}
    {% endif %}
    {% endif %}
    {% endfor %}
    {{ ns_room.room | replace("Key Tile (", "") | replace(")", "") }}

Now I know my keys are almost always in the kitchen. Nothing too special, but it was fun to try.