Featured image of post Find your phone with Home Assistant

Find your phone with Home Assistant

Create an automation which helps find your phone with Home Assistant.

Introduction

They say a man leaves the house with three things. Those would be wallet, keys and a phone. The catch is, that we are always searching for one of those three things around the house. For me, this is most often my phone. I tend to carry it around with me and misplace it somewhere in the apartment.

This is why I decided to create an automation in Home Assistant that would help me find my phone whenever it’s out of sight.


Implementation

The idea was simple: Trigger a loud sound on the phone after pressing a button on the Home Assistant dashboard. To build this we will need:

  • Home Assistant: Since you are reading this, you probably already have it set up.
  • Home Assistant Companion App: This app is essential for enabling notifications on your phone. You can download it from:

After installing the Companion App, link your phone to Home Assistant. Once connected, your phone will appear in Settings > Devices & Services > Integrations > Mobile App.


Setting up the Home Assistant UI

The UI for this automation consists of a single button. Pressing it triggers the sound notification on your phone, making it quick to locate your device.

Creating the Button Helper

  1. Navigate to Settings > Devices & Services > Helpers in Home Assistant.
  2. Click Create Helper and choose the Button option.
  3. Set a name and an icon that suits the purpose, such as “Find My Phone” with a phone-related icon.
  4. Click Create to save the helper.

Create the find button

Adding the Button to Your Dashboard

  1. Open your preferred dashboard and click Add Card.
  2. Choose the Entities card from the list of card options.
  3. Find the button you just created (e.g., input_button.find_my_phone) and add it to the card.

That is all the UI setup required. Your dashboard should now display a button like this:

Find my phone button


Setting up the Automation

With the button in place, it’s time to set up the automation that sends the notification to your phone. This involves creating an automation in Home Assistant that listens for the button press and triggers a notification.

Creating the Automation

  1. Open Home Assistant and navigate to Settings > Automations & Scenes.
  2. Click Create Automation and select Start with an empty automation.
  3. Switch to the YAML editor and paste the following code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
alias: Find my Phone
description: Automation used to find my phone.
triggers:
  - entity_id:
      - input_button.find_my_phone
    trigger: state
conditions: []
actions:
  - data:
      message: "{{ notification_message }}"
      title: "{{ notification_title }}"
      data:
        ttl: 0
        priority: high
        importance: high
        channel: "{{ notification_channel }}"
    action: "{{ target_device }}"
variables:
  target_device: notify.mobile_app_vlade_poco
  notification_channel: find_my_phone
  notification_title: Find my Phone
  notification_message: Hey phone, someone is looking for you!
mode: single

Customizing the Variables

At the bottom of the YAML, you’ll see a section called variables. Here’s what each variable does and how to adjust it:

  • target_device: The notification target, which should match your phone’s notification service. In this example, notify.mobile_app_vlade_poco refers to my Android phone. Update this to match your device’s identifier.
  • notification_channel: Defines the notification channel on Android. You can leave this as find_my_phone unless you have another channel with the same name. This setting is required in order to customize the default notification sound.
  • notification_title: The title displayed in the notification. Customize it as desired.
  • notification_message: The body of the notification message. Feel free to modify it to make it more fun or specific to you.

Final Steps

Before saving, ensure the entity_id in the triggers section matches the name of your button helper. For example, if you named your button differently, replace input_button.find_my_phone with the correct entity ID.

Testing the Automation

Once everything is set up:

  1. Save the automation.
  2. Return to your dashboard and press the “Find My Phone” button.

Please note that your phone has to be connected to your WIFI for this to work. If all is working correctly, you should see a notification on your phone like this:

Notification preview


Customizing the Notification Sound

You probably noticed that the received notification uses the default notification sound. This is not good enough, since we need a longer lasting sound. We can set this by using Notification channels.

Notification channels are an Android feature that allow you to customize how notifications behave, including their sound, vibration pattern, and priority. Here’s how you can use them to set a distinct sound for your “Find My Phone” notification:

  1. Trigger a Test Notification

    • First, press the button on your Home Assistant dashboard to send a notification to your phone. This ensures that the notification channel (find_my_phone) is created if it doesn’t already exist.
  2. Open Notification Settings

    • Navigate to Settings on your Android phone.
    • Go to Apps and find the Home Assistant app in the list.
    • Tap Notifications to view all notification channels associated with the app.
  3. Locate the Channel

    • Find the notification channel labeled find_my_phone under Notification categories. If you don’t see it immediately, you may need to tap See all or Advanced settings to display all channels.
  4. Customize the Sound

    • Tap on the find_my_phone channel.
    • Choose Sound and select a unique sound from your phone’s library or add a custom sound file.
    • You can also adjust other options, like vibration and visual indicators, to make the notification even more noticeable.
  5. Test the Changes

    • Return to your Home Assistant dashboard and press the button again. Verify that the notification uses your customized sound.

Notification settings Channel settings


Customize the notification delivery method

This is an optional step, but it may help if it takes too long for the notification to be delivered to your phone. Home Assistant Companion app uses Firebase Cloud Messaging (FCM) for notification delivery. I have found WebSockets to be more reliable and instant.

  1. Access App Settings

    • Open the Home Assistant Companion app on your Android phone.
  2. Navigate to Connection Settings

    • Tap the Settings menu (gear icon).
    • Scroll down to the Companion App section.
    • Tap on your Home Assistant server
    • Scroll down and select Persistent Connection.
  3. Enable WebSocket Communication

    • Set the Persistent connection to Always.
  4. Verify the Connection

    • Navigate back to your Home Assistant dashboard and trigger the “Find My Phone” notification again.
    • Confirm that the notification is received promptly, as intended.

1. Companion app settings 2. Home Assistant server settings 3. Persistent connection settings


Conclusion

Having the “Find My Phone” button on my tablet dashboard, right by the apartment door, has been a good solution. Whenever my phone goes missing, it’s just a quick tap away from making some noise and helping me track it down. Rarely a day goes by without me using it.

Thank you for reading this far, I hope it helps you!

comments powered by Disqus