Skip to content

Automation

Automation runs at the Python runtime/backend — not on the mobile app. Even if the user closes the app, rules keep working.

Purpose

Extend ODevice from "Observe + Control" to "Observe + Control + Configure + React Automatically" — with three simple primitives, not a full automation engine.

Primitives

1. Warning

Threshold + duration → warning state machine.

python
app.add_warning("pump-01", "pressure", ">", 8.0, duration=5, severity="warning")

States: inactive → pending → active → acknowledged → resolved.

2. Condition (automation)

"If X for N seconds, then set a writable property."

python
app.add_automation("High Pressure Stop",
    when={"entity": "pump-01", "property": "pressure", "operator": ">", "value": 9, "duration": 3},
    then={"entity": "pump-01", "property": "power", "operation": "set", "value": False},
    cooldown=30)

3. Schedule

Time-based action: once, daily, or specific weekdays.

python
app.add_schedule("Morning Start", "Asia/Bangkok",
    schedule={"type": "daily", "time": "08:00"},
    action={"entity": "pump-01", "property": "power", "operation": "set", "value": True})

Execution path

Automation never mutates state directly. It goes through the same command pipeline as manual control:

Rule evaluator → command → permission/validation → on_write() → backend → state → delta

So manual control and automation share one execution path, audit, and telemetry.

Operators

>  >=  <  <=  ==  !=

with duration (condition must hold for N seconds) and cooldown (min seconds between triggers).

Developer boundary

The developer controls what automation can do:

python
power = Boolean(writable=True, automation={"allow_set": True})   # automation may set
emergency_reset = Boolean(writable=True, automation={"allow_set": False})  # manual only

Manual write ≠ automation write.

Configuration vs state

Rules are configuration, not state. Stored separately from device state:

State:          pressure = 8.4, power = true
Configuration:  warning > 8, stop > 9, start 08:00

Endpoints

GET    /automation                          # rules + warning state
POST   /automation/{warning|automation|schedule}
PUT    /automation/{kind}/{id}              # enable/disable
DELETE /automation/{kind}/{id}

Constraints

  • Operators are the 6 comparison operators only
  • Schedule types: once / daily / weekdays (no cron)
  • Warning severity: info / warning / critical
  • Rules are in-memory (MVP, no persistence)

Non-goals (MVP)

No multi-condition AND/OR graphs, nested rules, webhook, email/SMS, geofence, sunrise/sunset, AI automation, or visual flow builder.

Built for self-hosted IoT runtimes.