I’m trying to set up a command to control my Logitech Media Service using JSON/RPC. The syntax below is being rejected by HA - could anyone advise what I’ve done wrong? The curl command works fine from an Ubuntu command line
kitchen_music:
command_on: 'curl -X POST -d '{"id":0,"params":["cc:cc:ba:8b:e2:ec",["playlist","play","randomplay://track"]],"method":"slim.request"}' http://192.168.1.36:9000/jsonrpc.js'
My guess is that it’s due to the quotes. Two systems are handling that string, Home Assistant and shell, both have specific requirements and how you use single and double quotes must satisfy the two systems.
You already know the curl command works in the shell so now it’s a matter of “packaging” the command to satisfy Home Assistant without causing it to be corrupted for use by shell.
Or at least that’s my theory …
Start your experiments by simply eliminating the outer single-quotes. The YAML processor should still understand it’s dealing with a string.
kitchen_music:
command_on: curl -X POST -d '{"id":0,"params":["cc:cc:ba:8b:e2:ec",["playlist","play","randomplay://track"]],"method":"slim.request"}' http://192.168.1.36:9000/jsonrpc.js
If that doesn’t resolve it, you might have to resort to escaping the meaning of the inner single-quotes using a backslash. My concern here is that it might pass the backslashes on to shell as literal backslashes (but it shouldn’t).
kitchen_music:
command_on: 'curl -X POST -d \'{"id":0,"params":["cc:cc:ba:8b:e2:ec",["playlist","play","randomplay://track"]],"method":"slim.request"}\' http://192.168.1.36:9000/jsonrpc.js'
EDIT
Correction. Leading single-quote was in the wrong place.
The first single-quote in a doubled set of single-quotes '' instructs Home Assistant to escape the meaning of the second single-quote. In other words, it’s the same as using a backslash \' to escape the meaning of a single-quote.