Target Selector
The Target selector provides a target picker that can select entities or devices.
⚠️ Note: This selector provides similar functionality to the
targetproperty on service creation, but as a field selector. For more flexible target selection that supports multiple target types simultaneously (entity_id, device_id, label_id, area_id), use thetargetproperty instead. See Target Selector for details.
Options
All target selectors accept these common metadata options:
default?: PICK_ENTITY | TDeviceId- Default selected targetdescription?: string- Human-readable description shown in the UIrequired?: boolean- Whether the field must be provided
Target-specific options (from ServiceListSelector["target"]):
entity?: EntityFilterSelector | EntityFilterSelector[]- Entity filter selector(s) to filter targets by entity (mutually exclusive withdevice)device?: DeviceFilterSelector | DeviceFilterSelector[]- Device filter selector(s) to filter targets by device (mutually exclusive withentity)
Return Type
The return type is PICK_ENTITY | TDeviceId.
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: "Target an entity or device",
fields: {
// Target selector
target: ServiceField.Target({
description: "Entity or device to target",
required: true,
}),
},
},
async data => {
// data.target is typed as: PICK_ENTITY | TDeviceId
logger.info(`Targeting: ${data.target}`);
}
);
}