timed-run
timed-run - run a device for a chosen time, then stop it.
timed-run - run a device for a chosen time, then stop it.
"Heat for 30 minutes", "run the fountain pump for 2 minutes": the device has no timer of its own, so the hub keeps one. runFor turns the device on and records a deadline; cancel switches the device off and forgets the deadline, and the device being switched off by hand just forgets it; at the deadline the hub issues the off once.
The deadline is DURABLE: it is a row in the records store, so a hub restart neither loses a pending off nor leaves the device running past its time. At boot a deadline already past sends the off once; a future one is re-armed.
What a device may be run for, and for how long at most, is per device type and role ({ so a request above it is REFUSED with a typed reason, never clamped.
At a glance
| Capability | timed-run |
| Provided by | An addon wraps the device and provides it. It is bound to a device through the device bindings and can be bound automatically to compatible devices. |
| Active providers per device | one |
| Device types | switch, pet-fountain |
| Device roles | switch: switch-heater |
| Device settings | Yes: its settings section on the device page is built from this capability's methods. |
| Source | packages/types/src/capabilities/timed-run.cap.ts |
Methods
Every method takes the device id (deviceId) to address the device; the input tables below list the other fields.
| Method | Kind | Required of a provider | Access |
|---|---|---|---|
getOptions | query | yes | default |
setSettings | mutation | yes | admin |
runFor | mutation | yes | protected |
cancel | mutation | yes | protected |
getOptions
query
Input
No fields besides deviceId.
Output
What the settings form needs: the unit, the bounds and the type's default.
| Field | Type | Required | Description |
|---|---|---|---|
unit | "s" | "min" | yes | |
maxDuration | number | yes | The longest run, in unit. |
defaultDuration | number | yes |
setSettings
mutation
The one-tap run of this device. A duration above the type's maximum is REFUSED (thrown), like runFor: the maximum is a safety bound.
Input
| Field | Type | Required | Description |
|---|---|---|---|
settings | { quickRunDuration?: number | null } | yes |
Output
Nothing.
runFor
mutation
Turn the device on and arm its off. A run already armed is replaced (the new deadline wins). Refuses with a typed reason above the type's maximum.
Input
| Field | Type | Required | Description |
|---|---|---|---|
duration | number | yes | |
unit | "s" | "min" | yes |
Output
{ ok: true; activeUntil: number } | { ok: false; reason: "unsupported-device" | "over-max" | "command-failed"; maxSeconds: number | null }
Actions (offered in automations and on device cards)
| Action | Label | Sets |
|---|---|---|
timedRun.runForMinutes | Run for minutes | |
timedRun.runForSeconds | Run for seconds |
cancel
mutation
Stop the run: switch the device off (once) and forget the pending off. Nothing armed: nothing is sent.
Input
No fields besides deviceId.
Output
Nothing.
Actions (offered in automations and on device cards)
| Action | Label | Sets |
|---|---|---|
timedRun.cancel | Cancel the timer |
Runtime state
The state Dominevo keeps for each device with this capability, readable without calling the provider.
| Field | Type | Required | Description |
|---|---|---|---|
activeUntil | number | null | yes | Epoch ms the pending off is due; null while nothing is armed. |
requestedBy | string | null | yes | Who asked for the run (a user id or an addon id); null when nothing is armed or it did not say. |
quickRun | { duration: number; unit: "s" | "min" } | null | yes | The one-tap run of THIS device: what a "Run" button on any surface starts. null when the device is gone or its type has no timed run; a status from before this field existed has none, and a surface falls back to the type's default. |
lastFetchedAt | number | yes |