Home Assistant: Music That Follows Me Around the House (Room Tracking)

Home Assistant: Music That Follows Me Around the House (Room Tracking)

One more automation that replaces my manual work. Here’s the scenario: I work from home, I listen to music through my office speakers, and it’s lunchtime. I walk into the kitchen, my music is still playing in the office, and I have to switch it over to the kitchen by hand in the Sonos app. I figured this could be done automatically. Could my home track me and move the music as I go? It turns out it can, and here’s how I did it.

This automation has quite a few prerequisites and moving parts, so bear with me.

The music side runs on Music Assistant. It isn’t tied to one manufacturer either: Sonos, Chromecast, AirPlay, Squeezebox and DLNA speakers can all live in the same system, so you can mix brands around the house and still move the music between them. Mine happen to be Sonos speakers, and Music Assistant is integrated into Home Assistant, so every speaker shows up there as a media player that automations can control. The best part is that Music Assistant can hand the play queue over from one speaker to another mid-song with a single action – and that one action is what the whole automation is built around.

Tracking

First, I need to track myself wherever I go. I could use presence sensors, but they can’t tell which person (or animal) they’ve detected, so that’s a no-go in a multi-person home. The next option would be cameras with face detection – but that’s a bit overkill, and I don’t want cameras indoors, for my family’s privacy. The third option is to carry something that can be detected – and here we go: I already have a smartphone and a Samsung Galaxy Watch 4. I don’t always carry my phone around the house, but the watch is always on my wrist.

The next question: what can detect the watch moving around the house? This one is easy – Bluetooth. I already have a couple of ESP32 Bluetooth proxies running in my house that can detect Bluetooth devices. There’s also an existing HACS integration called Bermuda that does exactly what’s needed: it tracks Bluetooth devices by signal strength.

Step 1: Bluetooth proxies

I won’t go into much detail on this step, as I’ve already covered it in my previous ESP32 Bluetooth Proxy article . The thing to note, though, is to place the proxies strategically. Don’t put one next to a wall shared with another room you want to track – the tracking isn’t perfect, and proxies close to each other with just a wall between them will most likely cause irritating detections in the wrong room.

If you don’t want to use self-made ESPHome Bluetooth proxies, there are also ready-made alternatives. Most Shelly Gen 3 and Gen 4 devices support Bluetooth proxy out of the box, and they expose their data to Home Assistant as well.

Step 2: Setting up the device to track

On most Android phones and watches the BLE MAC address isn’t static, for privacy reasons, so it can’t be used for tracking. There’s another solution, though: the Home Assistant companion app on the watch or phone. Enabling the “BLE Transmitter” in the companion app settings exposes an iBeacon-type object straight to Home Assistant, which can then be used for tracking.

So nothing more is needed – just install the Home Assistant app on the device, configure it and enable the BLE Transmitter. This may work quite differently on Apple devices, but at least on my Android devices it worked perfectly like this.

The biggest issue with tracking the Galaxy Watch 4, or other watches, is its ultra-low-power BLE mode, which can’t be changed (most probably to save the watch battery). I experimented with tracking the watch and noticed that even though it works to some extent, it isn’t tracked very accurately.

The Android phone, on the other hand, has configurable transmitter power. By default it’s set to ultra low, which is similar to the watch and just as bad for tracking. Changing it to medium or high solves all the stability issues, and detection is nearly instant when moving from one BLE proxy to another. Setting the advertise mode to balanced (3 Hz) also improves the accuracy greatly. This obviously has some effect on battery life, but nothing too dramatic as long as you stay at or below medium power and the balanced rate.

I was a bit bummed at first that I couldn’t reliably use the watch, but after thinking about it a bit more, phone tracking is actually even better. When I’m working, my phone sits on my desk – if I pop to the bathroom or grab a drink from the kitchen, I don’t want the music to move for that short time. When I go to have lunch in the kitchen, I take my phone with me, and that’s the whole idea: the music moves to a room where I’m going to stay a bit longer.

Where to enable the transmitter and set the power

On the Android phone, everything is in the companion app:

  1. Open the Home Assistant app and go to Settings → Companion app → Manage sensors.
  2. Scroll down to the Bluetooth sensors and open BLE Transmitter.
  3. Switch Enable sensor on. The phone starts advertising itself as an iBeacon right away.
  4. Set Transmit power to Medium (or High if your proxies are far apart). Leave it at Ultra low and you’ll get the same patchy tracking as the watch.
  5. Set Advertise mode to Balanced (3 Hz). Low latency (10 Hz) is faster still, but costs noticeably more battery.
  6. Note down the UUID, Major and Minor values shown on the same page. Bermuda lists the beacon by these, so you’ll need them in Step 3 to pick the right device.

One extra tip: exclude the Home Assistant app from Android’s battery optimisation. Otherwise Android may put the app to sleep and the beacon quietly stops transmitting, which looks exactly like you’ve left the house.

On a Wear OS watch the same sensor lives in the Home Assistant app on the watch itself, under Settings → Sensors → BLE Transmitter – but as said, the watch keeps its low power BLE regardless of what you pick there.

Step 3: Installing and configuring Bermuda

Bermuda is a HACS integration designed for indoor tracking. It detects your Bluetooth proxies automatically, along with their areas – you just need to set up the devices you want to track: the ones from Step 2.

Installing through HACS

Before you start, make sure HACS is installed and your proxies from Step 1 already show up in Home Assistant. Also give each proxy device an area in Settings → Devices & services → Devices – Bermuda uses those areas as its room names.

  1. Open HACS and search for Bermuda BLE Trilateration.
  2. Open it and click Download.
  3. Restart Home Assistant.
  4. Go to Settings → Devices & services. Bermuda usually shows up as a discovered integration, since it notices your Bluetooth proxies on its own – just click Add. If it doesn’t, use Add integration and search for Bermuda.

Adding a tracked device

  1. In Settings → Devices & services, open Bermuda and click Configure.
  2. Choose Select Devices.
  3. Find your phone’s iBeacon in the list. It’s identified by the UUID, Major and Minor you noted in Step 2.
  4. Tick it and Submit.

Bermuda now creates a device for it with a handful of entities. The ones that matter here are Area, Area Last Seen, a Distance sensor per proxy and a device tracker for home / not home.

Once this is done, you basically have a fully functioning tracking system – except, most probably, for the accuracy. Depending on the devices and BT proxies used, calibration may be necessary. Calibration is done on two levels: 1. global calibration and 2. scanner RSSI calibration.

Shelly devices and ESP32 proxies use different radios and antennas, so they won’t report the same signal strength for a device at the same distance – one may read consistently stronger or weaker than the other. This is exactly what the Scanner RSSI calibration is for: place the tracked device at the same distance from each proxy in turn, and adjust that proxy’s offset until all of them report roughly the same distance. You do this once per proxy, not per tracked device, so it’s worth redoing whenever you add a new Shelly.

Once those two are set properly, the last thing is to set the reference RSSI level per device. Depending on the BLE Transmitter power, the reference value may need to be lowered or raised. Place the tracked device exactly 1 metre from a BT proxy and tune the reference level until Home Assistant shows it at 1 metre.

Step 4: Moving the music around the house

Now that Home Assistant knows which room I’m in, the actual automation is surprisingly short. Music Assistant and corresponding integration for it does the heavy lifting with one action: music_assistant.transfer_queue moves the whole queue from one speaker to another and keeps playing from the same position in the track. The old speaker stops on its own, so there’s no clean-up step needed.

The master switch

First things first – I want to be able to turn the whole thing off. Guests over, kids listening to something in the kitchen while I work, or I just want the music to stay put: one toggle and the automation does nothing.

Create it in Settings → Devices & services → Helpers → Create helper → Toggle and name it Music Follow Me. That gives you input_boolean.music_follow_me, which you can also put on your dashboard.

Use Area Last Seen, not Area

Bermuda gives you two room sensors in my case, and the difference matters a lot here. Area goes to unknown whenever no proxy hears the phone clearly enough – and that happens more often than you’d think, even while sitting still. Area Last Seen keeps the last room it was sure about.

If you trigger on Area, a short dropout (Office → unknown → Office) looks like a room change. With Area Last Seen the sensor only changes when a different room actually picks you up.

Pick the right speaker entities

If you have both the Sonos integration and Music Assistant, every speaker shows up twice in Home Assistant. Make sure you use the Music Assistant ones – in my case they got a _2 suffix, like media_player.office_speaker_2. Open the entity and check which integration it belongs to. While you’re there, check the area too: one of my Music Assistant speakers had ended up in the wrong room.

The automation

alias: Music Follow Me
description: Moves the Music Assistant queue to the room my phone is in.
mode: restart

triggers:
  - trigger: state
    entity_id: sensor.my_phone_area_last_seen
    to: Office
    for: "00:00:03"
    id: to_office
  - trigger: state
    entity_id: sensor.my_phone_area_last_seen
    to: Kitchen
    for: "00:00:03"
    id: to_kitchen

conditions:
  - condition: state
    entity_id: input_boolean.music_follow_me
    state: "on"

actions:
  - choose:
      - alias: Moved to the Office - bring the Kitchen music along
        conditions:
          - condition: trigger
            id: to_office
          - condition: state
            entity_id: media_player.kitchen_speaker_2
            state: playing
        sequence:
          - action: music_assistant.transfer_queue
            target:
              entity_id: media_player.office_speaker_2
            data:
              source_player: media_player.kitchen_speaker_2
              auto_play: true
      - alias: Moved to the Kitchen - bring the Office music along
        conditions:
          - condition: trigger
            id: to_kitchen
          - condition: state
            entity_id: media_player.office_speaker_2
            state: playing
        sequence:
          - action: music_assistant.transfer_queue
            target:
              entity_id: media_player.kitchen_speaker_2
            data:
              source_player: media_player.office_speaker_2
              auto_play: true

Replace sensor.my_phone_area_last_seen with your own Bermuda sensor and the speakers with your own. A few things worth pointing out:

  • It never starts music. Each branch only runs if the other room is actually playing. Walk into the kitchen with nothing on, and nothing happens.
  • It never fights itself. Because the source is always the other room, there’s no “transfer the music to where it already is”.
  • mode: restart means if you change rooms again while it’s still waiting, the newest room wins.

Getting the delay right

The for: delay is the setting you’ll tune the most. I started with 1 second to see it react quickly – and the music moved to the kitchen, back to the office, to the kitchen and back again, four times in 75 seconds. The tracking simply jumps between rooms now and then, and a 1 second delay lets every jump through.

I ended up using a 3 second delay: it feels very quick, and I haven’t noticed any bouncing when I walk in for lunch.

If the music still bounces, try raising the delay a little. If that doesn’t help, the tracking itself probably needs better calibration (Step 3) or another proxy (see below).

Fine-tuning and increasing coverage

Two proxies is the bare minimum, and you’ll notice it. With only Office and Kitchen, any spot that isn’t clearly one of them is a coin flip between the two – and that’s where most of the room-jumping comes from. The easiest fix is more proxies, and this is where Shellys shine: if you already have Shelly Gen 3 or Gen 4 relays or plugs around the house, they’re proxies you’ve already paid for.

My pick for easy coverage: Shelly Plug M Gen3

If you don’t have Shellys around the house yet, the easiest way to add coverage is the Shelly Plug M Gen. It’s a small smart plug with Bluetooth built in, so adding a proxy to a room really is just plugging it into the wall – no wiring, no firmware flashing and no ESP32 board to build. Once it’s on your Wi-Fi and added to Home Assistant through the Shelly integration, turn on Bluetooth scanning in the device’s options, and Bermuda picks it up as a new scanner. You can still plug a lamp or anything else into it, so it doesn’t cost you a socket either. I run one myself and it works like a charm – setting it up as a Bluetooth proxy was very easy.

At around 13€ at the time of writing, it’s hard to beat as a ready-made proxy. It also comes in 2- and 4-packs if you want to cover several rooms in one go.

Two things to keep in mind. Shelly proxies only listen to Bluetooth advertisements and don’t make active connections like an ESPHome proxy can – but listening is all Bermuda needs, so for room tracking it makes no difference. And since it’s a plug, you’re limited to where your sockets are: if the only socket in a room is on a wall shared with the next room, pick another spot or use an extension cable.

A few things I learned while adding them:

  • At least one proxy per room you want to track. Bermuda can only name a room that has a proxy in it.
  • A proxy in the hallway helps even if you never play music there. It gives the tracking somewhere to land when you’re between rooms, instead of guessing between the two rooms on either side.
  • Keep them away from shared walls, same as in Step 1.
  • Redo the Scanner RSSI calibration for every new proxy, especially when mixing Shellys and ESP32s.
  • Check Bermuda’s max area radius. A device further than this from every proxy gets no room at all. I run it at 6 metres; with more proxies around you can keep it tight, with fewer you may need to raise it.

Adding a room to the automation itself is just one more trigger and one more branch per room. With more than three or four rooms that gets repetitive, and it’s worth switching to a version that maps rooms to speakers in one list.


Verdict and what’s next

Once Home Assistant knows which room I’m in, music is only the first thing that can use it. The next idea on my list is a phone dashboard that changes with the room. Home Assistant dashboards can show or hide a card or a whole section based on an entity’s state, so a section can simply be visible only when my Area Last Seen sensor says Kitchen.

In the kitchen that would mean timers, the shopping list and the kitchen lights up top. In the office it would be the desk lamp, the music controls and the heating. Add a user condition to the same card and it only changes for me, while everyone else in the family keeps their normal dashboard.

Leave a Reply

Your email address will not be published. Required fields are marked *