scadable add controller
Generate a controller file in controllers/ from a template.
scadable add controller <name>Example
scadable add controller temp-monitorCreates controllers/temp_monitor.py:
"""TODO: describe this controller."""
from scadable import Controller, on, SECONDS
class TempMonitor(Controller):
@on.interval(5, SECONDS)
def run(self):
passWhat you typically add
Three steps to make this real:
- Import the device classes you want to read from.
- Pick the trigger that matches when the method should fire.
- Write the logic in the method body.
from scadable import Controller, on, SECONDS
from devices.line_sensor import LineSensor
class TempMonitor(Controller):
@on.interval(5, SECONDS)
def check(self):
if LineSensor.temperature > 95:
self.alert("critical", f"Temp: {LineSensor.temperature}C")
self.publish("readings", {"temp": LineSensor.temperature})LineSensor.temperature reads the latest scaled value of register 40001 on the device. No HTTP calls, no awaits, no callbacks. The runtime makes the value available as an attribute and you read it.
Trigger patterns
You can stack multiple triggers on the same controller:
class SafetyMonitor(Controller):
@on.startup
def init(self):
self.publish("status", {"state": "armed"})
@on.interval(5, SECONDS)
def heartbeat(self):
self.publish("hb", {"ok": True})
@on.threshold(LineSensor.temperature, above=95)
def overheat(self):
self.alert("critical", "overtemp")
LineSensor.flow_rate = 0See Core Concepts for the full trigger inventory.
Exit codes
| Code | Meaning |
|---|---|
| 0 | File created |
| 1 | Controller file already exists |
Next steps
- Core Concepts: every trigger and what fires it
- scadable verify: confirm controller references resolve
- scadable compile: produce the bundle
Updated 4 days ago
