Get the FREE Ultimate OpenClaw Setup Guide →
J

Home Assistant CLI

Scanned

@JonesChi

npx machina-cli add skill @JonesChi/homeassistant-cli --openclaw
Files (1)
SKILL.md
4.8 KB

Home Assistant CLI

Control your Home Assistant smart home devices using the official hass-cli tool — a feature-rich command-line interface with auto-completion, event monitoring, and flexible output formatting.

Why This Skill vs. homeassistant (curl-based)?

Choose homeassistant-cli if you want:

  • Auto-completion for entity IDs and services (bash/zsh/fish)
  • Event monitoring in real-time (hass-cli event watch)
  • History queries (hass-cli state history)
  • Better output formatting (table/YAML/JSON with one flag)
  • Interactive exploration (easier to discover entities and services)
  • Comprehensive documentation with examples and troubleshooting

Choose homeassistant (curl) if you want:

  • ✅ Zero dependencies (curl + jq are pre-installed)
  • ✅ Lightweight and fast
  • ✅ Better for scripting and automation
  • ✅ No Python requirements

Both work great — this skill is for users who interact frequently with Home Assistant and want a richer CLI experience.

Setup

Before using hass-cli, configure authentication:

  1. Generate a long-lived access token in Home Assistant:

    • Navigate to your profile: https://your-homeassistant:8123/profile
    • Scroll to "Long-Lived Access Tokens"
    • Create a new token
  2. Set environment variables (add to shell config for persistence):

    export HASS_SERVER=https://homeassistant.local:8123
    export HASS_TOKEN=<your-token>
    
  3. Test connection:

    hass-cli info
    

Common Commands

List Entities

# List all entities
hass-cli state list

# Filter by domain
hass-cli state list light
hass-cli state list switch
hass-cli state list sensor

# Get specific entity state
hass-cli state get light.living_room

Control Devices

# Turn on/off lights
hass-cli service call light.turn_on --arguments entity_id=light.living_room
hass-cli service call light.turn_off --arguments entity_id=light.living_room

# Set brightness (0-255)
hass-cli service call light.turn_on --arguments entity_id=light.bedroom,brightness=128

# Turn on/off switches
hass-cli service call switch.turn_on --arguments entity_id=switch.fan
hass-cli service call switch.turn_off --arguments entity_id=switch.fan

# Toggle any device
hass-cli service call homeassistant.toggle --arguments entity_id=light.kitchen

List and Call Services

# List all services
hass-cli service list

# Filter services
hass-cli service list light
hass-cli service list 'home.*toggle'

# Get service details (YAML output)
hass-cli -o yaml service list homeassistant.toggle

Work with Scenes

# List scenes
hass-cli state list scene

# Activate a scene
hass-cli service call scene.turn_on --arguments entity_id=scene.movie_time

Monitor Events

# Watch all events
hass-cli event watch

# Watch specific event type
hass-cli event watch state_changed
hass-cli event watch automation_triggered

History

# Get state history (last 50 minutes)
hass-cli state history --since 50m light.living_room

# Multiple entities
hass-cli state history --since 1h light.living_room switch.fan

Output Formats

Control output with -o or --output:

# Table (default)
hass-cli state list

# YAML
hass-cli -o yaml state get light.living_room

# JSON
hass-cli -o json state list light

# No headers (for scripting)
hass-cli --no-headers state list

Tips

Examples

See references/examples.md for common automation patterns and use cases.

Source

git clone https://clawhub.ai/JonesChi/homeassistant-cliView on GitHub

Overview

Leverage the official hass-cli to control Home Assistant with real-time event monitoring, auto-completion, and versatile output formatting. It offers a richer, more discoverable CLI experience than the curl-based approach, making it easier to find entities and services and to inspect their states.

How This Skill Works

hass-cli provides a binary interface to Home Assistant. After configuring HASS_SERVER and HASS_TOKEN, you can run commands like hass-cli state list, hass-cli service list, and hass-cli event watch to interactively explore entities, call services, and view results in table, YAML, or JSON.

When to Use It

  • You want to discover entities and services quickly using auto-completion
  • Real-time visibility into state changes and events with hass-cli event watch
  • Need historical state data via queries like state history
  • Prefer structured output formats (table, YAML, JSON) for automation or reporting
  • Frequent Home Assistant interactions and exploration without curl dependencies

Quick Start

  1. Step 1: Set HASS_SERVER and HASS_TOKEN environment variables
  2. Step 2: Test the connection with hass-cli info
  3. Step 3: Try basic discovery and actions, e.g., hass-cli state list and hass-cli service list

Best Practices

  • Configure authentication once by exporting HASS_SERVER and HASS_TOKEN in your shell
  • Use state and service lists to discover capabilities before invoking actions
  • Leverage -o yaml or -o json for machine-friendly outputs
  • Test commands with non-critical devices first to avoid disruptions
  • Keep hass-cli up to date via pip or brew to access new features

Example Use Cases

  • List all lights: hass-cli state list light
  • Get a specific state: hass-cli state get light.living_room
  • Turn on a light: hass-cli service call light.turn_on --arguments entity_id=light.living_room
  • List and filter services: hass-cli service list light
  • Watch for changes: hass-cli event watch

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers