Skip to content

@camera.ui/sdk / sensor / BinarySensor

Abstract Class: BinarySensor<TProperties, TStorage> ​

Defined in: sensor/binary.ts:16

Base of the sensors that report one condition as on or off, such as smoke, a leak or an open contact. A subclass only sets its type.

Extends ​

Extended by ​

Type Parameters ​

TProperties ​

TProperties extends BinarySensorProperties = BinarySensorProperties

TStorage ​

TStorage extends object = Record<string, any>

Constructors ​

Constructor ​

new BinarySensor<TProperties, TStorage>(name, options?): BinarySensor<TProperties, TStorage>

Defined in: sensor/binary.ts:22

Parameters ​

name ​

string

options? ​

SensorOptions

Returns ​

BinarySensor<TProperties, TStorage>

Overrides ​

Sensor.constructor

Properties ​

category ​

readonly category: Sensor = SensorCategory.Sensor

Defined in: sensor/binary.ts:20

Category of the sensor: detection sensor, control, trigger or info.

Overrides ​

Sensor.category


name ​

readonly name: string

Defined in: sensor/base.ts:303

Name the plugin gave the sensor.

Inherited from ​

Sensor.name


onAssignmentChanged ​

readonly onAssignmentChanged: Observable<readonly string[]>

Defined in: sensor/base.ts:337

Emits the camera id list whenever the user changes the sensor's camera assignments.

Inherited from ​

Sensor.onAssignmentChanged


onCapabilitiesChanged ​

readonly onCapabilitiesChanged: Observable<string[]>

Defined in: sensor/base.ts:329

Emits the full capability list whenever it changes.

Inherited from ​

Sensor.onCapabilitiesChanged


onConnectedChanged ​

readonly onConnectedChanged: Observable<boolean>

Defined in: sensor/base.ts:339

Emits when the connected state changes.

Inherited from ​

Sensor.onConnectedChanged


onDeviceInfoChanged ​

readonly onDeviceInfoChanged: Observable<SensorDevice | undefined>

Defined in: sensor/base.ts:341

Emits the device whenever the sensor joins or leaves one, or its device, names or main-sensor role change.

Inherited from ​

Sensor.onDeviceInfoChanged


onPropertyChanged ​

readonly onPropertyChanged: Observable<PropertyChangeOf<TProperties>>

Defined in: sensor/base.ts:327

Emits on every property change.

Inherited from ​

Sensor.onPropertyChanged


onPropertySpecsChanged ​

readonly onPropertySpecsChanged: Observable<Readonly<Record<string, SensorPropertySpec>>>

Defined in: sensor/base.ts:343

Emits the property specs whenever the plugin changes them.

Inherited from ​

Sensor.onPropertySpecsChanged


type ​

abstract readonly type: SensorType

Defined in: sensor/base.ts:299

Type of the sensor, fixed per sensor class.

Inherited from ​

Sensor.type

Accessors ​

address ​

Get Signature ​

get address(): string | undefined

Defined in: sensor/base.ts:380

Current address at the source, e.g. a Home Assistant entity id. Display only.

Returns ​

string | undefined

Inherited from ​

SegmenterSensor.address


assignedCameraIds ​

Get Signature ​

get assignedCameraIds(): readonly string[]

Defined in: sensor/base.ts:413

Ids of the cameras the user assigned the sensor to.

Returns ​

readonly string[]

Ids of the cameras the user assigned the sensor to.

Inherited from ​

Sensor.assignedCameraIds


assignmentLocked ​

Get Signature ​

get assignmentLocked(): boolean

Defined in: sensor/base.ts:417

Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.

Returns ​

boolean

Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.

Inherited from ​

Sensor.assignmentLocked


capabilities ​

Get Signature ​

get capabilities(): TCapability[]

Defined in: sensor/base.ts:438

Capabilities the sensor advertises.

Returns ​

TCapability[]

Set Signature ​

set capabilities(value): void

Defined in: sensor/base.ts:443

Set capabilities, deduplicated, and notify backend plus local listeners.

Parameters ​
value ​

TCapability[]

Returns ​

void

Capabilities the sensor advertises.

Inherited from ​

Sensor.capabilities


connected ​

Get Signature ​

get connected(): boolean

Defined in: sensor/base.ts:409

Whether the sensor is registered and its plugin is connected.

Returns ​

boolean

Whether the sensor is registered and its plugin is connected.

Inherited from ​

Sensor.connected


detected ​

Get Signature ​

get detected(): boolean

Defined in: sensor/binary.ts:29

Whether the sensor currently detects its condition.

Returns ​

boolean


deviceInfo ​

Get Signature ​

get deviceInfo(): SensorDevice | undefined

Defined in: sensor/base.ts:392

Device the sensor belongs to, undefined without one and for a camera's own sensor.

Returns ​

SensorDevice | undefined

Device the sensor belongs to, undefined without one and for a camera's own sensor.

Inherited from ​

Sensor.deviceInfo


displayName ​

Get Signature ​

get displayName(): string

Defined in: sensor/base.ts:384

Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.

Returns ​

string

Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.

Inherited from ​

Sensor.displayName


id ​

Get Signature ​

get id(): string

Defined in: sensor/base.ts:361

Entity id of the sensor, provisional on a new sensor until registration.

Returns ​

string

Entity id of the sensor, provisional on a new sensor until registration.

Inherited from ​

Sensor.id


isAssigned ​

Get Signature ​

get isAssigned(): boolean

Defined in: sensor/base.ts:405

Whether the sensor is assigned to at least one camera.

Returns ​

boolean

Inherited from ​

SegmenterSensor.isAssigned


nativeId ​

Get Signature ​

get nativeId(): string | undefined

Defined in: sensor/base.ts:365

Durable identity the plugin supplied, e.g. an upstream device id.

Returns ​

string | undefined

Durable identity the plugin supplied, e.g. an upstream device id.

Inherited from ​

Sensor.nativeId


origin ​

Get Signature ​

get origin(): string | undefined

Defined in: sensor/base.ts:370

Source system the sensor was imported from, e.g. 'homeassistant'.

Returns ​

string | undefined

Inherited from ​

SegmenterSensor.origin


pluginId ​

Get Signature ​

get pluginId(): string | undefined

Defined in: sensor/base.ts:421

Id of the plugin that owns the sensor, set at registration.

Returns ​

string | undefined

Id of the plugin that owns the sensor, set at registration.

Inherited from ​

Sensor.pluginId


primary ​

Get Signature ​

get primary(): boolean

Defined in: sensor/base.ts:396

Whether the sensor is the main sensor of its device, called like the device when it stands alone.

Returns ​

boolean

Whether the sensor is the main sensor of its device, called like the device when it stands alone.

Inherited from ​

Sensor.primary


propertySpecs ​

Get Signature ​

get propertySpecs(): Readonly<Record<string, SensorPropertySpec>>

Defined in: sensor/base.ts:400

Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.

Returns ​

Readonly<Record<string, SensorPropertySpec>>

Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.

Inherited from ​

Sensor.propertySpecs


props ​

Get Signature ​

get protected props(): Readonly<TProperties>

Defined in: sensor/base.ts:729

Read-only view of the property values.

Returns ​

Readonly<TProperties>

Inherited from ​

Sensor.props


shortName ​

Get Signature ​

get shortName(): string

Defined in: sensor/base.ts:388

Name inside its device, the same as displayName for a sensor without a device.

Returns ​

string

Name inside its device, the same as displayName for a sensor without a device.

Inherited from ​

Sensor.shortName


sourceState ​

Get Signature ​

get sourceState(): SensorSourceState | undefined

Defined in: sensor/base.ts:375

State of the source behind an adopted sensor, as reported with setSourceState().

Returns ​

SensorSourceState | undefined

Inherited from ​

SegmenterSensor.sourceState


storage ​

Get Signature ​

get storage(): DeviceStorage<TStorage>

Defined in: sensor/base.ts:426

Per-sensor storage. Throws before registration.

Returns ​

DeviceStorage<TStorage>

Inherited from ​

Sensor.storage


storageSchema ​

Get Signature ​

get storageSchema(): JsonSchema[]

Defined in: sensor/base.ts:434

JSON schema of the per-sensor settings. Override it to get a settings UI.

Returns ​

JsonSchema[]

Inherited from ​

SegmenterSensor.storageSchema

Methods ​

getValue() ​

Call Signature ​

getValue<K>(property): TProperties[K] | undefined

Defined in: sensor/base.ts:467

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Type Parameters ​
K ​

K extends string | number | symbol

Parameters ​
property ​

K

Returns ​

TProperties[K] | undefined

Inherited from ​

Sensor.getValue

Call Signature ​

getValue(property): unknown

Defined in: sensor/base.ts:468

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Parameters ​
property ​

string

Returns ​

unknown

Inherited from ​

Sensor.getValue


getValues() ​

getValues(): Readonly<TProperties>

Defined in: sensor/base.ts:484

Get a read-only snapshot of all property values.

Returns ​

Readonly<TProperties>

Shallow copy of every property currently held by the sensor.

Example ​

ts
const snapshot = sensor.getValues();
console.log(snapshot);

Inherited from ​

Sensor.getValues


hasCapability() ​

hasCapability(capability): boolean

Defined in: sensor/base.ts:510

Check whether the sensor advertises a capability.

Parameters ​

capability ​

string

Capability flag to look for.

Returns ​

boolean

True if the sensor currently advertises it.

Example ​

ts
const dimmable = sensor.hasCapability('brightness');

Inherited from ​

Sensor.hasCapability


onStart() ​

protected onStart(): void | Promise<void>

Defined in: sensor/base.ts:818

Lifecycle hook, called once the sensor is registered and live (storage and RPC are wired up). Override it to start work whose lifetime matches the sensor's: polling loops, event subscriptions, timers.

Errors thrown here are swallowed, not logged. Handle failures inside the override. Paired 1:1 with onStop, which runs on removal, plugin shutdown or cleanup.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStart(): void {
  this._timer = setInterval(() => this.poll(), 5_000);
}

Inherited from ​

Sensor.onStart


onStop() ​

protected onStop(): void | Promise<void>

Defined in: sensor/base.ts:831

Counterpart of onStart: tear down whatever it started, such as timers, subscriptions and external resources.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStop(): void {
  if (this._timer) clearInterval(this._timer);
}

Inherited from ​

Sensor.onStop


setAddress() ​

setAddress(address): void

Defined in: sensor/base.ts:543

Report the sensor's current address at the source, e.g. after a Home Assistant entity was renamed. The identity (nativeId) stays.

Parameters ​

address ​

string

Current address at the source

Returns ​

void

Example ​

typescript
sensor.setAddress(entry.entity_id);

Inherited from ​

Sensor.setAddress


setDetected() ​

setDetected(value): void

Defined in: sensor/binary.ts:43

Report whether the condition is currently detected.

Parameters ​

value ​

boolean

True while the condition is detected.

Returns ​

void

Example ​

ts
sensor.setDetected(true);

setDeviceInfo() ​

setDeviceInfo(device, options?): void

Defined in: sensor/base.ts:566

Put the sensor into a device, or take it out with undefined. Sensors of this plugin that report the same DeviceInfo.id form one device. Pass the device in the constructor options when it is known there, call this for what changes later: a new firmware, a rename at the source. Only a change reaches the host. Ignored for a sensor added with camera.addSensor(), its camera is its device.

Parameters ​

device ​

DeviceInfo | undefined

Device at the source, undefined to leave the current one

options? ​

SetDeviceInfoOptions

Whether this sensor is the device's main sensor

Returns ​

void

Example ​

typescript
sensor.setDeviceInfo({ id: hub.serial, name: hub.name, manufacturer: 'Acme', firmware: hub.version }, { primary: true });

Inherited from ​

Sensor.setDeviceInfo


setDisplayName() ​

setDisplayName(value): void

Defined in: sensor/base.ts:459

Set the display name (the only mutable identifier on a sensor).

Parameters ​

value ​

string

Human-readable label shown in the UI.

Returns ​

void

Example ​

ts
sensor.setDisplayName('Front Door Motion');

Inherited from ​

Sensor.setDisplayName


setPropertySpec() ​

setPropertySpec<K>(property, spec): void

Defined in: sensor/base.ts:591

Narrow or describe one property for this device: a range and step, the enum values it supports, the choices it offers with their names, a text limit. The host rejects a command outside it before it reaches the plugin. Pass it in the constructor options when it is known there, call this for what changes later. Only a change reaches the host.

Type Parameters ​

K ​

K extends string

Parameters ​

property ​

K

Property to describe

spec ​

PropertySpecOverride | undefined

What the device accepts, undefined to follow the type's spec again

Returns ​

void

Example ​

typescript
alarm.setPropertySpec(SecuritySystemProperty.TargetState, {
  values: [SecuritySystemState.AwayArm, SecuritySystemState.StayArm, SecuritySystemState.Disarmed],
});

Inherited from ​

Sensor.setPropertySpec


setSourceState() ​

setSourceState(state): void

Defined in: sensor/base.ts:526

Report what the source behind this sensor looks like right now. The host shows the state with its reason on the sensors page and never deletes on it. Only meaningful for adopted sensors.

Parameters ​

state ​

SensorSourceState

Current source state

Returns ​

void

Example ​

typescript
sensor.setSourceState(registryHasEntity ? 'connected' : 'removed');

Inherited from ​

Sensor.setSourceState


updateModelSpec() ​

updateModelSpec(): void

Defined in: sensor/base.ts:748

Re-announces the model spec, e.g. once the models finished loading.

The spec a detector reports at registration is what it knows at that moment: models that load in the background are missing from it. Call this after loading, the server replaces its copy.

Returns ​

void

Example ​

typescript
async onStart(): Promise<void> {
  await this.loadModel();
  this.updateModelSpec();
}

Inherited from ​

Sensor.updateModelSpec