Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
Solved Runscript from a JSON Command
#1
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?
Reply
#2
something like this?
Reply
#3
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.....
Reply
#4
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.
Reply
#5
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?
Reply
#6
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
Reply
#7
You could turn your script into a basic addon you could run that via jsonrpc with Addons.ExecuteAddon
Reply
#8
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!
Reply
#9
try
"params": [ 0 ]
Reply
#10
(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.
Reply
#11
(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?
Reply
#12
(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?
Reply
#13
(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.
Learning Linux the hard way !!
Reply
#14
(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
Reply
#15
(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.
Learning Linux the hard way !!
Reply

Logout Mark Read Team Forum Stats Members Help
Runscript from a JSON Command0