Your First Automation

Let's create a simple automation: close blinds at sunset, open at sunrise.

Prerequisites

  • MotorWala installed and working
  • Home Assistant (or similar platform)
  • Basic understanding of automations

Method 1: Home Assistant

Step 1: Add Device

In configuration.yaml:

cover:
  - platform: mqtt
    name: "Bedroom Blinds"
    command_topic: "motorwala/bedroom/command"
    position_topic: "motorwala/bedroom/position"

Restart Home Assistant.

Step 2: Create Automation

Go to ConfigurationAutomationsAdd Automation

Close at Sunset:

alias: "Close Blinds at Sunset"
trigger:
  - platform: sun
    event: sunset
    offset: "-00:30:00"  # 30 minutes before sunset
action:
  - service: cover.close_cover
    target:
      entity_id: cover.bedroom_blinds

Open at Sunrise:

alias: "Open Blinds at Sunrise"
trigger:
  - platform: sun
    event: sunrise
    offset: "00:15:00"  # 15 minutes after sunrise
action:
  - service: cover.open_cover
    target:
      entity_id: cover.bedroom_blinds

Step 3: Test

  • Click Execute in automation editor
  • Verify blinds move
  • Wait for sunset/sunrise to test automatically

Method 2: Node-RED

Step 1: Install Nodes

cd ~/.node-red
npm install node-red-contrib-sun-position

Step 2: Create Flow

  1. Add sun-position node
  2. Configure for your location
  3. Add switch node to route sunset/sunrise
  4. Add http request nodes for open/close
  5. Deploy

Flow JSON:

[
  {
    "id": "sunset-trigger",
    "type": "sun-position",
    "name": "Sun Position",
    "positionConfig": "home",
    "events": ["sunset", "sunrise"]
  },
  {
    "id": "close-blinds",
    "type": "http request",
    "method": "POST",
    "url": "http://192.168.1.100/api/motor/close"
  }
]

Method 3: Cron + curl

Simple scheduled commands using cron.

Step 1: Edit Crontab

crontab -e

Step 2: Add Schedule

# Close at 6 PM
0 18 * * * curl -X POST http://192.168.1.100/api/motor/close

# Open at 7 AM
0 7 * * * curl -X POST http://192.168.1.100/api/motor/open

Note: This uses fixed times, not actual sunset/sunrise.

Method 4: Python Script

Create blind_automation.py:

import requests
import schedule
import time
from suntime import Sun

# Your location
latitude = 28.6139  # New Delhi
longitude = 77.2090

sun = Sun(latitude, longitude)

def close_blinds():
    print("Closing blinds...")
    requests.post('http://192.168.1.100/api/motor/close')

def open_blinds():
    print("Opening blinds...")
    requests.post('http://192.168.1.100/api/motor/open')

# Calculate sunset/sunrise
sunset = sun.get_sunset_time()
sunrise = sun.get_sunrise_time()

# Schedule
schedule.every().day.at(sunset.strftime('%H:%M')).do(close_blinds)
schedule.every().day.at(sunrise.strftime('%H:%M')).do(open_blinds)

# Run
while True:
    schedule.run_pending()
    time.sleep(60)

Run as service:

python3 blind_automation.py &

Advanced: Conditional Logic

Only close if it's hot outside:

automation:
  - alias: "Close Blinds When Hot"
    trigger:
      - platform: numeric_state
        entity_id: sensor.outside_temperature
        above: 30
    condition:
      - condition: sun
        after: sunrise
        before: sunset
    action:
      - service: cover.close_cover
        target:
          entity_id: cover.bedroom_blinds

Troubleshooting

Automation doesn't trigger:

  • Check device IP is correct
  • Verify device is online
  • Review automation logs

Blinds move at wrong time:

  • Confirm timezone settings
  • Check location coordinates
  • Verify offset calculations

Inconsistent behavior:

  • Add delays between commands
  • Check for conflicting automations
  • Review device error logs

Next Steps


Share your automation! Tag us @WalaWorks

Previous

Next