5 m

A phone, headphones and a watch lying on a wooden desktopBluetooth devices are cool. We use them a lot in our modern society. We use them to listen to music, for our smart watches, door locks, smart scales, e.g. Each of these devices has its own unique bluetooth address, which is readable from within Home Assistant if you have an Android device. So, I started thinking: if I can trigger automations based on a bluetooth connection of my phone, what would be cool to automate?

First of all, you need to make sure that the bluetooth connection sensor is enabled within the Home Assistant Companion App for Android. Open the app, click the side menu, click on ‘App Configuration and on ‘Manage Sensors’. Look for the ‘Bluetooth Connection’ sensor and make sure that it is enabled.

Screenshot of Android Bluetooth device settingsConnect the device you want to use as a trigger to your phone. After connecting, you can click on ‘Settings’ next to the device you want to use as trigger within your phone’s bluetooth settings. Here you can see some settings, but what matters is the bluetooth address shown at the bottom of this page. You don’t have to write that number down, but we will check the number in Home Assistant.

Next, go to the developer tools in Home Assistant. Select the tab ‘States’ and search for your bluetooth sensor. Its entity ID will look something like this: ‘sensor.pixel_4a_bluetooth_connection’. Select it and take a look at the attributes of this sensor and specifically at the ‘connected_paired_devices’. You should see the same number as on the bluetooth settings page on your phone. Here, you can copy it.

Screenshot of the developer tools within Home Assistant

Now, you can use this as a template trigger within every automation. This trigger will look like this:

trigger:
- platform: template
  value_template: "{{ '5C:**:**:**:**:87' in state_attr('sensor.pixel_4a_bluetooth_connection', 'connected_paired_devices') }}"

Now that we have defined a trigger, let’s talk about what you can automate with your connected bluetooth devices.

Forgetting your smart watch

Before I started wearing a smart watch, recharging or swopping the battery of my watch was a big thing. I had to go to the watchmaker and let him carefully open my watch, swop the battery and close it properly to keep the waterprove seal. This happened a few times in my life. Most of the times, my watch died before the battery needed to be replaced.

This is different with my smart watch. I need to charge it every two days or so. So, it happens very often that I leave the house without wearing my smart watch, because I forgot to take it after charging it.

The following automation will send a reminder to your phone as soon as your smart watch disconnects. This automation will be more accurate if you are using sensible presence detection to check if you are leaving the home. I used my alarm system as a condition to check if I am really leaving the house to rule out other causes in case when my smart watch disconnects.

- alias: Reminder - Do not forget your watch
  description: ''
  trigger:
  - platform: template
    value_template: "{{ not 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_paired_devices') }}"
  condition:
  - condition: state
    entity_id: YOUR_ALARM
    state: armed_away
  action:
  - service: notify.mobile_app_YOUR_PHONE
    data:
      message: It looks like you left your watch at home.
      title: Watch reminder
  mode: single

Do not disturb while listening to your favorite music

Imagine, you are listening to your favorite music with your favorite bluetooth headphone or speaker when someone calls you. You music will stop while your phone is ringing and your good vibe is totally gone. This will only happen when your phone is not on do not disturb. So, why not switch your phone to DND when your favorite bluetooth headphone or speaker is connected?

A while ago, I wrote an article about Do Not Disturb on Android phones. I am still using the method described in that article, so it is very easy for me to add my big headphones as trigger to these automations. I recommend you to do the same, because there will be more situations in which you may want your phone to be on DND. You can easily put all triggers together into two automations; one to turn on and one to turn off DND on your phone.

For the benefits of this idea, I will give you an example of how an automation specifically for this situation will look like below. Note that you need to give the Home Assistant Companion App extra permissions to toggle DND on your phone.

# Example automation to turn on DND
- alias: Turn on DND
  description: ''
  trigger:
  - platform: template
    value_template: "{{ 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_paired_devices') }}"
  condition: []
  action:
  - service: notify.mobile_app_YOUR_PHONE
    data:
      message: command_dnd
      title: priority_only
  mode: single
# Example automation to turn off DND
- alias: Turn off DND
  description: ''
  trigger:
  - platform: template
    value_template: "{{ not 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_paired_devices') }}"
  condition: []
  action:
  - service: notify.mobile_app_YOUR_PHONE
    data:
      message: command_dnd
      title: 'off'
  mode: single

Don’t forget to weigh yourself with your smart scale

Most of the smart scales are not paired with your phone. They won’t show up in the bluetooth section of your phone. However, you can find them in the attributes of the sensor under ‘connected_not_paired_devices’. A small change of the template will do the trick.

trigger:
- platform: template
  value_template: "{{ 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_not_paired_devices') }}"

So, what can you do with this trigger, besides playing a drumroll whenever you weigh yourself. 😉 You can use this template in a condition of an automation which reminds you to weigh. You can find an example below. I left out the trigger part, because everyone uses their own method of night mode or specific weighing time.

# Example automation for a weigh reminder
- alias: Weigh reminder
  description: ''
  trigger: []
  condition: []
  action:
  - wait_template: "{{ 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_not_paired_devices') }}"
    timeout: 00:05:00
    continue_on_timeout: true
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ not 'BLUETOOTH_ADDRESS' in state_attr('sensor.BLUETOOTH_SENSOR', 'connected_not_paired_devices') }}"
      sequence:
      - service: notify.mobile_app_YOUR_PHONE
        data:
          message: Do not forget to weigh yourself today.
          title: Weigh reminder
  mode: single

Of course you can do this the other way around and compliment yourself for weighing. 😉

I hope you got some inspiration from these bluetooth ideas. Let me know which bluetooth devices you’ve connected to your phone and which automation you would like to make! 😄