Help me format this

I have this command that I want to use with shell_command:

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValuudiodevice","value":"PULSE:Default"},"id":1}' http://192.168.1.100:80/jsonrpc -u user:pass

I am having difficulties with the quotes and the double quotes in the command…
As far as I know the formatting has to start and end with a single quote, but the command already has a single quote in the -d option.

so if I use the below formating I get an error

kodi_audio_bluetooth: 'curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValuudiodevice","value":"PULSE:Default"},"id":1}' http://192.168.1.100:80/jsonrpc -u user:pass'

2 options: put that command in a bash file that you can call, or format it this way:

shell_command_name: >
  curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValuudiodevice","value":"PULSE:Default"},"id":1}' http://192.168.1.100:80/jsonrpc -u user:pass

Although not tested with a shell command, I use this for messages in data_templates so I guess it should work. If not revert to 1st option?

The shell_command is definitely a bit weird about how it processes quotes. But I think @lolouk44’s suggestion should work for you.

The reason I’m commenting, though, is that it looks like you have a JSON formatting issue in your original post. I.e., there seems to be an extra } in your body data after "value":"PULSE:Default". Specifically, should:

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValuudiodevice","value":"PULSE:Default"},"id":1}' http://192.168.1.100:80/jsonrpc -u user:pass

be:

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValuudiodevice","value":"PULSE:Default","id":1}' http://192.168.1.100:80/jsonrpc -u user:pass

Ugh. I had this problem. A quoted single quote in YAML is escaped with another single quote. See here: How to show the Raspberry Pi CPU temperature? - #32 by tom_l

It worked! Thank you a lot!
I can now change the audio output of my kodi from analogue to bluetooth speakers using HA!

1 Like

And you can escape a double quote with a back slash () :blush:
https://yaml-multiline.info/

The whole command was wrong… Maybe a copy-paste thing
Here is the correct one:

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"TYPETHEDEVICEHERE"},"id":1}' http://kodiIP:kodiWEBPORT/jsonrpc -u kodiuser:kodipass

This is the original post I made for controlling KODI if anyone is interested.