Skip to content

sdk/homekit/unifi-protect: add USL-Smoke smoke and carbon monoxide alarms - #2233

Open
stalinCCCP415 wants to merge 2 commits into
koush:mainfrom
stalinCCCP415:unifi-protect-usl-smoke
Open

stalinCCCP415 wants to merge 2 commits into
koush:mainfrom
stalinCCCP415:unifi-protect-usl-smoke

Conversation

@stalinCCCP415

Copy link
Copy Markdown
Contributor

Why

The USL-Smoke (UniFi SuperLink smoke and carbon monoxide detector) is reported by Protect as a sensor. Today the plugin discovers it as a generic sensor (contact, alarm sound, motion, temperature, humidity, leak) and never reads its alarm state, so it cannot raise a smoke or carbon monoxide alarm in HomeKit. Scrypted also has no interface to carry that state.

What

  • sdk: add SmokeSensor (smokeDetected) and CarbonMonoxideSensor (carbonMonoxideDetected) next to FloodSensor. Python types are regenerated; no version bump.
  • homekit: map the two interfaces to the HAP SmokeSensor and CarbonMonoxideSensor services on sensor accessories.
  • unifi-protect:
    • Identify the detector by model (marketName of USL Smoke, or a type starting with USL-Smoke-). The UP Sense advertises the same alarm types and reports an idle smokeStatus, so the model is the only reliable signal.
    • Expose SmokeSensor and CarbonMonoxideSensor according to featureFlags.alarmTypes (smoke, CO), instead of the generic sensor interfaces.
    • Set state from smokeStatus.smokeAlarm and smokeStatus.coAlarm. While smokeStatus is null the last known state is kept, so a dropout cannot clear an active alarm.
    • Other sensors are unchanged.

The model rule and field names follow the USL Smoke support in hjdhjd/homebridge-unifi-protect. The plugin stays on unifi-protect@4.27.5, whose typings lack these fields, so they are read through a small local type.

Not included

Detector fault and end-of-life flags, battery and tamper status.

Testing

  • The SDK builds, and npm run build in plugins/unifi-protect succeeds.
  • The HomeKit plugin depends on a HAP-NodeJS checkout outside the repo, so it was typechecked against the public @homebridge/hap-nodejs 2.3.0 instead: no errors in src/types/sensor.ts.
  • A fixture-based check of model detection, interface selection and state mapping passes.
  • Not tested against a physical USL-Smoke.

…arms

Add SmokeSensor and CarbonMonoxideSensor interfaces to the SDK and map them to the HAP smoke and carbon monoxide sensor services. The UniFi Protect plugin identifies the USL-Smoke by model, exposes the alarm types it advertises, and sets their state from smokeStatus.
@koush

koush commented Nov 21, 2026

Copy link
Copy Markdown
Owner

I think these interfaces already exist? did you check? I swear I added these at some point.

@stalinCCCP415

Copy link
Copy Markdown
Contributor Author

The two interfaces do not appear to exist in the current Scrypted SDK.

I checked sdk/types/src/types.input.ts, the ScryptedInterface enumeration, the generated Python SDK definitions, and the published SDK documentation. None currently defines SmokeSensor or CarbonMonoxideSensor.

I believe the confusion may be with the existing HAP-NodeJS HomeKit services, Service.SmokeSensor and Service.CarbonMonoxideSensor. Those services already exist, but Scrypted does not currently expose corresponding device interfaces.

The purpose of this PR is to add those missing Scrypted interfaces and map them to the existing HomeKit services.

@koush

koush commented Nov 22, 2026

Copy link
Copy Markdown
Owner

PM10Sensor = "PM10Sensor",
PM25Sensor = "PM25Sensor",
VOCSensor = "VOCSensor",
NOXSensor = "NOXSensor",
CO2Sensor = "CO2Sensor",

I found these, and am remembering that I then added this:

export interface Sensors {
sensors: Record<string, Sensor>;
}

I think Sensors may work. can implement that and set the relevant state in sensors dict, and HomeKit can check that to see which sensors are implemented. I want to avoid adding more interfaces to the sdk. just need to settle on standard key/values so like sensors = {
co: somevalueforcarbonmonoxize
}

etc.

@stalinCCCP415

Copy link
Copy Markdown
Contributor Author

Thank you for the feedback. Anything you'd prefer I change or update, or are you planning to take it from here?

@koush

koush commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thank you for the feedback. Anything you'd prefer I change or update, or are you planning to take it from here?

propose some Sensors keys, and wire those into HomeKit instead.

… new SDK interfaces

Per review feedback, drop the SmokeSensor and CarbonMonoxideSensor SDK
interfaces and use the existing generic Sensors interface with standard
keys: `smoke` and `co`, value 1 when the alarm is active and 0 otherwise.

- unifi-protect: the USL-Smoke implements Sensors and populates the keys
  from featureFlags.alarmTypes, so they exist before the first smokeStatus
  arrives. The last known value is kept while smokeStatus is null.
- homekit: map the smoke and co keys to the HAP SmokeSensor and
  CarbonMonoxideSensor services, and skip devices whose only supported
  interface is Sensors with no keys HomeKit understands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WiS3A3J6W395CwrVv8AXs7

This branch has not been deployed

No deployments
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.

3 participants