Service control
A service is node-level machinery rather than something the user thinks of as a device, such as time and timezone. ESPRMNeoService and ESPRMNeoServiceParam work almost exactly like their device counterparts, with two differences worth knowing before you use them.
const time = node.services.find((s) => s.name === "Time");
const timezone = time?.params.find((p) => p.id === "TZ");
await timezone?.setValue("Asia/Kolkata");
How services differ from devices
| Device | Service | |
|---|---|---|
| Reached through | node.devices | node.services |
| Parameter carries | deviceName | serviceName |
| Primary parameter | primaryParam | none |
| Cached reads | getParams({ cache }) | always live |
There is no primaryParam on a service, because a service has no single main control. And service.getParams() takes no options; it is always a live read.
Read service parameters
const params = await time?.getParams();
getParams() returns Promise<ESPRMNeoServiceParam[]>, the same instances as service.params, with value updated. It fetches over the best available transport every time; there is no cached mode.
It throws if the parent node reference has been garbage-collected. Keep the node alive for as long as you hold a service.
Write a service parameter
await timezone?.setValue("Asia/Kolkata");
setValue(value) returns Promise<ESPAPIResponse> and behaves exactly as it does on a device parameter, including the caveat that acceptance is not confirmation. See Device control.
You can also address a service through node.setParams(), which takes service names alongside device names in the same payload:
await node.setParams({
Time: { TZ: "Asia/Kolkata" },
});
Identifying a service by type
Names are firmware-chosen; types are stable. Match on type when you need a specific service rather than a specific name:
const time = node.services.find((s) => s.type === "esp.service.time");
A service's type comes straight from the node configuration the firmware publishes, so the set available to you depends on what that node runs.
Related
- Device control — the device equivalent of this page
- Nodes — where services sit in the hierarchy
- Node configuration — where services come from
- Time and timezone — the firmware side of the Time service