Giter Site home page Giter Site logo

home-assistant-ecosystem / home-assistant-cli Goto Github PK

View Code? Open in Web Editor NEW
425.0 16.0 63.0 707 KB

:computer: Command-line tool for Home Assistant

License: Other

Python 97.55% Shell 2.24% Dockerfile 0.21%
cli home-automation home-assistant iot smart-home

home-assistant-cli's Introduction

Home Assistant Command-line Interface (hass-cli)

Coveralls License PyPI release

The Home Assistant Command-line interface (hass-cli) allows one to work with a local or a remote Home Assistant Core or Home Assistant (former Hass.io) instance directly from the command-line.

hass-cli screencast

Installation

To use latest release:

$ pip install homeassistant-cli

To use latest pre-release from dev branch:

$ pip install git+https://github.com/home-assistant-ecosystem/home-assistant-cli@dev

The developers of hass-cli usually provide up-to-date packages for recent Fedora and EPEL releases. Use dnf for the installation:

$ sudo  dnf -y install home-assistant-cli

The community is providing support for macOS through homebew.

$ brew install homeassistant-cli

Keep in mind that the available releases in the distribution could be out-dated.

home-assistant-cli is also available for NixOS.

To use the tool on NixOS. Keep in mind that the latest release could only be available in the unstable channel.

$ nix-env -iA nixos.home-assistant-cli

Docker

If you do not have a Python setup you can try use hass-cli via a container using Docker.

$ docker run homeassistant/home-assistant-cli

To make auto-completion and access environment work like other scripts you'll need to create a script file to execute.

$ curl https://raw.githubusercontent.com/home-assistant/home-assistant-cli/master/docker-hass-cli > hass-cli
$ chmod +x hass-cli

Now put the hass-cli script into your path and you can use it like if you had installed it via command line as long as you don't need file system access (like for hass-cli template).

Setup

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 scroll down to "Long-Lived Access Tokens").

Then you can use --server and --token parameter on each call or as is recommended setup HASS_SERVER and HASS_TOKEN environment variables.

$ export HASS_SERVER=https://homeassistant.local:8123
$ export HASS_TOKEN=<secret>

Once that is enabled, run one of the following commands to enable autocompletion for hass-cli commands.

$ source <(_HASS_CLI_COMPLETE=bash_source hass-cli) # for bash
$ source <(_HASS_CLI_COMPLETE=zsh_source hass-cli)  # for zsh
$ eval (_HASS_CLI_COMPLETE=fish_source hass-cli)    # for fish

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.

Most commands returns a table 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                           LOCATION         REQUIRES_API_PASWORD  VERSION
  https://home-assistant.local:8123  Fort of Solitude False                 0.86.2

If you prefer yaml you can use --output=yaml:

$ hass-cli --output yaml info
  base_url: https://home-assistant.local:8123
  location_name: Wayne Manor
  requires_api_password: false
  version: 0.86.2

To get list of states you use state list:

$ hass-cli state list
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
[...]

You can use --no-headers to suppress the header.

--table-format let you select which table format you want. Default is simple but you can use any of the formats supported by https://pypi.org/project/tabulate/: plain, simple, github, grid, fancy_grid, pipe, orgtbl, rst, mediawiki, html, latex, latex_raw, latex_booktabs or tsv

Finally, you can also via --columns control which data you want shown. Each column has a name and a jsonpath. The default setup for entities are:

--columns=ENTITY=entity_id,DESCRIPTION=attributes.friendly_name,STATE=state,CHANGED=last_changed

If you for example just wanted the name and all attributes you could do:

$ hass-cli --columns=ENTITY="entity_id,ATTRIBUTES=attributes[*]" state list zone
ENTITY             ATTRIBUTES
zone.school        {'friendly_name': 'School', 'hidden': True, 'icon': 'mdi:school', 'latitude': 7.011023, 'longitude': 16.858151, 'radius': 50.0}
zone.unnamed_zone  {'friendly_name': 'Unnamed zone', 'hidden': True, 'icon': 'mdi:home', 'latitude': 37.006476, 'longitude': 2.861699, 'radius': 50.0}
zone.home          {'friendly_name': 'Andersens', 'hidden': True, 'icon': 'mdi:home', 'latitude': 27.006476, 'longitude': 7.861699, 'radius': 100}

You can get more details about a state by using yaml or json output format. In this example we use the shorthand of output: -o:

$ hass-cli -o yaml state 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 state 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 state edit sensor.test --json='{ "state":"off"}'

List possible services with or without a regular expression filter:

$ hass-cli service list 'home.*toggle'
  DOMAIN         SERVICE    DESCRIPTION
  homeassistant  toggle     Generic service to toggle devices on/off...

For more details the YAML format is useful:

$ hass-cli -o yaml service list homeassistant.toggle
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

You can get history about one or more entities, here getting state changes for the last 50 minutes:

$ hass-cli state history --since 50m light.kitchen_light_1 binary_sensor.presence_kitchen
  ENTITY                          DESCRIPTION      STATE    CHANGED
  binary_sensor.presence_kitchen  Kitchen Motion   off      2019-01-27T23:19:55.322474+00:00
  binary_sensor.presence_kitchen  Kitchen Motion   on       2019-01-27T23:21:44.015071+00:00
  binary_sensor.presence_kitchen  Kitchen Motion   off      2019-01-27T23:22:02.330566+00:00
  light.kitchen_light_1           Kitchen Light 1  on       2019-01-27T23:19:55.322474+00:00
  light.kitchen_light_1           Kitchen Light 1  off      2019-01-27T23:36:45.254266+00:00

The data is sorted by default as Home Assistant returns it, thus for history it is useful to sort by a property:

$ hass-cli --sort-by last_changed state history --since 50m  light.kitchen_light_1 binary_sensor.presence_kitchen
ENTITY                          DESCRIPTION      STATE    CHANGED
binary_sensor.presence_kitchen  Kitchen Motion   off      2019-01-27T23:18:00.717611+00:00
light.kitchen_light_1           Kitchen Light 1  on       2019-01-27T23:18:00.717611+00:00
binary_sensor.presence_kitchen  Kitchen Motion   on       2019-01-27T23:18:12.135015+00:00
binary_sensor.presence_kitchen  Kitchen Motion   off      2019-01-27T23:18:30.417064+00:00
light.kitchen_light_1           Kitchen Light 1  off      2019-01-27T23:36:45.254266+00:00

Note: the --sort-by argument is referring to the attribute in the underlying json/yaml NOT the column name. The advantage for this is that it can be used for sorting on any property even if not included in the default output.

Areas and Device Registry

Since v0.87 of Home Assistant there is a notion of Areas in the Device registry. hass-cli lets you list devices and areas and assign areas to devices.

Listing devices and areas works similar to list Entities.

$ hass-cli device list
ID                                NAME                           MODEL                            MANUFACTURER        AREA
a3852c3c3ebd47d3acac195478ca6f8b  Basement stairs motion         SML001                           Philips             c6c962b892064a218e968fcaee7950c8
880a944e74db4bb48ea3db6dd24af357  Basement Light 2               TRADFRI bulb GU10 WS 400lm       IKEA of Sweden      c6c962b892064a218e968fcaee7950c8
657c3cc908594479aab819ff80d0c710  Office                         Hue white lamp                   Philips             None
[...]

$ hass-cli area list
ID                                NAME
295afc88012341ecb897cd12d3fbc6b4  Bathroom
9e08d89203804d5db995c3d0d5dbd91b  Winter Garden
8816ee92b7b84f54bbb30a68b877e739  Office
[...]

You can create and delete areas:

$ hass-cli area delete "Old Shed"
-  id: 1
   type: result
   success: true
   result: success

$ hass-cli area create "New Shed"
-  id: 1
   type: result
   success: true
   result:
       area_id: cdd09a80f03a4cc59d2943053c0414c0
       name: New Shed

You can assign area to a specific device. Here the Kitchen area gets assigned to device named "Cupboard Light".

$ hass-cli device assign Kitchen "Cupboard Light"

Besides assigning individual devices you can assign in bulk:

$ hass-cli device assign Kitchen --match "Kitchen Light"

The above line will assign Kitchen area to all devices with substring "Kitchen Light".

You can also combine individual and matched devices in one line:

$ hass-cli device assign Kitchen --match "Kitchen Light" eab9930f8652408882cc8cb604651c60 Cupboard

Above will assign area named "Kitchen" to all devices having substring "Kitchen Light" and to specific area with id "eab9930..." or named "Cupboard".

Events

You can subscribe and watch all or a specific event type using event watch.

$ hass-cli event watch

This will watch for all event types, you can limit to a specific event type by specifying it as an argument:

$ hass-cli event watch deconz_event

Home Assistant (former Hass.io)

If you are using Home Assistant (former Hass.io) there are commands available for you to interact with Home Assistant services/systems. This includes the underlying services like the supervisor.

Check the Supervisor release you are running:

$ hass-cli ha supervisor info
result: ok
data:
 version: '217'
 version_latest: '217'
 channel: stable
 [...]

Check the Core release you are using at the moment:

$ hass-cli ha core info
result: ok
data:
    version: 0.108.2
    version_latest: 0.108.3
    [...]

Update Core to the latest available release:

$ hass-cli ha core update

Other

You can call services:

$ 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 (local) 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 it's 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 "$(_HASS_CLI_COMPLETE=source hass-cli)"

Once enabled there is autocompletion for commands and for certain attributes like entities:

$ hass-cli state 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
[...]

Note: For this to work you'll need to have setup the following environment variables if your Home Assistant installation is secured and not running on localhost:8123:

export HASS_SERVER=http://homeassistant.local:8123
export HASS_TOKEN=eyJ0eXAiO-----------------------ed8mj0NP8

Help

$ hass-cli
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 or `auto` for automatic
                                  detection. Can also be set with the
                                  environment variable HASS_SERVER.  [default:
                                  auto]
  --token TEXT                    The Bearer token for Home Assistant
                                  instance. Can also be set with the
                                  environment variable HASS_TOKEN.
  --password TEXT                 The API password for Home Assistant
                                  instance. Can also be set with the
                                  environment variable HASS_PASSWORD.
  --timeout INTEGER               Timeout for network operations.  [default:
                                  5]
  -o, --output [json|yaml|table|ndjson|auto]
                                  Output format.  [default: auto]
  -v, --verbose                   Enables verbose mode.
  -x                              Print backtraces when exception occurs.
  --cert TEXT                     Path to client certificate file (.pem) to
                                  use when connecting.
  --insecure                      Ignore SSL Certificates. Allow to connect to
                                  servers with self-signed certificates. Be
                                  careful!
  --debug                         Enables debug mode.
  --columns TEXT                  Custom columns key=value list. Example:
                                  ENTITY=entity_id,
                                  NAME=attributes.friendly_name
  --no-headers                    When printing tables don't use headers
                                  (default: print headers)
  --table-format TEXT             Which table format to use.
  --sort-by TEXT                  Sort table by the jsonpath expression.
                                  Example: last_changed
  --help                          Show this message and exit.

Commands:
  area        Get info and operate on areas from Home Assistant...
  completion  Output shell completion code for the specified shell (bash or...
  config      Get configuration from a Home Assistant instance.
  device      Get info and operate on devices from Home Assistant...
  discover    Discovery for the local network.
  entity      Get info on entities from Home Assistant.
  event       Interact with events.
  ha          Home Assistant (former Hass.io) commands.
  info        Get basic info from Home Assistant.
  map         Show the location of the config or an entity on a map.
  raw         Call the raw API (advanced).
  service     Call and work with services.
  state       Get info on entity state from Home Assistant.
  system      System details and operations for Home Assistant.
  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 Home Assistant development setup.

Recommended way to develop is to use virtual environment to ensure isolation from rest of your system using the following steps:

Clone the git repository and do the following:

$ 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

home-assistant-cli's People

Contributors

benleb avatar chenrui333 avatar davidcollins001001 avatar dependabot-preview[bot] avatar dependabot[bot] avatar drjeff avatar dtrodrigues avatar dwradcliffe avatar evgeni avatar fabaff avatar frenck avatar haakonstorm avatar jasonk avatar jpnadas avatar makuser avatar maxandersen avatar michaelwoods avatar mildsunrise avatar musicinmybrain avatar onkelbeh avatar pschmitt avatar quamilek avatar robbiet480 avatar rufik avatar rytilahti avatar scop avatar sytone avatar walnerz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

home-assistant-cli's Issues

add template command for template processing

hass-cli template run mytemplate.j2 output would be result of running home assistant template function.

hass-cli template run-local mytemplate.j2 mytemplate.data.yaml output would be result of running templates local with access to things like state, device registry etc. some of which are not currently available in remote home assistant.

Would be nice if homeassistant could receive custom data, but at the moment that is not there which makes it interesting to run templates locally.

`event listen`

hass-cli event listen <event_type>*

which will login and subscribe for each event_type listed and then
for every received event print formatted output. Might want option to add additional filtering.

add hass.io relevant commands

if server is on hassio we could expose addon commands

hassio addon open <addon name> to open webui
hassio addon restart <addon name> to restart etc.

also hassio system commands could be made.

hassio system restart
hassio ha restart ...

Click Error with Python3 and ANSI Encoding

Maybe too early but I cannot run hass-cli on MacOS Sierra

retinabook:home-assistant-cli steffen$ hass-cli 
Traceback (most recent call last):
  File "/usr/local/bin/hass-cli", line 11, in <module>
    load_entry_point('homeassistant-cli', 'console_scripts', 'hass-cli')()
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 675, in main
    _verify_python3_env()
  File "/usr/local/lib/python3.5/site-packages/click/_unicodefun.py", line 119, in _verify_python3_env
    'mitigation steps.' + extra)
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.  Either run this under Python 2 or consult http://click.pocoo.org/python3/ for mitigation steps.

This system lists a couple of UTF-8 supporting locales that
you can pick from.  The following suitable locales where
discovered: af_ZA.UTF-8, am_ET.UTF-8, be_BY.UTF-8, bg_BG.UTF-8, ca_ES.UTF-8, cs_CZ.UTF-8, da_DK.UTF-8, de_AT.UTF-8, de_CH.UTF-8, de_DE.UTF-8, el_GR.UTF-8, en_AU.UTF-8, en_CA.UTF-8, en_GB.UTF-8, en_IE.UTF-8, en_NZ.UTF-8, en_US.UTF-8, es_ES.UTF-8, et_EE.UTF-8, eu_ES.UTF-8, fi_FI.UTF-8, fr_BE.UTF-8, fr_CA.UTF-8, fr_CH.UTF-8, fr_FR.UTF-8, he_IL.UTF-8, hr_HR.UTF-8, hu_HU.UTF-8, hy_AM.UTF-8, is_IS.UTF-8, it_CH.UTF-8, it_IT.UTF-8, ja_JP.UTF-8, kk_KZ.UTF-8, ko_KR.UTF-8, lt_LT.UTF-8, nl_BE.UTF-8, nl_NL.UTF-8, no_NO.UTF-8, pl_PL.UTF-8, pt_BR.UTF-8, pt_PT.UTF-8, ro_RO.UTF-8, ru_RU.UTF-8, sk_SK.UTF-8, sl_SI.UTF-8, sr_YU.UTF-8, sv_SE.UTF-8, tr_TR.UTF-8, uk_UA.UTF-8, zh_CN.UTF-8, zh_HK.UTF-8, zh_TW.UTF-8

Columns not applied to entity get command

Version used: 0.4.4

Problem:
The --columns parameter is not applied to the entity get command only for entity list.
I try to create an i3 status bar entry for delaying trains and only need the state value, therefore tried to filter by columns but it didn't work.
Additionally it would be nice to have this as a direct option (e.g. -q for quiet output with only the state).

Otherwise, great tool, using it already with rofi to quickly toggle the lights in my flat ;).

Doesn't work on Hass.io anymore.

After upgrading to 0.2.0, the CLI doesn't work anymore (changes in #23, #26).

image

Hass.io Supervisor shows this log:

18-12-11 21:20:57 WARNING (MainThread) [hassio.api.security] No API token provided for /api/config

The weird thing is though, hass-cli info does not fail (just an empty result):

image

For the record, I do not have HASS_SERVER or HASS_TOKEN env variables set. Just a (valid) HASSIO_TOKEN.

support for client side certifactes

those using HA requiring client side certificates should have a way to run.

curl uses --key for the key and --cert for the certificate. i.e.

curl -v \
  --cacert ./ca.pem \
  --key ./admin-key.pem \
  --cert ./admin.pem \
  https://xxxx/api/v1/

requests supports all three as documented at http://docs.python-requests.org/en/master/user/advanced/
idea from this thread: https://www.reddit.com/r/homeassistant/comments/a56qwa/hasscli_new_command_line_tool_for_home_assistant/eblbjjy/?context=3

list, toggle and other commands should have a "human" output format

when running list it would be more useful by default to get a table with columns for each entity rather than json/yaml dump.

same goes for toggle command which in its return values get a list of entities that have been verified to be toggled - just as well show the list of those names rather than raw object dumps.

example:

$ hass-cli entity list
NAME               FRIENDLY NAME      STATE
sensor.yr          sensor for weather    on
light.entrance entrance light             off

warning report

hass-cli --version

hass-cli, version 0.4.4

hass-cli config whitelist-dirs

Trying to locate Home Assistant on local network...
Exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/zeroconf.py", line 1179, in handle_read
data, (addr, port) = socket_.recvfrom(_MAX_MSG_ABSOLUTE)
OSError: [Errno 9] Bad file descriptor
Found and using http://192.168.1.4:8123 as server
DIRECTORY
/config/www

pip3.6 list | grep -i zero

zeroconf (0.21.3)

allow --insecure to skip hostname matching

if your server is running with duckdns or similar you will get a certificate error if trying to connect directly via the IP - even if accepting all certificates which is what --insecure does.

There might be a way to work around this in ssl/requests layer but requires some explicit install of additional dependencies - see https://github.com/urllib3/urllib3/blob/master/src/urllib3/packages/ssl_match_hostname/_implementation.py for details.

 import ssl
   
    ssl.match_hostname = lambda cert, hostname: True

should be enough if ipaddress and ssl are installed (which depends on python version)

have a way to force editor being used before updating/calling commands

would be nice hass-cli edit entity <entityname> --attributes=friendly_name=Peace and hass-cli service call homeassistant.toggle <entityname> would be able to always open editor of the sent command before submitting it.

Maybe add a --editor flag to enforce it and not just when no attributes/states are given ?

device and area registry support

Would be nice to list/query devices and manipulate areas.

$ hass-cli area list
AREA
Bathroom
Winter Garden
Kitchen
Guest Room

$ hass-cli area create "Small Bathroom"

$ hass-cli area delete "Small Bathroom"

$ hass-cli device list "Kitchen.*"

# make inventory overview
$ hass-cli --no-headers --columns manufacturer,model device list | sort | uniq -c | sort -nr 
  10 IKEA of Sweden      TRADFRI bulb GU10 WS 400lm
   8 Philips             SML001
   7 LUMI                lumi.sensor_magnet.aq2
   6 Sonos               Play:1
   6 Philips             LTW012
   6 Philips             LCT003
   6 Philips             Hue color spot
   6 Philips             Hue ambiance candle
   5 Philips             LWG001

# Assign area "Kitchen" to any entity matching "Kitchen Light" filter.
$ hass-cli device assign --filter Kitchen "Kitchen Light"

hass-cli: command not found

After installing with pip, trying to run the source <(hass-cli completion zsh) command fails:

hass-cli: command not found

I tried to log out and in of SSH, but no luck.

support for websocket api

new apis are added in websockets, not all available via restapi.

Would be good to be able to do things like:

hass-cli device list that would access device registry in the websockets api

or things like
hass-cli entity watch <...> would listen on changes for state changes via websockets api

and even more generically:

hass-cli raw ws <method> would run and wait for result on websockets api.

could even add autocompletion for well known ws endpoints in the latter case.

automate relase from master tags

something always goes wrong or I forget something during release - would be so much nicer if just tagging master would ensure release happens at least for pypi without need for human intervention.

option for ignoring certificate mismatch

when you have duckdns or similar with certifiactes using your local ip result in errors like:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 376, in connect
    _match_hostname(cert, self.assert_hostname or hostname)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 386, in _match_hostname
    match_hostname(cert, asserted_hostname)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 327, in match_hostname
    % (hostname, dnsnames[0]))
ssl.SSLCertVerificationError: ("hostname 'hassio.local' doesn't match 'andersens.duckdns.org'",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='hassio.local', port=8123): Max retries exceeded with url: /api/discovery_info (Caused by SSLError(SSLCertVerificationError("hostname 'hassio.local' doesn't match 'yourha.duckdns.org'")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/hass-cli", line 11, in <module>
    load_entry_point('homeassistant-cli', 'console_scripts', 'hass-cli')()
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/max/code/hass-cli/homeassistant_cli/plugins/info.py", line 15, in cli
    click.echo(format_output(ctx, req(ctx, "get", "discovery_info")))
  File "/Users/max/code/hass-cli/homeassistant_cli/helper.py", line 63, in req
    resp = req_raw(ctx, method, endpoint, *args)
  File "/Users/max/code/hass-cli/homeassistant_cli/helper.py", line 43, in req_raw
    response = requests.get(url, headers=headers, timeout=ctx.timeout)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='hassio.local', port=8123): Max retries exceeded with url: /api/discovery_info (Caused by SSLError(SSLCertVerificationError("hostname 'hassio.local' doesn't match 'yourha.duckdns.org'")))

would be nice having an option that just warns about the mismatch but will connect.

see https://stackoverflow.com/questions/15445981/how-do-i-disable-the-security-certificate-check-in-python-requests for options.

`hass-cli lint` to sanity check states/groups etc.

i just bump into having setup a group that I thought was all great but i noticed it reported state unknown because I made a typo for the ligts.

would be nice to have a lint command or similar that could check for "dumb" mistakes like this ;)

Running source <(hass-cli comletion zsh) fails

Tried running the source <(hass-cli completion zsh) returns the following error:

pi@hassbian:~ $ source <(hass-cli completion zsh)

-bash: /dev/fd/63: line 10: syntax error near unexpected token `descr'
-bash: /dev/fd/63: line 10: `    for key descr in ${(kv)response}; do'

I had to install hass-cli with sudo in order to make it install. I tried to run the source command with sudo, but that returns command not found.

sort by column should be possible

with #79 it is more useful than ever to be able to sorty by i.e. CHANGED column.

something like --sort-by <jsonpath> using same notion as done for columns; then do the sorting BEFORE making the table data.

Hass.io compatibility

For Hass.io users the CLI is harder to get running. With a little bit of code, this CLI would probably just work out of the box for these users.

Steps to take:

  • HASS_SERVER environment variable is absent.
  • HASS_TOKEN environment variable is absent.
  • Detect if the HASSIO_TOKEN environment variable is present.
  • If present, use http://hassio/homeassistant as the server URL
  • If present, use the HASSIO_TOKEN environment variable as the bearer token.

replace 'unsorted' with source in zsh completion

currently you get a menu with a header called unsorted in zsh completion.

would be nicer if it had the used server name in there.

just need to replace "unsorted" with server name in completion.py

consider removing homeassistant dependency

currently we depend on homeassistant itself - mainly just to get/share a few constants.

This means a user need to install homeassistant's own dependencies too even though they don't need.

would be nice to avoid that + might be easier to handle mulitple version differences if no hard dep to homeassistant.

add ha/system commands

expose commands to do the typical 'system' level commands.

config check
reload core
reload groups
reload automations
reload all ?
server restart
server shutdown

look into using transfer.sh uploads as ephemeral storage in travis

can be hard to ask users to setup full dev env to try out a pr.

travis for security reasons don't allow upload or any operations requiring use of encoded keys.

idea is to use transfer.sh to upload the generated wheel and then post ocmment back to pull-request with command for installing the built wheel. transfer.sh deletes it automatically after 14 days which should be sufficient for most PR work.

have a consistent use of commands/subcommands

currently we have commands like:

get (state|event|service)
edit (state|event)
delete (state)
toggle (entity)
completion (zsh|bash)

etc.

I did the get/edit/delete initially since I thought there would be more things to edit but as things are now we end up with other commands that does not follow the same structure so i'm more inclined to move to
something like:

  • entity (list|edit|get|delete|toggle)
  • event (fire)
  • service (list|explain|call)
  • completion (zsh|bash)
  • logs (get)
  • raw (get|post)

so something more like following <thing> <operation> <target> pattern instead.

piping is not working

hass-cli entity list | pbcopy or any other pipe destination result in some weird result.

For some reason output are not properly piped.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.