Bento Spaces docs

Bento Spaces documentation

16 — Automations

Climate rules that run on the server, not in a tab. The first slice is a thermostat for connector-backed ACs: profiles own the thresholds, a rule picks one profile for one device, and a minute tick decides whether to power the unit on or off.

Where it lives

PieceFile
profile/rule modelsource/Bento.Api/Models/Automations.cs
validationsource/Bento.Api/Services/AutomationValidator.cs
decision logic (pure)source/Bento.Api/Services/AutomationEngine.cs
connector IO, logging, ticksource/Bento.Api/Services/AutomationRunner.cs
storagesource/Bento.Api/Storage/AutomationStore.cs → data/users/{id}/automations.json
HTTPsource/Bento.Api/Endpoints/AutomationEndpoints.cs
UIweb/src/features/automations/AutomationsDialog.js

Profiles and rules

{
  "profiles": [
    { "id": "p_cold", "name": "Cold", "season": "heat", "min": 21, "max": 24, "cooldownMinutes": 10 },
    { "id": "p_hot",  "name": "Hot",  "season": "cool", "min": 23, "max": 26, "cooldownMinutes": 10 }
  ],
  "rules": [
    {
      "id": "r_living",
      "name": "Living",
      "connectorId": "c_…",
      "deviceId": "living",
      "enabled": true,
      "defaultProfileId": "p_cold",
      "overrideMinutes": 60,
      "season": {
        "winterFrom": "10-15", "winterTo": "04-15",
        "winterProfileId": "p_cold", "summerProfileId": "p_hot"
      },
      "weather": {
        "metric": "outdoorTemp",
        "brackets": [
          { "max": 15, "profileId": "p_cold" },
          { "profileId": "p_hot" }
        ]
      }
    }
  ]
}

deviceId is optional: without it the rule talks to a single-device gree-ac bridge (/api/state, /api/power); with it, to one child (/api/devices/{id}/…).

How a tick decides

Order matters, and every branch is deterministic:

  1. Disabled → nothing.
  2. Offline (online: false) → nothing.
  3. No currentTemp → nothing. A stale or absent sensor is never a reason to guess.
  4. Manual override — the observed power differs from the previous observation and we did
  5. not command in the last two minutes. The rule pauses for overrideMinutes (default 60).
  6. Paused → nothing until the pause ends.
  7. Profile — first weather bracket that matches, else the seasonal window, else
  8. defaultProfileId. A profile switch alone never sends a command; the next tick compares the
  9. new thresholds against the current reading.
  10. Hysteresis — heat: on at/below min, off at/above max; cool: mirrored. Between the
  11. two, nothing. That gap is the point.
  12. Cooldown — no second command inside cooldownMinutes, even if the reading moved.
  13. Otherwise POST …/power and log it.

Weather brackets are ordered, first match wins, the last entry (no max) is the fallback. A boundary is damped by 1°: at 15.0/15.1 the previous bracket stays. Only a one-bracket crossing is damped; a jump is real weather.

The seasonal window wraps the year (15 Oct → 15 Apr). Dates are MM-DD and compared in UTC. GET /api/automations/preview runs the same engine against a supplied reading and clock, which is what the API smoke tests use to prove every branch.

Running

AutomationRunner is a hosted service: once a minute, for every account with rules, it reads each enabled rule's device, evaluates and (if needed) commands. It starts 20 s after boot.

The dialog's Run now calls the same path immediately, so "why did it do that?" is answerable without waiting for the tick.

Limits

API

MethodPathNotes
GET/api/automations{ rev, profiles, rules, state }; account only
PUT/api/automationsreplace profiles and rules; 422 with errors[]
POST/api/automations/preview{ rule, profiles, reading, state?, now? } → { decision }
POST/api/automations/{ruleId}/runexecute once against the live connector

Limits: 12 profiles, 24 rules, 8 weather brackets, cooldown 1–120 min, override 5–1440 min, thresholds 5–35 °C.

Acceptance