Command-line tool for Home Assistant.
Project description
Home Assistant Command-line Interface (hass-cli)
The Home Assistant Command-line interface (hass-cli) allows one to work with a local or a remote Home Assistant instance directly from the command-line.
Note: This is still in alpha and under heavy development. Name and structure of commands are expected to still change.
Installation
To use latest release:
$ pip install homeassistant-cli
To use latest pre-release from dev branch:
$ pip install pip3 install git+https://github.com/home-assistant/home-assistant-cli@dev
To get started you’ll need to have or generate a long lasting token format on your Home Assistant profile page (i.e. https://localhost:8123/profile).
Then you can use --server and --token paremeter on each call, or as is recommended setup HASS_SERVER and HASS_TOKEN environment variables.
$ export HASS_SERVER=https://hassio.local:8123
$ export HASS_TOKEN=<secret>
Once that is enabled and you are using either zsh or bash run the folowing to enable autocompletion for hass-cli commands.
$ source <(hass-cli completion zsh)
Usage
Note: Below is listed some of the features, make sure to use –help and autocompletion to learn more of the features as they become available.
By default (for now) most commands returns “raw” version of what the Home Assistant API returns. For example to get basic info about your Home Assistant server you use info:
$ hass-cli info
{
"base_url": "http://hassio.local:8123",
"location_name": "Fortress of Solitude",
"requires_api_password": false,
"version": "0.82.1"
}
If you prefer yaml you can use –output=yaml:
$ hass-cli --output yaml info
base_url: https://hassio.local:8123
location_name: Wayne Manor
requires_api_password: false
version: 0.82.1
Listing entities has support for tables:
$ hass-cli --output=table entity list ✘ 2 dev ✭ ✱
ENTITY DESCRIPTION STATE
--------------------------------------------------------- ---------------------------------------------- ---------------------
zone.school School zoning
zone.home Andersens zoning
sun.sun Sun below_horizon
camera.babymonitor babymonitor idle
timer.timer_office_lights idle
timer.timer_small_bathroom idle
group.kitchen_lights Kitchen Lights off
binary_sensor.presence_basement_combined Basement Motion Anywhere off
sensor.yr_symbol yr Symbol 4
group.basement_lights Basement Lights unknown
sensor.packages_delivered Packages Delivered 1
sensor.packages_in_transit Packages In Transit 1
sensor.ring_front_door_last_ding Front Door Last Ding 14:08
sensor.ring_front_door_battery Front Door Battery 52
...
Get state of a entity:
$ hass-cli --output yaml entity get light.guestroom_light ◼
attributes:
friendly_name: Guestroom Light
supported_features: 61
context:
id: 84d52fe306ec4895948b546b492702a4
user_id: null
entity_id: light.guestroom_light
last_changed: '2018-12-10T18:33:51.883238+00:00'
last_updated: '2018-12-10T18:33:51.883238+00:00'
state: 'off'
You can edit state via an editor:
$ hass-cli entity edit light.guestroom_light
This will open the current state in your favorite editor and any changes you save will be used for an update.
You can also explicitly create/edit via the –json flag:
$ hass-cli entity edit sensor.test --json='{ "state":"off"}'
List posible service with or without a regular expression filter:
hass-cli --output=yaml service list 'home.*toggle' ✘ 1 dev ✭ ✱
homeassistant:
services:
toggle:
description: Generic service to toggle devices on/off under any domain. Same
usage as the light.turn_on, switch.turn_on, etc. services.
fields:
entity_id:
description: The entity_id of the device to toggle on/off.
example: light.living_room
$ hass-cli service call deconz.device_refresh
With arguments:
$ hass-cli service call homeassistant.toggle --arguments entity_id=light.office_light
Open a map for your Home Assistant location:
$ hass-cli map
Render templates server side:
$ hass-cli template motionlight.yaml.j2 motiondata.yaml
Render templates client side:
$ hass-cli template --local lovelace-template.yaml
Auto-completion
As described above you can use source <(hass-cli completion zsh) to quickly and easy enable auto completion. If you do it from your .bashrc or .zshrc its recommend to use the form below as that does not trigger a run of hass-cli itself.
For zsh:
eval "$(_HASS_CLI_COMPLETE=source_zsh hass-cli)"
For bash:
eval "$(_FOO_BAR_COMPLETE=source foo-bar)"
Once enabled there is autocompletion for commands and for certain attributes like entities:
$ hass-cli entity get light.<TAB> ⏎ ✱ ◼
light.kitchen_light_5 light.office_light light.basement_light_4 light.basement_light_9 light.dinner_table_light_4 light.winter_garden_light_2 light.kitchen_light_2
light.kitchen_table_light_1 light.hallroom_light_2 light.basement_light_5 light.basement_light_10 light.dinner_table_wall_light light.winter_garden_light_4 light.kitchen_table_light_2
light.kitchen_light_1 light.hallroom_light_1 light.basement_light_6 light.small_bathroom_light light.dinner_table_light_5 light.winter_garden_light_3 light.kitchen_light_4
light.kitchen_light_6 light.basement_light_1 light.basement_light_7 light.dinner_table_light_1 light.dinner_table_light_6 light.hallroom_light_4
light.guestroom_light light.basement_light_stairs light.basement_light_2 light.hallroom_light_5 light.dinner_table_light_3 light.winter_garden_light_5
light.hallroom_light_3 light.basement_light_3 light.basement_light_8 light.dinner_table_light_2 light.winter_garden_light_1 light.kitchen_light_3
Note: For this to work you’ll need to have setup the following environment variables if your home-assistant is secured and not running on localhost:8123:
export HASS_SERVER=https://hassio.local:8123
export HASS_TOKEN=<Bearer token from HASS_SERVER/profile>
Help
Usage: hass-cli [OPTIONS] COMMAND [ARGS]...
Command line interface for Home Assistant.
Options:
-l, --loglevel LVL Either CRITICAL, ERROR, WARNING, INFO or
DEBUG
--version Show the version and exit.
-s, --server TEXT The server URL of Home Assistant instance.
--token TEXT The Bearer token for Home Assistant
instance.
--timeout INTEGER Timeout for network operations. [default:
5]
-o, --output [json|yaml|table] Output format [default: json]
-v, --verbose Enables verbose mode.
-x Print backtraces when exception occurs.
--insecure Ignore SSL Certificates. Allow to connect to
servers with self-signed certificates. Be
careful!
--debug Enables debug mode.
--version Show the version and exit.
--help Show this message and exit.
Commands:
completion Output shell completion code for the specified shell (bash or...
config Get configuration from Home Assistant.
discover Discovery for the local network.
entity Get info and operate on entities from Home Assistant.
event Interact with events.
info Get basic info from Home Assistant.
map Print the current location on a map.
raw Call the raw API (advanced).
service Call and work with services.
template Render templates on server or locally.
Clone the git repository and
$ pip3 install --editable .
Development
Developing is (re)using as much as possible from homeassistant development setup <https://developers.home-assistant.io/docs/en/development_environment.html>.
Recommended way to develop is to use virtual environment to ensure isolation from rest of your system using the following steps:
$ python3 -m venv .
$ source bin/activate
$ script/setup
after this you should be able to edit the source code and running hass-cli directly:
$ hass-cli
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file homeassistant-cli-0.3.1.tar.gz
.
File metadata
- Download URL: homeassistant-cli-0.3.1.tar.gz
- Upload date:
- Size: 41.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2741fbe9a9daebee68db60ab0d01fd60681814900ce9f9e8f9540da323a74b79 |
|
MD5 | e3b915b6ccc0985329c9d49ae8e5a21c |
|
BLAKE2b-256 | ee70367b672ccccc0bb7dba90ae84b7400236e8323aab1bc1169cc74784e0399 |
File details
Details for the file homeassistant_cli-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: homeassistant_cli-0.3.1-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92fcca14c8a7e9836f2d9ee1401709e34d03863c533da5682e3365421dd1f1f0 |
|
MD5 | ccb3f742a8d49b65ff1436ef4d4fedda |
|
BLAKE2b-256 | a18785edc17a88e99930d269e73bf023eb8d168a9491c4671ce1d29f0e0c2739 |