Skip to content

Prefix service names with the accessory name - #98

Open
tillkruss wants to merge 1 commit into
michaelahern:mainfrom
tillkruss:fix/unique-service-names
Open

Prefix service names with the accessory name#98
tillkruss wants to merge 1 commit into
michaelahern:mainfrom
tillkruss:fix/unique-service-names

Conversation

@tillkruss

Copy link
Copy Markdown

Problem

Every service this plugin creates is named with a hardcoded literal — 'Temp', 'Humidity', 'Battery', 'Air Quality', 'CO2', 'Air Pressure', 'Radon' — so two Airthings devices on the same bridge publish services with identical names.

That makes them indistinguishable in Homebridge UI. @homebridge/hap-client derives each service's nameBasedUniqueId as:

sha256([
  service.instance.name,                      // "homebridge"
  service.instance.username,                  // bridge MAC
  service.accessoryInformation.Manufacturer,  // "Airthings"
  service.serviceName,                        // "Temp"
  service.uuid.slice(0, 8),                   // service type
].join('|'))

The serial number isn't an input. With two Airthings devices on one bridge, all five components match, so both devices' services hash to the same value. Homebridge UI keys custom names on that hash, with two visible consequences:

  • Renaming one device's tile silently renames the other's.
  • The two services collapse into a single tile, so one device's sensors go missing from the room they were placed in.

All seven services collide. I hit this with a View Plus and a Wave Radon on one bridge — every rename applied to both devices, which looked like the UI was failing to save.

Fix

Prefix each service name with config.name, which is already used for the accessory's Name characteristic (line 100) and is therefore in scope and guaranteed set (the plugin defaults it upstream).

Verification

Computing nameBasedUniqueId for both of my devices, before and after:

Service Before After
Battery ❌ collides c5583c8a… vs 636dfcea…
Air Quality ❌ collides 19f83c0b… vs 7c5b7ce1…
Temp ❌ collides 763dc51f… vs eef5d29e…
Humidity ❌ collides c36e58e0… vs 61324296…
CO2 ❌ collides cb7e57d4… vs 02aefa4e…
Air Pressure ❌ collides 74aae75b… vs 5b1c6400…
Radon ❌ collides e88488f2… vs bf0604dc…

7/7 collide before, 0/7 after. npm run build (lint + tsc) passes clean.

Compatibility

uniqueId hashes username + aid + iid + type, none of which change here, so existing Homebridge UI room layouts and HomeKit pairings are preserved. This is not a bridge-identity change.

The user-visible effect is that service names in the Home app become e.g. "Blue Room View Plus Temp" instead of "Temp". Names users have set themselves in the Home app take precedence and are unaffected. If you'd rather not change this for existing single-device users, I'm happy to put it behind a config flag or apply the prefix only when more than one accessory is configured — just say which you'd prefer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SPgfBrVBq5w5useKSLXR14

HomeKit service names are currently hardcoded literals ('Temp',
'Humidity', 'Battery', ...), identical across every accessory this
plugin creates. Running two Airthings devices on one bridge therefore
produces services that are indistinguishable to downstream consumers.

Homebridge UI is affected: @homebridge/hap-client derives a service's
nameBasedUniqueId as

    sha256([instance.name, instance.username, Manufacturer,
            serviceName, uuid.slice(0, 8)].join('|'))

The serial number is not an input, so with two Airthings devices on the
same bridge all five components match and both devices' services hash
identically. The UI keys custom names on that hash, so renaming one
device's "Temp" tile silently renames the other's, and the two collapse
into a single tile. All seven services collide.

Prefixing with config.name — already used for the accessory's Name
characteristic — makes serviceName unique per accessory and resolves
all seven collisions. uniqueId is unaffected (it hashes aid/iid), so
existing Homebridge UI room layouts and HomeKit pairings are preserved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 25, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the HomeKit service display names created by the Airthings Homebridge plugin so they’re unique per accessory instance, preventing Homebridge UI service collisions when multiple Airthings devices are bridged.

Changes:

  • Prefixes each created service name with config.name (the accessory name) for Battery, Air Quality, Temperature, Humidity, CO2, Air Pressure, and Radon services.
  • Keeps accessory identity stable (no changes to serial/UUID/subtype usage in the plugin code path shown).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants