hass-cli 0.5: 区域, 设备 Registry and event CLI

With Home Assistant 0.87 out we got 区域 and 设备 Registry UI thus it is time to do a 发布 of hass-cli that allows you to operate on these in a terminal.

This 发布 adds the following features:

  • 区域 list, create, delete, and rename
  • 设备 list and assign
  • Event watch

To get it run:

$ pip3 安装 homeassistant-cli

And once you have configured some of the new things you can like:

Create an 区域:

$ hass-cli 区域 create Attic
-  id: 1
   type: result
   success: true
   result:
      area_id: 83977bdb16524579a856560925a791a7
      name: Attic

List all your 区域:

$ hass-cli 区域 list
ID                                NAME
295afc88012341ecb897cd12d3fbc6b4  Bathroom
9e08d89203804d5db995c3d0d5dbd91b  Winter Garden
8816ee92b7b84f54bbb30a68b877e739  Office
e6ebd3e6f6e04b63a0e4a109b4748584  Kitchen
f7f5412a9f47436da669a537e0c0c10f  Livingroom
bc98c209249f452f8d074e8384780e15  Hallway
83977bdb16524579a856560925a791a7  Attic

List 设备 matching a pattern:

$ hass-cli 设备 list "Kitchen.*灯光*"
ID                                NAME                      MODEL                    MANUFACTURER    区域
f9cad07069c74d519fbe84811c91f1fb  Kitchen 灯光 2           LCT003                   Philips         e6ebd3e6f6e04b63a0e4a109b4748584
d02ec64623ae4407a80b903cbc061511  Kitchen 灯光 3           LCT003                   Philips         e6ebd3e6f6e04b63a0e4a109b4748584
820c9e511fce42ea92b228c18710aa56  Kitchen 灯光 1           LCT003                   Philips         e6ebd3e6f6e04b63a0e4a109b4748584
417dd42c0c764765aa29580d77b8b7ad  Kitchen 灯光 5           LCT003                   Philips         e6ebd3e6f6e04b63a0e4a109b4748584

Like with entity list you can filter and pipe results to get interesting things.

How about a inventory count?

$ hass-cli --no-headers --columns manufacturer,model 设备 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
 5 Philips             LCT012
 5 Philips             Hue color candle
 5 IKEA of Sweden      TRADFRI bulb E14 W op/ch 400lm
 4 Sonos               One
 4 Philips             RWL021
 4 Philips             Hue color lamp
 4 IKEA of Sweden      TRADFRI 遥控器 control
 3 Philips             Hue lightstrip plus
 3 OSRAM               Color temperature 灯光
 3 LUMI                lumi.vibration.aq1
 3 IKEA of Sweden      TRADFRI transformer 30W
 ....
 

And then my favorite feature, assign of 区域 to a 设备:

$ hass-cli 设备 assign Kitchen "Kitchen 灯光 2"

or even more powerful, bulk-assign to any 实体 matching a certain pattern:

$ hass-cli 设备 assign --match "Kitchen" Kitchen
  Successfully assigned 'Kitchen' to 'Kitchen'
  Successfully assigned 'Kitchen' to 'Kitchen table left'
  Successfully assigned 'Kitchen' to 'Kitchen table right'
  Successfully assigned 'Kitchen' to 'Kitchen left middle at window'
  Successfully assigned 'Kitchen' to 'Kitchen front right at fridge'
  Successfully assigned 'Kitchen' to 'Kitchen left back at hub'
  Successfully assigned 'Kitchen' to 'Kitchen left back at bar'
  Successfully assigned 'Kitchen' to 'Kitchen right back at sink'
  Successfully assigned 'Kitchen' to 'Kitchen right middle at oven'
  Successfully assigned 'Kitchen' to 'Kitchen 灯光 2'
  Successfully assigned 'Kitchen' to 'Kitchen 灯光 3'
  .... 
  

And finally as a little bonus feature you can now watch the event bus from the CLI:

All events:

$ hass-cli event watch

or specific events:

$ hass-cli event watch call_service

At the moment the output is raw JSON, that will improve in a future 发布.

The full change list including bugfixes from community is as follows:

What's Changed

New features:

  • 设备, 区域 and event support 237ade8 @maxandersen
  • add minimal dockerfile 2b00bd7 Ben Lebherz

Bug fixes:

  • fix(实体): honor --columns in 实体 get 67397a1 @maxandersen
  • Fix result reporting from 服务 calls 14fc952 @maxandersen
  • Remove pyaml and move to ruamel only for yaml df9f8c2 @maxandersen

Minor fixes:

  • fix: 发布 0.5.0 版本 200a099 @maxandersen
  • fix: be pep440 complant 98320f8 @maxandersen
  • fix: fix lint 错误 eca26fa @maxandersen
  • fix: fix lint 错误 ffd2369 @maxandersen
  • enable deploy of git timestamped build 4b27a65 @maxandersen
  • Merge branch 'master' into dev caaf7b1 @maxandersen
  • add Docker reference d3b64e8 @maxandersen
  • docs: add docs for 区域, 设备 and event watch ee4f74a @maxandersen
  • Make dockerfile build from source + entrypoint b7f8764 @maxandersen
  • Fix lint issue 8bb0c9e @fabaff
  • Fix lint issues 58fdc83 @fabaff
  • fix bad typing 499b544 @maxandersen
  • fix editor formatting 86d9bf8 @maxandersen
  • Fix 版本 3765a03 @maxandersen
  • Fix 版本 marker edbe4bf @maxandersen

Have fun!

Max Rydahl Andersen