Automations API

Built-in automation rules that run directly on Wala Works devices.

Overview

Wala Works devices support simple automation rules that execute locally without requiring an external automation platform. These are useful for:

  • Basic time-based schedules
  • Sensor-triggered actions
  • Failsafe behaviors
  • Offline operation

For complex automations, use Home Assistant, Node-RED, or similar platforms.

Automation Structure

{
  "id": "auto-1",
  "name": "Close at Sunset",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunset",
    "offset": -1800
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Triggers

Time Triggers

Fixed time:

{
  "type": "time",
  "value": "18:00",
  "days": ["mon", "tue", "wed", "thu", "fri"]
}

Sun-based:

{
  "type": "time",
  "value": "sunset",
  "offset": -1800
}

Options:

  • value: "sunrise", "sunset", or "HH:MM" (24-hour format)
  • offset: Seconds before (-) or after (+) time
  • days: Array of days (mon, tue, wed, thu, fri, sat, sun) or ["all"]

Interval:

{
  "type": "interval",
  "seconds": 3600
}

State Triggers

Motor position:

{
  "type": "position",
  "operator": ">=",
  "value": 75
}

Operators:

  • == - Equal to
  • != - Not equal to
  • > - Greater than
  • < - Less than
  • >= - Greater than or equal
  • <= - Less than or equal

Relay state:

{
  "type": "relay_state",
  "channel": 1,
  "state": "on",
  "duration": 3600
}

Triggers when relay has been in state for specified duration (seconds).

System Triggers

WiFi connection:

{
  "type": "wifi",
  "state": "connected"
}

Boot/startup:

{
  "type": "system",
  "event": "boot"
}

Events:

  • boot - Device starts up
  • wifi_connected - WiFi connects
  • wifi_disconnected - WiFi disconnects
  • mqtt_connected - MQTT connects
  • mqtt_disconnected - MQTT disconnects

Conditions

Add conditions that must be true for automation to execute.

Time Conditions

Time range:

{
  "type": "time_range",
  "after": "07:00",
  "before": "22:00"
}

Day of week:

{
  "type": "day",
  "days": ["mon", "tue", "wed", "thu", "fri"]
}

State Conditions

Motor position:

{
  "type": "position",
  "operator": "<",
  "value": 50
}

Relay state:

{
  "type": "relay",
  "channel": 1,
  "state": "off"
}

System Conditions

WiFi signal:

{
  "type": "wifi_rssi",
  "operator": ">",
  "value": -70
}

MQTT connection:

{
  "type": "mqtt",
  "state": "connected"
}

Actions

Motor Actions (MotorWala)

Open:

{
  "type": "motor",
  "action": "open"
}

Close:

{
  "type": "motor",
  "action": "close"
}

Set position:

{
  "type": "motor",
  "action": "position",
  "value": 50,
  "speed": 80
}

Stop:

{
  "type": "motor",
  "action": "stop"
}

Relay Actions (RelayWala)

Turn on:

{
  "type": "relay",
  "channel": 1,
  "action": "on"
}

Turn off:

{
  "type": "relay",
  "channel": 1,
  "action": "off"
}

Toggle:

{
  "type": "relay",
  "channel": 1,
  "action": "toggle"
}

Pulse (momentary):

{
  "type": "relay",
  "channel": 1,
  "action": "pulse",
  "duration": 1000
}

System Actions

Delay:

{
  "type": "delay",
  "seconds": 30
}

Notification:

{
  "type": "notify",
  "message": "Blinds closed at sunset",
  "level": "info"
}

Sends notification to MQTT topic and device logs.

MQTT Publish:

{
  "type": "mqtt_publish",
  "topic": "home/status",
  "payload": "Blinds closed"
}

API Endpoints

List Automations

GET /api/automations

Response:

{
  "automations": [
    {
      "id": "auto-1",
      "name": "Close at Sunset",
      "enabled": true,
      "last_triggered": "2025-11-04T18:30:00Z",
      "trigger_count": 45
    },
    {
      "id": "auto-2",
      "name": "Open at Sunrise",
      "enabled": true,
      "last_triggered": "2025-11-05T06:45:00Z",
      "trigger_count": 46
    }
  ]
}

Get Automation

GET /api/automations/{id}

Response:

{
  "id": "auto-1",
  "name": "Close at Sunset",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunset",
    "offset": -1800
  },
  "conditions": [
    {
      "type": "time_range",
      "after": "15:00",
      "before": "23:00"
    }
  ],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ],
  "created": "2025-01-15T10:00:00Z",
  "last_triggered": "2025-11-04T18:30:00Z",
  "trigger_count": 45
}

Create Automation

POST /api/automations
Content-Type: application/json

Request:

{
  "name": "Close at Sunset",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunset",
    "offset": -1800
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Response:

{
  "success": true,
  "id": "auto-3",
  "message": "Automation created"
}

Update Automation

PUT /api/automations/{id}
Content-Type: application/json

Request:

{
  "name": "Close at Sunset (Updated)",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunset",
    "offset": -3600
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Delete Automation

DELETE /api/automations/{id}

Response:

{
  "success": true,
  "message": "Automation deleted"
}

Enable/Disable Automation

POST /api/automations/{id}/enable
POST /api/automations/{id}/disable

Response:

{
  "success": true,
  "enabled": true
}

Trigger Automation Manually

POST /api/automations/{id}/trigger

Manually execute automation (useful for testing).

Response:

{
  "success": true,
  "executed": true,
  "message": "Automation triggered successfully"
}

Examples

Example 1: Daily Schedule

Close blinds at 6 PM on weekdays:

{
  "name": "Weekday Evening Close",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "18:00",
    "days": ["mon", "tue", "wed", "thu", "fri"]
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Example 2: Sunrise/Sunset

Open at sunrise, close at sunset:

Sunrise automation:

{
  "name": "Open at Sunrise",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunrise",
    "offset": 900
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "open"
    }
  ]
}

Sunset automation:

{
  "name": "Close at Sunset",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "sunset",
    "offset": -1800
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Example 3: Sequential Actions

Turn on lights, wait, turn off:

{
  "name": "Timed Light",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "18:00"
  },
  "conditions": [],
  "actions": [
    {
      "type": "relay",
      "channel": 1,
      "action": "on"
    },
    {
      "type": "delay",
      "seconds": 7200
    },
    {
      "type": "relay",
      "channel": 1,
      "action": "off"
    }
  ]
}

Example 4: Conditional Automation

Only close if currently open:

{
  "name": "Conditional Close",
  "enabled": true,
  "trigger": {
    "type": "time",
    "value": "20:00"
  },
  "conditions": [
    {
      "type": "position",
      "operator": ">",
      "value": 50
    }
  ],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Example 5: WiFi Failsafe

Close blinds if WiFi disconnects for 5 minutes:

{
  "name": "WiFi Failsafe",
  "enabled": true,
  "trigger": {
    "type": "wifi",
    "state": "disconnected",
    "duration": 300
  },
  "conditions": [],
  "actions": [
    {
      "type": "motor",
      "action": "close"
    }
  ]
}

Example 6: Boot Action

Set relay states on device boot:

{
  "name": "Boot Configuration",
  "enabled": true,
  "trigger": {
    "type": "system",
    "event": "boot"
  },
  "conditions": [],
  "actions": [
    {
      "type": "relay",
      "channel": 1,
      "action": "off"
    },
    {
      "type": "relay",
      "channel": 2,
      "action": "on"
    }
  ]
}

Automation History

Get Execution History

GET /api/automations/{id}/history?limit=20

Response:

{
  "automation_id": "auto-1",
  "executions": [
    {
      "timestamp": "2025-11-04T18:30:00Z",
      "success": true,
      "duration_ms": 250,
      "actions_executed": 1
    },
    {
      "timestamp": "2025-11-03T18:30:00Z",
      "success": true,
      "duration_ms": 245,
      "actions_executed": 1
    }
  ]
}

Clear History

DELETE /api/automations/{id}/history

Limits

Device automation limits:

| Limit | Value | |-------|-------| | Max automations | 20 | | Max actions per automation | 10 | | Max conditions per automation | 5 | | History retention | 100 executions |

Best Practices

Keep It Simple

Device automations are best for: ✅ Simple time-based schedules ✅ Failsafe behaviors ✅ Boot configuration ✅ Basic state changes

Use external platforms for: ❌ Complex logic ❌ Multi-device coordination ❌ Advanced conditions ❌ External sensor data

Error Handling

Automations continue on error:

  • Failed actions are logged
  • Subsequent actions still execute
  • Automation remains enabled

Testing

Always test automations:

# Trigger manually
curl -X POST http://192.168.1.100/api/automations/auto-1/trigger

# Check logs
curl http://192.168.1.100/api/system/logs?limit=10

# Monitor history
curl http://192.168.1.100/api/automations/auto-1/history

Backup

Export automations before firmware updates:

# Export all automations
curl http://192.168.1.100/api/automations > automations-backup.json

# Import after update
curl -X POST http://192.168.1.100/api/automations/import \
  -H "Content-Type: application/json" \
  -d @automations-backup.json

Integration with External Platforms

Home Assistant

Supplement device automations with Home Assistant:

Device handles:

  • Basic daily schedules
  • Failsafe behaviors

Home Assistant handles:

  • Complex scenes
  • Multi-device coordination
  • External sensor triggers

Node-RED

Use Node-RED for advanced logic:

Device handles:

  • Local operation (offline)
  • Quick responses

Node-RED handles:

  • API integrations
  • Complex flows
  • Data processing

Troubleshooting

Automation not triggering:

  1. Check automation is enabled
  2. Verify trigger configuration
  3. Review conditions (must all be true)
  4. Check device time/timezone
  5. Review automation history

Actions not executing:

  1. Verify action syntax
  2. Check device state (can't close if already closed)
  3. Review system logs
  4. Test action manually via API

Sunset/sunrise times wrong:

  1. Set correct timezone
  2. Configure location (latitude/longitude)
  3. Verify NTP sync
  4. Check sunrise/sunset calculator

History not recording:

  1. Check history storage not full
  2. Verify automation is triggering
  3. Review system logs
  4. Clear old history

Next Steps


Automation questions? Check FAQ or contact support

Previous

Next