Home-assistant-cli

I need to control home-assistant device from command line
and I found this


Readme how to use this is minimal
Can somebody give me example?
For example, if I want to switch on light?

I try to turn on light with command below and get error
Don’t understand what means this error?
What am I missing?

root@linux:/etc/monit/conf.d# hasscli state -e switch.bedroom_ceiling_light -a set -s on

Traceback (most recent call last):
File “/usr/local/bin/hass-cli”, line 11, in
load_entry_point(‘homeassistant-cli’, ‘console_scripts’, ‘hass-cli’)()
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/local/lib/python3.4/dist-packages/click/decorators.py”, line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File “/usr/local/lib/python3.4/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/root/Downloads/home-assistant-cli/homeassistant_cli/plugins/state.py”, line 29, in cli
attributes=json.loads(attributes))
File “/usr/lib/python3.4/json/init.py”, line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not ‘NoneType’

Depending on what you’re looking for, you could just use cURL with the API.

curl -H "Content-Type: application/json" -X POST -d '{"entity_id":"light.ceiling","brightness":"255"}' https://URL/api/services/light/turn_on?api_password=PASSWORD

change the entity_id to match yours. And call the correct API endpoint based on what you need. Like

https://URL/api/services/light/turn_off
https://URL/api/services/switch/turn_on

Use the services dev tool to see the correct domain/service combos.

(remember - don’t pass incompatible args - like don’t pass a brightness to light/turn_off - it won’t work)

I try this but light not working
No error in console, don’t understand why

curl -H “Content-Type: application/json” -X POST -d ‘{“entity_id”:“switch.bedroom_ceiling_light”,“state”:“on”}’ https://URL/api/services/switch/turn_on?api_password=xxx

I postponed home-assistant-cli for a couple of reasons. It’s state is still pre-alpha.

Give it a brightness like in my example. “turn on” doesn’t also need an “on” state passed to it.

If it helps, the attributes you pass mirror the ones you’d put in a service call in an automation.

@ih8gates Thanks
@fabaff Since hass-cli not ready for use, I will use curl for now

@dony71 feel free to open issues against hass-cli :wink:

hass-cli is in a better state now (still heavy development) but see Resurrected Feature: Home Assistant CLI