Statistic Selector
The Statistic selector provides a picker for Home Assistant statistics.
Options
All statistic selectors accept these common metadata options:
default?: string- Default selected statisticdescription?: string- Human-readable description shown in the UIrequired?: boolean- Whether the field must be provided
Statistic-specific options (from ServiceListSelector["statistic"]):
multiple?: boolean- Whentrue, allows selecting multiple statistics (returnsstring[])
Return Type
stringwhenmultipleis not set orfalsestring[]whenmultiple: true
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: "Query a statistic",
fields: {
// Statistic selector
statistic: ServiceField.Statistic({
description: "Statistic to query",
required: true,
}),
},
},
async data => {
// data.statistic is typed as: string
logger.info(`Querying statistic: ${data.statistic}`);
}
);
}