Example: Smart Farm
Pump control + temperature monitoring with full automation. Demonstrates the complete "Observe + Control + Configure + React Automatically" loop.
python
from odevice import App, Device, Number, Boolean
app = App("Smart Farm")
pump = Device(id="pump-01", name="Irrigation Pump", properties={
"flow_rate": Number(unit="L/min", min=0, max=60, view="gauge"),
"running": Boolean(writable=True, automation={"allow_set": True}),
})
climate = Device(id="climate-01", name="Field Climate", properties={
"temperature": Number(unit="°C", min=0, max=50, view="gauge",
configurable={"warning": True}),
"soil_moisture": Number(unit="%", min=0, max=100, view="progress"),
})
# Auto-irrigation with hysteresis (start <30%, stop >70%)
app.add_automation("Auto Start", when={...soil < 30...}, then={...running: True...})
app.add_automation("Auto Stop", when={...soil > 70...}, then={...running: False...})
app.add_schedule("Morning Irrigation", "Asia/Bangkok",
schedule={"type": "daily", "time": "06:00"},
action={...running: True...})Run: python examples/smart-farm/main.py (or make run-farm)
Demonstrates: gauge, progress, alarm, switch, action, warning, condition automation (with hysteresis), daily schedule, backend-declared page.