Homeassisstant CLI
Find a file
renovate bot 187f8d05c7 chore(release): 1.21.1 [skip ci]
## [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 ([d8aa64e](d8aa64ec4b))
2025-12-08 21:26:33 +01:00
.forgejo/workflows chore(docker): update git.bueraner.de/murdoc/docker-semantic-release:latest docker digest to 692996f 2025-12-06 10:05:50 +00:00
adapters chore: improve update command 2025-12-06 09:31:00 +01:00
app chore: re-added NewState function 2025-12-05 19:47:25 +01:00
cmd chore: disable update check 2025-12-08 21:26:04 +01:00
domain feat: add errorlog function 2025-11-30 01:55:10 +01:00
internal feat: run CallService integration test only on defined hosts 2025-12-06 07:17:12 +01:00
pkg/utils feat: add pre-commit hooks and improve CLI functionality 2025-11-23 10:49:17 +01:00
ports feat: add update check command 2025-12-06 08:31:28 +01:00
.envrc feat: add integration test 2025-11-30 10:29:31 +01:00
.gitignore fix: bin folder 2025-11-23 11:27:01 +01:00
.golangci-lint.yml chore: improve .golangci-lint settings 2025-12-02 20:19:26 +01:00
.markdownlint.json fix: please markdown linter 2025-12-05 17:39:24 +01:00
.pre-commit-config.yaml chore: remove go pre-commits 2025-11-24 19:30:50 +01:00
AGENTS.md fix: please markdown linter 2025-12-05 17:39:24 +01:00
CHANGELOG.md chore(release): 1.21.1 [skip ci] 2025-12-08 21:26:33 +01:00
Dockerfile Merge pull request 'chore(docker): update alpine docker tag to v3.23' (#16) from renovate/alpine-3.x into main 2025-12-05 06:07:18 +00:00
go.mod fix(deps): update module github.com/spf13/cobra to v1.10.2 2025-12-04 02:05:50 +00:00
go.sum docs: add comprehensive agent guidelines document 2025-12-05 07:47:48 +01:00
main.go feat: improve unit test for main.go 2025-12-02 17:46:25 +01:00
main_test.go feat: improve unit test for main.go 2025-12-02 17:46:25 +01:00
Makefile feat: improve make test command 2025-12-05 20:45:04 +01:00
README.md docs: add architecture overview 2025-11-30 08:55:09 +01:00
release.config.mjs feat: add CI/CD workflows and improve HA service logic 2025-11-24 06:43:21 +01:00
renovate.json chore(deps): add renovate.json 2025-11-24 08:05:58 +00:00

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

MIT License


Support

For questions or issues: Git Repository Issues