Room Presence with Google Homes - seangreen2/home_assistant GitHub Wiki
that can be found here.
Due to Google's API changes the Google Home integration will soon be removed from Home Assistant and I will eventually remove this page from my wiki. I have developed a Room Presence Logic automationWhat you'll need:
- At least one Google Home (the more the better)
- A Bluetooth Low Energy capable device (we used our Android phones)
For the past few days I have been experimenting with detecting Room Presence via the Bluetooth on our android phones and on our three Google Home Minis. We typically bring our phones with us room to room, but this should work with any other bluetooth devices that are on your person. https://i.imgur.com/e1VCcdB.jpg
The detection takes less than ten seconds to determine the room location and so far has a 100% success rate with the automations I have created for it so far. Huge credit to this post on the HA Forums for getting me this far and adapting it for my personal use: https://community.home-assistant.io/t/new-google-home-device-tracker-component-introduced-in-ha-0-83/81755
Note, our apartment is roughly 1,200 sq/ft with a Mini in our Bedroom, Living Room, and Office and the YAML examples will reflect that. Your Google Home placement will also be important as if they are too close together they can give false positives. Your results may vary.
For a visual of where my Minis are located, here's a floorplan provided by my Neato. The yellow circles represent each Mini's location: https://i.imgur.com/hwULRnO.jpg
First things first, you need to add each of your Google Homes to your config file:
googlehome:
devices:
# Office
- host: 192.168.1.100
rssi_threshold: -100
track_devices: true
device_types: 2
# Bedroom
- host: 192.168.1.101
rssi_threshold: -100
track_devices: true
device_types: 2
# Living Room
- host: 192.168.1.102
rssi_threshold: -100
track_devices: true
device_types: 2
Once your devices are detected, each Home will have a separate entry in your known_devices.yaml. The RSSI threshold determines how far the Homes will look for devices. You will want this fairly high because even with a phone literally on top of the Home, the RSSI will report to about -50. WARNING: Do NOT set track_devices:
to "false" after your devices have been detected - this will tell the Homes to stop scanning altogether.
I had to jump through a lot of hoops to get our Pixel 3 phones detected by each of the Homes. I ended up having to download the Smartthings app despite not owning any Smartthings equipment to get our phones to start broadcasting their BLE signal. Below you will find a numbered list of steps I took to get each phone detected. Yes, I know the steps seem convoluted, but they worked. Your results may vary.
- First, download the Smartthings app, create an account, and then enable these settings as shown in this image: https://i.imgur.com/nRk8nkz.png
- Second, delete any previous traces of your particular device in known_devices.yaml
- Third, Enable Pairing Mode on each of the Homes, then connect your device to each Home.
- Fourth, On your Phone (or other device), remove each Home that you just paired with. DO NOT remove the respective devices from your Homes' Known Devices.
- Fifth, Restart your device and Home Assistant. UNPLUG your Homes from power for thirty seconds and then plug them back in. (I know, I know, but this was the only reason it worked for me.)
- Sixth, after everything has rebooted, move your device in proximity of each Home for about thirty seconds. Rinse and repeat until all Home has detected your device in your known_devices.yaml
- Seventh, restart Home Assistant after all Homes have detected your devices.
Once you restart HA, find the appropriate device tracker entity for the devices you want to track. Note the entity names because the next step is to make several Template Sensors to measure the RSSI values. I also recommend renaming your tracker entities to something more user friendly and descriptive like I have.
Next we'll need to make some Template Sensors to single out and measure the RSSI values only to use later in our automations.
- platform: template
sensors:
bedroom_sean_gh_rssi:
value_template: >-
{% if is_state("device_tracker.192_168_1_100_3c_28_6d_29_fe_3d", "home") %}
{{state_attr('device_tracker.192_168_1_100_3c_28_6d_29_fe_3d', 'rssi')}}
{% else %}
-99
{% endif %}
- platform: template
sensors:
livingroom_sean_gh_rssi:
value_template: >-
{% if is_state("device_tracker.192_168_1_101_3c_28_6d_29_fe_3d", "home") %}
{{state_attr('device_tracker.192_168_1_101_3c_28_6d_29_fe_3d', 'rssi')}}
{% else %}
-99
{% endif %}
- platform: template
sensors:
office_sean_gh_rssi:
value_template: >-
{% if is_state("device_tracker.192_168_1_102_3c_28_6d_29_fe_3d", "home") %}
{{state_attr('device_tracker.192_168_1_102_3c_28_6d_29_fe_3d', 'rssi')}}
{% else %}
-99
{% endif %}
- platform: template
sensors:
sean_room_status:
value_template: '{{ states.input_select.sean_room_location.state }}'
friendly_name: 'Room Location'
icon_template: >
{% if is_state('input_select.sean_room_location', 'Office') %}
mdi:keyboard
{% elif is_state('input_select.sean_room_location', 'Bedroom') %}
mdi:hotel
{% elif is_state('input_select.sean_room_location', 'Living Room') %}
mdi:sofa
{% elif is_state('input_select.sean_room_location', 'Away') %}
mdi:exit-run
{% elif is_state('input_select.sean_room_location', 'Home') %}
mdi:home-account
{% else %}
mdi:exit-run
{% endif %}
The last Template Sensor is to select the state for your room location. These sensors also make your RSSI values default to -99 if you're out of range of your Home's Bluetooth making accuracy better. The code below will also need to placed in your main config.
input_select:
sean_room_location:
name: Sean's Room Location
options:
- Bedroom
- Living Room
- Office
- Away
- Home
The last thing we need to add to the main config are some Input Booleans. This part can be optional depending on how you do your automations.
input_boolean:
sean_office_presence:
name: Sean Office Presence
initial: false
sean_living_room_presence:
name: Sean Living Room Presence
initial: false
sean_bedroom_presence:
name: Sean Bedroom Presence
initial: false
Now for the automations! This is actually pretty straight forward as all you have to do is compare the RSSI values that are being reported from each Home. Because you have already created the Template Sensors earlier, you will only need to do is some copy/pasting those sensors into the automations. You will need to create an automation for each room you want to detect presence in. For me there's only three, but this is simple enough to add more rooms as needed.
This is how the RSSI values look for me as well as the input booleans: https://i.imgur.com/dlpmxz8.jpg
# Sean is in the living Room using Google Home BT tracking
- alias: Sean in Living Room
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.livingroom_sean_gh_rssi
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ ( states.sensor.office_sean_gh_rssi.state ) > ( states.sensor.livingroom_sean_gh_rssi.state ) }}"
- condition: template
value_template: "{{ ( states.sensor.bedroom_sean_gh_rssi.state ) > ( states.sensor.livingroom_sean_gh_rssi.state ) }}"
action:
- service: input_boolean.turn_on
data:
entity_id: input_boolean.sean_living_room_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_bedroom_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_office_presence
- service: input_select.select_option
data:
entity_id: input_select.sean_room_location
option: Living Room
# Sean is in the Office using Google Home BT tracking
- alias: Sean in Office
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.office_sean_gh_rssi
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ ( states.sensor.livingroom_sean_gh_rssi.state ) > ( states.sensor.office_sean_gh_rssi.state ) }}"
- condition: template
value_template: "{{ ( states.sensor.bedroom_sean_gh_rssi.state ) > ( states.sensor.office_sean_gh_rssi.state ) }}"
action:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_living_room_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_bedroom_presence
- service: input_boolean.turn_on
data:
entity_id: input_boolean.sean_office_presence
- service: input_select.select_option
data:
entity_id: input_select.sean_room_location
option: Office
# Sean is in the bedroom using Google Home BT tracking
- alias: Sean in Bedroom
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.bedroom_sean_gh_rssi
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ ( states.sensor.livingroom_sean_gh_rssi.state ) > ( states.sensor.bedroom_sean_gh_rssi.state ) }}"
- condition: template
value_template: "{{ ( states.sensor.office_sean_gh_rssi.state ) > ( states.sensor.bedroom_sean_gh_rssi.state ) }}"
action:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_living_room_presence
- service: input_boolean.turn_on
data:
entity_id: input_boolean.sean_bedroom_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_office_presence
- service: input_select.select_option
data:
entity_id: input_select.sean_room_location
option: Bedroom
# Sean is away from the house
- alias: 'Sean is Away'
initial_state: 'on'
trigger:
- platform: state
entity_id: device_tracker.sean_phone
to: 'not_home'
action:
- service: input_select.select_option
data:
entity_id: input_select.sean_room_location
option: Away
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_living_room_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_bedroom_presence
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sean_office_presence
# Sean is now home and BT is unknown
- alias: 'Sean is Home'
initial_state: 'on'
trigger:
- platform: state
entity_id: device_tracker.sean_phone
to: 'home'
action:
- service: input_select.select_option
data:
entity_id: input_select.sean_room_location
option: Home
Next, save your automations and config files and restart Home Assistant. After a few seconds your devices should be detected and start showing their RSSI Values. You can now add this information to your frontend, or set them up to be used in other automations!