Entity Selector
The Entity selector provides an entity picker that can be filtered by domain and/or integration.
⚠️ Note: This selector can provide part of the functionality of the
targetproperty (specificallyentity_id), but for more flexible target selection that supports multiple target types simultaneously, use thetargetproperty instead. See Target Selector for details.
Options
All entity selectors accept these common metadata options:
default?: PICK_ENTITY | PICK_FROM_PLATFORM<...>- Default selected entitydescription?: string- Human-readable description shown in the UIrequired?: boolean- Whether the field must be provided
Entity-specific options (from ServiceListSelector["entity"]):
domain?: ALL_DOMAINS | ALL_DOMAINS[]- Filter entities by domain(s) (e.g.,"light",["button", "sensor"])integration?: TPlatformId- Filter entities by integration/platform. When provided withdomain, usesPICK_FROM_PLATFORMtypingdevice_class?: string | string[]- Filter entities by device classsupported_features?: string | string[]- Filter entities by supported featuresmultiple?: boolean- Whentrue, allows selecting multiple entities (returns array)reorder?: boolean- Whether entities can be reorderedfilter?: EntityFilterSelector | EntityFilterSelector[]- Additional entity filter selector(s)include_entities?: PICK_ENTITY | PICK_ENTITY[]- Entity ID(s) to include in the selector (mutually exclusive withexclude_entities)exclude_entities?: PICK_ENTITY | PICK_ENTITY[]- Entity ID(s) to exclude from the selector (mutually exclusive withinclude_entities)
Return Type
The return type depends on the options provided:
- With
integrationanddomain:PICK_FROM_PLATFORM<INTEGRATION, ExtractDomainUnion<DOMAIN>>or array - With only
domain:PICK_ENTITY<DOMAIN>or array - Without filters:
PICK_ENTITYor array
Example
import { TServiceParams } from "@digital-alchemy/core";
import { ServiceField } from "@digital-alchemy/synapse";
export function SynapseServiceCreate({
synapse,
context,
logger,
}: TServiceParams) {
synapse.service.create(
{
context,
description: "Control a light entity",
fields: {
// Entity selector filtered to light domain
light_entity: ServiceField.Entity({
domain: "light",
description: "Light to control",
required: true,
}),
},
},
async data => {
// data.light_entity is typed as: PICK_ENTITY<"light">
logger.info(`Controlling light: ${data.light_entity}`);
}
);
}