Using OpenClaw for Home Automation with Smart Devices

Clawpedia · For Humans

Control smart home devices through OpenClaw using integrations with Home Assistant, MQTT, and more.

Using OpenClaw for Home Automation with Smart Devices

Transform your home into an intelligent environment where OpenClaw orchestrates all your smart devices through natural conversation. This guide covers complete home automation setups from basic to advanced.

Smart Home Architecture


┌────────────────────────────────────────────┐
│                OpenClaw Agent               │
│  Natural Language → Intent → Device Action  │
└──────────┬─────────┬─────────┬─────────────┘
           │         │         │
     ┌─────▼──┐ ┌────▼───┐ ┌──▼──────┐
     │  MQTT  │ │  HTTP   │ │ Bridge  │
     │ Broker │ │  APIs   │ │ (Zigbee)│
     └───┬────┘ └────┬───┘ └──┬──────┘
         │           │        │
    ┌────▼──┐  ┌─────▼──┐ ┌──▼──────┐
    │Sensors│  │ Cloud  │ │  Local  │
    │Lights │  │Devices │ │ Devices │
    └───────┘  └────────┘ └─────────┘

Getting Started: Basic Setup

Prerequisites

ComponentRecommendedAlternative
HubHome AssistantHubitat, OpenHAB
ProtocolZigbee (via Conbee II)Z-Wave, WiFi
BrokerMosquitto MQTTHiveMQ, EMQX

Initial Configuration


# config.yaml
agent:
  system_prompt: |
    You are a smart home controller. You manage devices in these rooms:
    - Living Room: lights (ceiling, lamp), TV, speakers, thermostat
    - Bedroom: lights (main, bedside), blinds, fan
    - Kitchen: lights, coffee machine, oven status sensor
    - Office: lights, monitor, desk fan
    - Bathroom: lights, heated floor, ventilation
    
    Device naming convention: {type}.{room}_{device}
    Example: light.living_room_ceiling
    
    Rules:
    - Always confirm before locking doors or arming alarm
    - Never set thermostat below 16°C or above 28°C
    - Dim lights gradually (not instant) after 10 PM
    - Report energy usage when asked

Room-Based Scenes


// skills/home-scenes/index.js
const scenes = {
  "morning": {
    description: "Gentle wake-up routine",
    actions: [
      { entity: "cover.bedroom_blinds", action: "open", delay: 0 },
      { entity: "light.bedroom_main", action: "turn_on", attrs: { brightness: 30, color_temp: 300 }, delay: 0 },
      { entity: "light.bedroom_main", action: "turn_on", attrs: { brightness: 80, color_temp: 250 }, delay: 300000 }, // 5 min later
      { entity: "climate.home", action: "set", attrs: { temperature: 22 }, delay: 0 },
      { entity: "switch.coffee_machine", action: "turn_on", delay: 600000 } // 10 min later
    ]
  },
  
  "movie_night": {
    description: "Cinema experience at home",
    actions: [
      { entity: "light.living_room_ceiling", action: "turn_off" },
      { entity: "light.living_room_lamp", action: "turn_on", attrs: { brightness: 10, rgb_color: [255, 147, 41] } },
      { entity: "cover.living_room_blinds", action: "close" },
      { entity: "media_player.living_room_tv", action: "turn_on" },
      { entity: "media_player.living_room_speakers", action: "turn_on" }
    ]
  },
  
  "goodnight": {
    description: "Secure the house and prepare for sleep",
    actions: [
      { entity: "light.all", action: "turn_off" },
      { entity: "lock.front_door", action: "lock" },
      { entity: "lock.back_door", action: "lock" },
      { entity: "cover.all", action: "close" },
      { entity: "alarm.home", action: "arm_night" },
      { entity: "climate.home", action: "set", attrs: { temperature: 19 } }
    ]
  },
  
  "away": {
    description: "Leaving the house",
    actions: [
      { entity: "light.all", action: "turn_off" },
      { entity: "climate.home", action: "set", attrs: { temperature: 17 } },
      { entity: "lock.all", action: "lock" },
      { entity: "alarm.home", action: "arm_away" },
      { entity: "switch.random_lights", action: "turn_on" } // Presence simulation
    ]
  }
};

module.exports = {
  name: "home-scenes",
  tools: [
    {
      name: "activate_scene",
      description: "Activate a predefined home scene",
      parameters: {
        type: "object",
        properties: {
          scene_name: { 
            type: "string",
            enum: Object.keys(scenes)
          }
        },
        required: ["scene_name"]
      },
      async execute({ scene_name }, context) {
        const scene = scenes[scene_name];
        if (!scene) return { error: "Unknown scene" };
        
        for (const action of scene.actions) {
          if (action.delay > 0) {
            setTimeout(() => executeAction(action, context), action.delay);
          } else {
            await executeAction(action, context);
          }
        }
        
        return { activated: scene_name, description: scene.description };
      }
    }
  ]
};

Energy Monitoring


// skills/energy-monitor/index.js
module.exports = {
  name: "energy-monitor",
  
  tools: [
    {
      name: "energy_report",
      description: "Get energy usage report",
      parameters: {
        type: "object",
        properties: {
          period: { type: "string", enum: ["today", "week", "month"] }
        }
      },
      async execute({ period = "today" }, context) {
        const sensors = await context.homeAssistant.getStates("sensor.energy_*");
        
        return {
          total_kwh: sensors.reduce((sum, s) => sum + parseFloat(s.state), 0),
          by_device: sensors.map(s => ({
            name: s.attributes.friendly_name,
            kwh: parseFloat(s.state),
            cost: (parseFloat(s.state) * 0.30).toFixed(2)
          })),
          period
        };
      }
    }
  ]
};

Conditional Automation


# Automations triggered by context
automations:
  - name: "Weather-based blinds"
    trigger: "temperature > 25°C AND sun_elevation > 30"
    action: "Close south-facing blinds"
    
  - name: "Presence-based lighting"
    trigger: "motion detected AND time between sunset and 23:00"
    action: "Turn on room lights at 60% brightness"
    
  - name: "Energy saver"  
    trigger: "no motion for 30 minutes in a room"
    action: "Turn off lights and reduce heating in that room"
    
  - name: "Security alert"
    trigger: "door/window opened AND alarm armed"
    action: "Send notification, activate cameras, turn on all lights"

Voice + Text Control Examples

NetworkDedicated IoT VLANStandard WiFi

Natural language commands your agent will understand:


"Turn on the kitchen lights"
→ light.kitchen_main → turn_on

"Set living room to 22 degrees"
→ climate.living_room → set_temperature(22)

"What's the temperature in the bedroom?"
→ sensor.bedroom_temperature → report state

"Close all blinds and turn off lights except the bedroom"
→ cover.* → close, light.* → turn_off, light.bedroom_* → skip

"Movie time"
→ Activate movie_night scene

"Is anyone home?"
→ Check presence sensors and report

"How much energy did we use today?"
→ Generate energy report for today

"Wake me up at 7 AM with the morning routine"
→ Schedule morning scene for 7:00

Security Setup


# Security configuration
home_security:
  cameras:
    - entity: camera.front_door
      recording: motion_triggered
    - entity: camera.backyard
      recording: always
      
  alerts:
    - condition: "door_opened AND nobody_home"
      notify: [push, sms]
      action: "activate cameras, record 60s clip"
      
    - condition: "smoke_detected"
      notify: [push, sms, call]
      action: "turn off HVAC, unlock doors, turn on all lights"
      
  access_control:
    require_pin: [lock.front_door, alarm.home]
    require_confirmation: [lock.*, alarm.*]

Troubleshooting

ProblemSolution
Device not respondingCheck WiFi/Zigbee signal, restart device, check battery
Slow responseUse local control (MQTT) instead of cloud APIs
Scene partially executesAdd error handling, increase timeouts between actions
Wrong room detectedImprove entity naming, add room context to prompts

Best Practices

Automation loopsAdd cooldown periods between trigger checks

Related Articles