🔳 Home Assistant command line interface
Go to file
dependabot[bot] 4adbdef358
Bump github.com/go-resty/resty/v2 from 2.16.0 to 2.16.1 (#523)
2024-11-20 07:24:53 +01:00
.devcontainer Bump go to v1.23 (#513) 2024-09-24 15:22:17 +02:00
.github Bump actions/setup-go from 5.0.2 to 5.1.0 (#520) 2024-10-25 16:17:37 +02:00
client Centralize error handling and add 503 support (#504) 2024-08-20 16:48:12 +02:00
cmd Centralize error handling and add 503 support (#504) 2024-08-20 16:48:12 +02:00
spinner Use string formatting for final spinner message (#508) 2024-08-19 15:47:11 +02:00
.gitignore Update go to 1.17 (#312) 2021-09-27 16:50:55 +02:00
.golangci.yaml More linting, address findings, config improvements (#448) 2024-02-13 11:21:55 +01:00
LICENSE Initial commit 2017-12-19 15:12:32 +01:00
README.md Update URL (#394) 2023-04-29 11:01:49 +02:00
go.mod Bump github.com/go-resty/resty/v2 from 2.16.0 to 2.16.1 (#523) 2024-11-20 07:24:53 +01:00
go.sum Bump github.com/go-resty/resty/v2 from 2.16.0 to 2.16.1 (#523) 2024-11-20 07:24:53 +01:00
main.go Rebranding to Home Assistant CLI (#195) 2020-02-07 13:03:53 +01:00

README.md

Home Assistant CLI

Command line interface to facilitate interaction with the Home Assistant Supervisor.

Usage

  • ha help
  • ha <subcommand> <action> [<options>]

E.g.:

  • ha core info --raw-json

Modifiers

Global

      --api-token string   Home Assistant Supervisor API token
      --config string      Optional config file (default is $HOME/.homeassistant.yaml)
      --endpoint string    Endpoint for Home Assistant Supervisor (default is 'supervisor')
  -h, --help               help for ha
      --log-level string   Log level (defaults to Warn)
      --no-progress        Disable the progress spinner
      --raw-json           Output raw JSON from the API

All options are also available as SUPERVISOR_ prefixed environment variables like SUPERVISOR_LOG_LEVEL

Subcommands

Available commands:

  addons         Install, update, remove and configure Home Assistant add-ons
  audio          Audio device handling.
  authentication Authentication for Home Assistant users.
  cli            Get information, update or configure the Home Assistant cli backend
  core           Provides control of the Home Assistant Core
  dns            Get information, update or configure the Home Assistant DNS server
  docker         Docker backend specific for info and OCI configuration
  hardware       Provides hardware information about your system
  help           Help about any command
  host           Control the host/system that Home Assistant is running on
  info           Provides a general Home Assistant information overview
  multicast      Get information, update or configure the Home Assistant Multicast
  network        Network specific for updating, info and configuration imports
  observer       Get information, update or configure the Home Assistant observer
  os             Operating System specific for updating, info and configuration imports
  resolution     Resolution center of Supervisor, show issues and suggest solutions
  backups        Create, restore and remove backups
  supervisor     Monitor, control and configure the Home Assistant Supervisor

Installation

The CLI is provided by the CLI container on Home Assistant systems and is available on the device terminal when using the Home Assistant Operating System.

The CLI is automatically updated on those systems.

Furthermore, the SSH add-on (available in the add-on store) provides access to this tool and several community add-ons provide it as well (e.g., the Visual Studio Code add-on).

Developing & contributing

Prerequisites

The CLI can interact remotely with the Home Assistant Supervisor using the remote_api add-on from the developer add-ons repository.

After installing and starting the add-on, a token is shown in the remote_api add-on log, which is needed for further development.

Get the source code

Fork (https://github.com/home-assistant/cli/fork) or clone this repository.

Using it in development

export SUPERVISOR_ENDPOINT=http://192.168.1.2
export SUPERVISOR_API_TOKEN=replace_this_with_remote_api_token
go run main.go info

Note: Replace the 192.168.1.2 with the IP address of your Home Assistant instance running the remote_api add-on and use the token provided.

Building

We use go modules; an example build below:

CGO_ENABLED=0 go build -ldflags="-s -w" -o "ha"

For details how we build cross for different architectures, please see our build action file.

Contributing a change

  1. Create a feature branch on your fork/clone of the git repository.
  2. Commit your changes.
  3. Rebase your local changes against the master branch.
  4. Run test suite with the go test ./... command and confirm that it passes.
  5. Run gofmt -s to ensure your code is formatted properly.
  6. Create a new Pull Request.