Post JSON to XBMC (KODI)

1,169 views
Skip to first unread message

Chrishiscox Chris

unread,
Feb 24, 2015, 10:35:31 AM2/24/15
to ope...@googlegroups.com

I am attempting to go one stage further than queryimg my kodi servers. I have three of them, and would like to set them to party mode using a json statement.
If I type in browser address bar the following: (note chrome auto formats it to safe characters, which i think I need for SendHttpGet or Post.

This is my rule, which doesnt work.


rule "Set Party Mode on Kodi"
when 
Item kodi_party_music received command
then
switch(receivedCommand) {
case 0 : {sendCommand(XBMC_OpenMedia, "http://10.0.24.2{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "partymode": "music" } }, "id": 1 }")}

}
end

I have also tried the xbmc bindings, which open files etc, but oes nothing when Ido the following:

case 1 : sendCommand(kodiDVR_OpenMedia,"partymode")
Any body got bright idea?

Thanks

Chris 

Chris Hiscox

unread,
Feb 25, 2015, 9:59:53 AM2/25/15
to ope...@googlegroups.com
I have tested with Curl, and that seems broken too!

I send executeCommandLine("curl --user kodi:kodi1989 --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.Open", "params": {"item": { "partymode": "music" } } }' 'http://10.0.24.7/jsonrpc'

and the response I get from the log is
14:53:13.989 ERROR o.o.c.s.ScriptExecutionThread[:50]- Error during the execution of rule 'Set Party Mode on Kodi': The name 'id' cannot be resolved to an item or type.

 I have tried replacing the " with %22 , and preceding with a \. Still same error.
How can I pass a string with double quotes in  it via openhab -  I can see openhab is confuised and thinks the " indicates another item.

Any suggestions?

Chris

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/T3OjeiByrPw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/12539969-7605-4d3a-87f0-11dc08434daf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcel Erkel

unread,
May 8, 2015, 12:14:42 PM5/8/15
to ope...@googlegroups.com, ch...@of1.org
Hi,

Not sure if this issue is still valid, but the following works for me:

I used http://www.freeformatter.com/url-encoder.html to URL-encode the following json:

{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"partymode":"music"}},"id":1}

which resulted in the following output:

%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Player.Open%22%2C%22params%22%3A%7B%22item%22%3A%7B%22partymode%22%3A%22music%22%7D%7D%2C%22id%22%3A1%7D

I then created the following rule:

rule "Set Party Mode on Kodi"
when

   
Item kodi_party_music changed
then
   
var String json = "%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Player.Open%22%2C%22params%22%3A%7B%22item%22%3A%7B%22partymode%22%3A%22music%22%7D%7D%2C%22id%22%3A1%7D"
    sendHttpGetRequest
("http://kodi:kodi...@10.0.24.7/jsonrpc?request=" + json)
end


This works for me.

Using executeCommandLine with curl and escaping the " using a backslash like \" did not result in any errors in the openhab.log but neither did it work. When I traced using Wireshark on my laptop where Kodi was running, no tcp/ip packets arrived. I then tried using the full path to the curl command, but that also did not work.
What did work was putting the command in a shell script and executing the shell script but I think the sendHttpGetRequest method is a much cleaner approach.

Hope this helps!

Cheers,
Marcel

P.S. Make sure that the Webserver in Kodi is indeed running on port 80 and not 8080.

wolffromthenorth

unread,
Sep 11, 2015, 3:56:40 AM9/11/15
to openhab, ch...@of1.org
Any update on this as i'm trying to do the same thing and i'm not succeeding.

i would like to execute a addon script in xbmc wich i can do with a json request as described, works from the browser but not in openhab.
please help

Reply all
Reply to author
Forward
0 new messages