Need Command Line writing help

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.

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

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

Nope didn’t work anymore ideas?

put the command inside a .sh and trigger that from HA?

yes thats what I’m doing now just wanted a cleaner one line solution I need a lot of these.

#!/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

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.

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 \

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