Homeassisstant CLI
## [1.21.1](https://git.bueraner.de/murdoc/ha-cli/compare/v1.21.0...v1.21.1) (2025-12-08) ### Bug Fixes * add new context cancel timeout for follow command ([ |
||
|---|---|---|
| .forgejo/workflows | ||
| adapters | ||
| app | ||
| cmd | ||
| domain | ||
| internal | ||
| pkg/utils | ||
| ports | ||
| .envrc | ||
| .gitignore | ||
| .golangci-lint.yml | ||
| .markdownlint.json | ||
| .pre-commit-config.yaml | ||
| AGENTS.md | ||
| CHANGELOG.md | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| main_test.go | ||
| Makefile | ||
| README.md | ||
| release.config.mjs | ||
| renovate.json | ||
ha-cli
ha-cli is a command-line tool for controlling Home Assistant.
It allows listing devices, turning entities on and off, and
supports wildcards and domain filters.
Features
- List all entities in Home Assistant (
device list) - Filter by domains or wildcards (
device list light decke*) - Display all domains (
device list --domains) - Turn entities on and off (
device turn-on/turn-off) - Auto-completion of entity IDs in shells (Bash, Zsh)
- Support for Home Assistant API tokens via environment variables
Architecture
- adapters/ → Outbound + Inbound Adapter (HTTP, CLI, DB, Logger …)
- app/ → Application Layer (Use-Cases)
- domain/ → Business Domain (Entities, Aggregate Roots, Policies)
- ports/ → Ports/Interfaces (Input + Output Ports)
- cmd/ → Eingänge (Cobra Commands, CLI-Parsing etc.)
- internal/ → private Helper, die NICHT Teil der Architektur sind
- pkg/ → Public Libraries (optional)
- main.go → Composition Root (Wiring)
| Ordner | Rolle im Hexagon | Darf wen kennen? |
|---|---|---|
| domain/ | Zentrum (Entities, Regeln) | kennt niemand |
| ports/ | Ports (Interfaces) | darf domain kennen |
| app/ | Use-Cases | kennt domain + ports |
| adapters/ | Adapter implementieren Ports | kennt ports, nicht app/domain |
| cmd/ | Primäre Adapter (CLI) | kennt app |
| main.go | Composition Root | kennt ALLES (darf das!) |
| internal/ | Hilfen | abhängig vom Inhalt |
Overview
+----------------------+
CLI (cobra) ----> | cmd/ | (Primary Adapter)
+----------+-----------+
|
v
+----------------------+
| app/ | (Use Cases)
+----------+-----------+
|
v
+---------------------------+
| ports/ | (Input/Output Ports)
+----------+----------------+
/ \
v v
+-------------------------+ +----------------------------+
| adapters/logger | | adapters/homeassistant_http|
| (Logger implementation) | | (HTTP implementation) |
+-------------------------+ +----------------------------+
Core domain:
+---------------+
| domain/ |
+---------------+
Installation
# With Go
go install git.bueraner.de/murdoc/ha-cli@latest
Configuration
Set the environment variables:
export HA_BASE_URL="http://homeassistant.local:8123"
export HA_TOKEN="Your_Long_HomeAssistant_Token"
# Optional: Load token from file
export HA_TOKEN_FILE="/path/to/token.txt"
Usage
List devices
# All devices
ha-cli device list
# List only lights
ha-cli device list light
# List only switches with "decken" in the name
ha-cli device list switch decken
# Display all domains
ha-cli device list --domains
Control devices
# Turn on an entity
ha-cli device turn-on switch.eg_wz_wled_decke
# Turn off an entity
ha-cli device turn-off light.wohnzimmer
Wildcards and multiple filters
# All switches with 'wled' in the name
ha-cli device list switch wled*
# Lights on the ceiling
ha-cli device list light decken*
Enable shell completion
# Bash
source <(ha-cli completion bash)
# Zsh
autoload -U compinit; compinit
source <(ha-cli completion zsh)
Now turn-on and turn-off will auto-complete entity IDs.
Development
- Clone the repository
- Build:
make install - Tests:
make test
License
Support
For questions or issues: Git Repository Issues