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'
lolouk44
(lolouk44)
August 16, 2018, 1:07pm
2
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
tom_l
August 16, 2018, 3:20pm
4
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
lolouk44
(lolouk44)
August 16, 2018, 5:44pm
6
And you can escape a double quote with a back slash ()
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.
I have 2 raspberrys. One is with home assistant, and the other is with Kodi libreELEC.
They both work fine and now I am looking to do some cool automations with them.
First thing I want to do is have my bluetooth speaker wake me up in the morning by using a Kodi playlist I am gonna add later.
My setup is this:
The kodi is connected to my TV with HDMI so all sounds are coming from it.
I also have a bluetooth speaker I want to use.
Kodi is connected to this too and works perfectly when I sel…