Kodi Community Forum
Solved Runscript from a JSON Command - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Solved Runscript from a JSON Command (/showthread.php?tid=234884)

Pages: 1 2


Runscript from a JSON Command - DaveBlake - 2015-08-10

Is it possible (in Kodi 15.0) to execute a self written Python script stored in the Kodi userdata folder using a JSON command?

I have a script which simplifies quickly switching audio settings without menus of data entry etc., and I have set up a keymap that runs this on a certain key press. I would like to run the same script remotely i.e. from a web browser on my home network. An app on my Andriod tablet that did the same would be great - click the icon and audio output device changes - since I usually use an app (Kore or Yatse) to control Kodi it would be close to hand, but that is a later step.

I'm sure I've seen the answer somewhere but can't find it. Maybe I have to create an addon to make it possible?


RE: Runscript from a JSON Command - helta - 2015-08-10

something like this?


RE: Runscript from a JSON Command - DaveBlake - 2015-08-10

Helta, yes the script is something like that How To. Got the script bit sorted, but how can I invoke that script remotely? That is sat on the sofa with a tablet, and the video about to play but audio output is still pointed at my hifi that is turned off and I want to switch to the HDMI output.....


RE: Runscript from a JSON Command - helta - 2015-08-10

You could bind a keypress to invoke the script.

So for example in a keyboard.xml, you could use:
Code:
<keymap>
  <global>
    <keyboard>
      <!-- Put your key mappings here -->
      <zero>RunScript("C:\Users\td\Dropbox\docs\audio_switch.py")</zero>
    </keyboard>
  </global>
</keymap>

Pressing zero in this case, will run the script.


RE: Runscript from a JSON Command - DaveBlake - 2015-08-11

Helta, yes like I said in the op I have set up a keymap that runs the script on a certain key press.

I hope that someone comes along that knows if I can execute a Python script using JSON?


RE: Runscript from a JSON Command - Ned Scott - 2015-08-11

I don't know if there is a JSON-RPC way to execute scripts, but why not use JSON-RPC to change the setting? What you are currently asking is this:

JSON-RPC command -> to trigger a python script -> to trigger a JSON-RPC command


RE: Runscript from a JSON Command - teeedubb - 2015-08-11

You could turn your script into a basic addon you could run that via jsonrpc with Addons.ExecuteAddon


RE: Runscript from a JSON Command - DaveBlake - 2015-08-11

Thanks guys, I may well have approached thi sin the wrong way!

Then it turns out that there is an addon in the repository that does what I wanted to do in my first silly script, and in a more flexible way.
(2015-08-11, 10:38)teeedubb Wrote: You could turn your script into a basic addon you could run that via jsonrpc with Addons.ExecuteAddon

So yes I now want to use ExecuteAddon from anywhere on the network Smile

Oh yes thanks for the how-to Teeedubb that started me out on this adventure.

Having problems with the parameters, perhaps you can advise. Binding a key to run the addon I use

Code:
Runscript(script.audio.profiles, 0)

What would the JSON equivalent be? Something like

Code:
http://192.168.1.213/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.audio.profiles","params":{"mode":0}},"id":1}

only the parameter "mode" is wrong. I don't know what the parameter is called, and my Python is too weak to read it from the script. So near yet so far!


RE: Runscript from a JSON Command - teeedubb - 2015-08-11

try
"params": [ 0 ]


RE: Runscript from a JSON Command - DaveBlake - 2015-08-11

(2015-08-11, 12:00)teeedubb Wrote: try
"params": [ 0 ]
Thanks, but with some help from the addon author, what it needs to be is "params":["0"]

These JSON parameters are so tricky! The working string is as follows

Code:
http://192.168.1.213/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.audio.profiles","params":["0"]},"id":1}

Many thanks for you support.


RE: Runscript from a JSON Command - [email protected] - 2020-11-01

(2015-08-11, 13:54)DaveBlake Wrote:
(2015-08-11, 12:00)teeedubb Wrote: try
"params": [ 0 ]
Thanks, but with some help from the addon author, what it needs to be is "params":["0"]

These JSON parameters are so tricky! The working string is as follows
Code:
http://192.168.1.213/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.audio.profiles","params":["0"]},"id":1}

Many thanks for you support.

Any idea how to enter this command in a Yatse custom command:

http://192.168.1.70:8082/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "pagedown" }, "id": 1 }

what goes in Method field and what goes in parameters field?


RE: Runscript from a JSON Command - [email protected] - 2020-11-02

(2020-11-01, 20:15)[email protected] Wrote:
(2015-08-11, 13:54)DaveBlake Wrote:
(2015-08-11, 12:00)teeedubb Wrote: try
"params": [ 0 ]
Thanks, but with some help from the addon author, what it needs to be is "params":["0"]

These JSON parameters are so tricky! The working string is as follows
Code:
http://192.168.1.213/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.audio.profiles","params":["0"]},"id":1}

Many thanks for you support.

Any idea how to enter this command in a Yatse custom command:

http://192.168.1.70:8082/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "pagedown" }, "id": 1 }

what goes in Method field and what goes in parameters field?

i get this error {"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

and i have in method Input.ExecuteAction and in the params i have

{{ "action": "pagedown" }, "id": 1}}


why is it erroring?  What is wrong?


RE: Runscript from a JSON Command - black_eagle - 2020-11-02

(2020-11-02, 16:51)[email protected] Wrote: why is it erroring?  What is wrong?

Why don't you read the response, where it tells you what is wrong, rather than spamming your question all over the board in any vaguely similar thread?

I don't use Yatse, but I don't think "id": 1 belongs in the params bit.


RE: Runscript from a JSON Command - [email protected] - 2020-11-02

(2020-11-02, 16:59)black_eagle Wrote:
(2020-11-02, 16:51)[email protected] Wrote: why is it erroring?  What is wrong?

Why don't you read the response, where it tells you what is wrong, rather than spamming your question all over the board in any vaguely similar thread?

I don't use Yatse, but I don't think "id": 1 belongs in the params bit.

Because I post and don't often get responses or the answer.  I'm not sure what you mean "ID":1 does not belong?  What then remove it altogether?  I tried 0


RE: Runscript from a JSON Command - black_eagle - 2020-11-02

(2020-11-02, 19:42)[email protected] Wrote: Because I post and don't often get responses or the answer. 

Patience!  People will answer when someone who knows the answer reads your question.  Some people wait for a week or two before getting an answer.
(2020-11-02, 19:42)[email protected] Wrote: What then remove it altogether?

Yes.  Or at least, it is not part of the parameters so I don't think it should be there.  However, as I don't use Yatse, I could be totally wrong as I don't know how it implements it's JSON calls but I would imagine it sets the id itself.