DrJeff
(DrJeff)
May 30, 2017, 5:43pm
1
Here is the command line it works from terminal but need to escape the characters or whatever to get Home Assistant to parse it properly I know it should be eeasy but I’m missing something. Any help would be nice.
/usr/bin/curl -X POST -H "x-ha-access: PASSWORD" -H "Content-Type: application/json" '{"entity_id": "script.master_tight"}' http://192.168.0.10:8123/api/services/script/turn_on
This is getting called inside of Home Assistant via Command Line Cover Component.
ih8gates
(Scott Reston)
May 30, 2017, 8:03pm
2
When defining your shell_command, try defining a block scalar and see if that works. Something like:
shellcommandname: >-
/usr/bin/curl -X POST -H "x-ha-access: PASSWORD" -H "Content-Type: application/json" '{"entity_id": "script.master_tight"}' http://192.168.0.10:8123/api/services/script/turn_on
DrJeff
(DrJeff)
May 30, 2017, 11:40pm
3
What defines the block scaler? “>-”
And it runs as a component Cover Command Line
Command_on: >-
/usr/bin/curl -X POST -H "x-ha-access: PASSWORD" -H "Content-Type: application/json" '{"entity_id": "script.master_tight"}' http://192.168.0.10:8123/api/services/script/turn_on
DrJeff
(DrJeff)
May 31, 2017, 5:59am
4
Nope didn’t work anymore ideas?
put the command inside a .sh and trigger that from HA?
DrJeff
(DrJeff)
May 31, 2017, 6:09am
6
yes thats what I’m doing now just wanted a cleaner one line solution I need a lot of these.
DrJeff
(DrJeff)
May 31, 2017, 6:10am
7
#!/bin/bash
curl -X POST -H "x-ha-access: PASSWORD" \
-H "Content-Type: application/json" \
-d '{"entity_id": "script.master_open"}' \
http://192.168.0.10:8123/api/services/script/turn_on
ih8gates
(Scott Reston)
May 31, 2017, 11:56am
8
Right. > says “the next bit should be one big string”. The - part says “remove whitespace from the front” so you don’t get the leading newline.
I think you can escape individual double-quotes with a pair of double quotes. IE “” is a single, escaped double-quote.
Something like this might work:
/usr/bin/curl -X POST -H "x-ha-access: PASSWORD" -H "Content-Type: application/json" "{""entity_id"": ""script.master_tight""}" http://192.168.0.10:8123/api/services/script/turn_on
Also - make sure you’ve got the right key. “Command_on” isn’t a valid setting for covers.
ih8gates
(Scott Reston)
May 31, 2017, 12:05pm
9
After posting the above, I ran it through YAMLlint and it fails.
I got this to pass.
command_open: "/usr/bin/curl -X POST -H \"x-ha-access: PASSWORD\" -H \"Content-Type: application/json\" \"{\"\"entity_id\"\": \"\"script.master_tight\"\"}\" http://192.168.0.10:8123/api/services/script/turn_on"
But YAMLLint optimizes for Ruby. So you might still need to escape those double-quotes with another double-quote rather than a \
RobDYI
May 31, 2017, 12:52pm
10
I have been looking for a solution to this as well, I call a python script presently.
import requests
import simplejson as json
url = "http://192.168.2.186:8124/api/services/switch/toggle"
data = {"entity_id": "switch.doorbell"}
headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers)
I tried this and although it checked in the configuration checker it fails. (It ran all the command shell scripts after it)
# doorbell: python3 /Users/username/.homeassistant/mp3/doorbell.py
doorbell: >-
/usr/bin/curl -X POST -H "Content-Type: application/json" '{"entity_id": "switch.doorbell"}' http://192.168.2.186:8124/api/services/switch/toggle