v18 Leia Play/pause toggle example?
#16
How to get iRule working with Kodi v18.1 (Leia)

There are two good methods of solving @houser's problem:
  1. "open" solution using Lua code (IoT devices; e.g. Vera, SmartThings, etc.)
  2. iRule only solution

Option 1: How to Trigger Kodi API from a Vera Device

If you have a Vera or similar device, you can do it via curl (as mentioned above).

iRule is beautiful, but excruciatingly frustrating to configure. It has to be horribly programmed behind the scenes, IMHO. It was certainly not well managed from a software dev perspective.

I won't go into details, but in a nutshell, if you have a Vera, create a Device in iRule to support Vera scenes. Create an HTTP gateway pointed to your Vera box. Create a scene in Vera with no devices and use the code below to call the appropriate command.

Note: Vera will require you assign either a device or a notification to the scene. Just assign some dummy device or notify yourself (useful for testing). 

During the Vera scene creation, there is a section called "Also, execute the following Luup code:" in step 3. Left click that to open the code editing screen. Enter this code and press Save.

Lua:
os.execute('curl -X POST -H "content-type:application/json" http://192.168.1.2:8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Input.Up"}\'')

Obviously, you will need to customize the JSON API commands and IP address to suit your needs. The example above will move the UI cursor up. When you execute the scene, the action will fire.


Option 2: Trigger Kodi API with iRule Custom Device URL

The key to getting it to work in iRule are the following details:
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP
  2. Create a Device handler in iRule Builder
  3. Add a new Device Code to the Kodi device
  4. Enter your URL in this format: 
json:
jsonrpc?request={"jsonrpc":"2.0","method":"Input.Up", "id":1}

If you have any existing HTTP gateways for Kodi, you may need to remove them to get it all to work properly
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply
#17
(2019-04-11, 21:52)HTGeek Wrote: How to get iRule working with Kodi v18.1 (Leia)

There are two good methods of solving @houser's problem:
  1. "open" solution using Lua code (IoT devices; e.g. Vera, SmartThings, etc.)
  2. iRule only solution
Option 1: How to Trigger Kodi API from a Vera Device

If you have a Vera or similar device, you can do it via curl (as mentioned above).

iRule is beautiful, but excruciatingly frustrating to configure. It has to be horribly programmed behind the scenes, IMHO. It was certainly not well managed from a software dev perspective.

I won't go into details, but in a nutshell, if you have a Vera, create a Device in iRule to support Vera scenes. Create an HTTP gateway pointed to your Vera box. Create a scene in Vera with no devices and use the code below to call the appropriate command.

Note: Vera will require you assign either a device or a notification to the scene. Just assign some dummy device or notify yourself (useful for testing). 

During the Vera scene creation, there is a section called "Also, execute the following Luup code:" in step 3. Left click that to open the code editing screen. Enter this code and press Save.

Lua:
os.execute('curl -X POST -H "content-type:application/json" http://192.168.1.2:8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Input.Up"}\'')

Obviously, you will need to customize the JSON API commands and IP address to suit your needs. The example above will move the UI cursor up. When you execute the scene, the action will fire.


Option 2: Trigger Kodi API with iRule Custom Device URL

The key to getting it to work in iRule are the following details:
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP
  2. Create a Device handler in iRule Builder
  3. Add a new Device Code to the Kodi device
  4. Enter your URL in this format: 
json:
jsonrpc?request={"jsonrpc":"2.0","method":"Input.Up", "id":1}

If you have any existing HTTP gateways for Kodi, you may need to remove them to get it all to work properly 

Thanks so much for this! Thought I might have to resign myself between using Yatse for Kodi control and switching to Irule to control my displays and amps etc.
Reply
#18
Just returning to mention for others looking for a solution for this, that it started working after some excellent advice from here:
https://getsatisfaction.com/irule/topics...n-delivery
The trick with iRule for at least me was to drop the encoding and use a network gateway rather than http.
Along with some cleverly doctored fixes in that thread it works great. FWIW, YMMV
Good luck.
Reply
#19
(2019-04-27, 17:01)houser Wrote: Just returning to mention for others looking for a solution for this, that it started working after some excellent advice from here:
https://getsatisfaction.com/irule/topics...n-delivery
The trick with iRule for at least me was to drop the encoding and use a network gateway rather than http.
Along with some cleverly doctored fixes in that thread it works great. FWIW, YMMV
Good luck.
What do you mean by "drop the encoding"?  I have my gateway reconnected to Kodi via Network Gateway and I get a green sync in the app so I believe that part is working... my formatting on the command just must be off but I can't figure it out.

Thanks.
Reply
#20
(2019-11-27, 06:24)JohnLew Wrote:
(2019-04-27, 17:01)houser Wrote: Just returning to mention for others looking for a solution for this, that it started working after some excellent advice from here:
https://getsatisfaction.com/irule/topics...n-delivery
The trick with iRule for at least me was to drop the encoding and use a network gateway rather than http.
Along with some cleverly doctored fixes in that thread it works great. FWIW, YMMV
Good luck.
What do you mean by "drop the encoding"?  I have my gateway reconnected to Kodi via Network Gateway and I get a green sync in the app so I believe that part is working... my formatting on the command just must be off but I can't figure it out.

Thanks. 
Hi John,

I meant URL encoded or not. Example below of the same command encoded and not that works here FWIW:

Play/pause toggle Kodi 18.xx non encoded:
jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1},"id":1}

Play/pause toggle Kodi 17.xx encoded:
jsonrpc?request=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Player.PlayPause%22%2C%22params%22%3A%7B%22playerid%22%3A1%7D%2C%22id%22%3A1%7D
Reply
#21
Terribly belated reply to this thread after a long hiatus from this forum (terrible, I know; but life threw me a curve ball the last 6+ months).... anyhoo.... perhaps this info will be useful to someone some day....

Tested from a Linux box on my LAN (using BaSH command line), and they worked perfectly. Make sure you use whatever port # you assigned to Kodi's Web interface (default = 8080):

Shutdown Kodi:
Bash:
curl -X POST -H "content-type:application/json" http://xxx.xxx.xxx.xxx:8080/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"System.shutdown"}'

Open/Close DVD drawer:
Bash:
curl -X POST -H "content-type:application/json" http://xxx.xxx.xxx.xxx:8080/jsonrpc -d '{"jsonrpc":"2.0","id":1,"method":"System.EjectOpticalDrive"}'
Headless Linux Kodi box [Ubuntu 16.04.6 LTS Server] | Dedicated Media Server [Ubuntu 16.04.6 LTS Server]
Reply
#22
I have this same issue and was directed to this thread - but I had someone set up my iRule and know how to do basics like syncing the app and tweaking the layout.  Are there directions out there on how to execute those three steps?
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP - I'm guessing in the iRule app on the tablet functioning as a remote.
  2. Create a Device handler in iRule Builder - I think this means adding a device, but iRule Builder has a pulldown list for this function.
  3. Add a new Device Code to the Kodi device - not sure what this  means.
  4. Enter your URL in this format - I think this means replacing the existing button commands with commands for the added device, using the simpler URLs instead of the current?
Thanks in advance for any assistance.
Win10 64-bit
Kodi 20.1 / Mimic-LR
Reply
#23
(2021-04-27, 00:25)dshorrosh Wrote: I have this same issue and was directed to this thread - but I had someone set up my iRule and know how to do basics like syncing the app and tweaking the layout.  Are there directions out there on how to execute those three steps?
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP - I'm guessing in the iRule app on the tablet functioning as a remote.
  2. Create a Device handler in iRule Builder - I think this means adding a device, but iRule Builder has a pulldown list for this function.
  3. Add a new Device Code to the Kodi device - not sure what this  means.
  4. Enter your URL in this format - I think this means replacing the existing button commands with commands for the added device, using the simpler URLs instead of the current?
Thanks in advance for any assistance.

Hi @dshorrosh 
If you are building a Kodi remote from scratch, there are devices with complete command sets in the builder.
Go to "browse devices" in the device menu and download an appropriate set for your kodi version.
The iRule servers are shutting down end of this year so maybe factor that into your project also.
Good luck
Reply
#24
(2021-04-27, 05:48)houser Wrote:
(2021-04-27, 00:25)dshorrosh Wrote: I have this same issue and was directed to this thread - but I had someone set up my iRule and know how to do basics like syncing the app and tweaking the layout.  Are there directions out there on how to execute those three steps?
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP - I'm guessing in the iRule app on the tablet functioning as a remote.
  2. Create a Device handler in iRule Builder - I think this means adding a device, but iRule Builder has a pulldown list for this function.
  3. Add a new Device Code to the Kodi device - not sure what this  means.
  4. Enter your URL in this format - I think this means replacing the existing button commands with commands for the added device, using the simpler URLs instead of the current?
Thanks in advance for any assistance.

Hi @dshorrosh 
If you are building a Kodi remote from scratch, there are devices with complete command sets in the builder.
Go to "browse devices" in the device menu and download an appropriate set for your kodi version.
The iRule servers are shutting down end of this year so maybe factor that into your project also.
Good luck
Thanks for the reply.  I have a pretty good remote that controls my receiver, blu-ray, TV and Kodi (or at least it controlled Kodi until Leia) - so I'll be changing the gateway, figuring out which device to add, and swap the existing button commands from the old Kodi / XBMC to one that works.

And yep I know iRule is a dead platform so trying to get it solid before the servers shut down, defer the complete do-over as long as possible.
Win10 64-bit
Kodi 20.1 / Mimic-LR
Reply
#25
(2021-04-27, 06:02)dshorrosh Wrote:
(2021-04-27, 05:48)houser Wrote:
(2021-04-27, 00:25)dshorrosh Wrote: I have this same issue and was directed to this thread - but I had someone set up my iRule and know how to do basics like syncing the app and tweaking the layout.  Are there directions out there on how to execute those three steps?
  1. Gateway configured as a NETWORK gateway with your Web Socket port as the port number (default: 9090); set protocol to TCP - I'm guessing in the iRule app on the tablet functioning as a remote.
  2. Create a Device handler in iRule Builder - I think this means adding a device, but iRule Builder has a pulldown list for this function.
  3. Add a new Device Code to the Kodi device - not sure what this  means.
  4. Enter your URL in this format - I think this means replacing the existing button commands with commands for the added device, using the simpler URLs instead of the current?
Thanks in advance for any assistance.

Hi @dshorrosh 
If you are building a Kodi remote from scratch, there are devices with complete command sets in the builder.
Go to "browse devices" in the device menu and download an appropriate set for your kodi version.
The iRule servers are shutting down end of this year so maybe factor that into your project also.
Good luck
Thanks for the reply.  I have a pretty good remote that controls my receiver, blu-ray, TV and Kodi (or at least it controlled Kodi until Leia) - so I'll be changing the gateway, figuring out which device to add, and swap the existing button commands from the old Kodi / XBMC to one that works.

And yep I know iRule is a dead platform so trying to get it solid before the servers shut down, defer the complete do-over as long as possible.
I hear you. Have done the same, for the same reasons. Migrating to Kramer Control as I go.
FWIW. If you are on Leia, you are also good to go for Matrix with the same commands.
The port I am using for my gateway is 9090. Important: The gateway as of Leia-Matrix needs to be a gateway port and not http.
Here is a working example string for play/pause as initially asked:
​​​
jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1},"id":1}
Good luck again Wink

edit:
Before I forget, there is a nasty little bug in iRule that changes the gateway port on the handset to something other than 9090
like 9999 if you change other settings so be aware of that maybe.
Reply
#26
(2021-04-27, 06:12)houser Wrote:
(2021-04-27, 06:02)dshorrosh Wrote:
(2021-04-27, 05:48)houser Wrote: Hi @dshorrosh 
If you are building a Kodi remote from scratch, there are devices with complete command sets in the builder.
Go to "browse devices" in the device menu and download an appropriate set for your kodi version.
The iRule servers are shutting down end of this year so maybe factor that into your project also.
Good luck
Thanks for the reply.  I have a pretty good remote that controls my receiver, blu-ray, TV and Kodi (or at least it controlled Kodi until Leia) - so I'll be changing the gateway, figuring out which device to add, and swap the existing button commands from the old Kodi / XBMC to one that works.

And yep I know iRule is a dead platform so trying to get it solid before the servers shut down, defer the complete do-over as long as possible.
I hear you. Have done the same, for the same reasons. Migrating to Kramer Control as I go.
FWIW. If you are on Leia, you are also good to go for Matrix with the same commands.
The port I am using for my gateway is 9090. Important: The gateway as of Leia-Matrix needs to be a gateway port and not http.
Here is a working example string for play/pause as initially asked:
​​​
jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1},"id":1}
Good luck again Wink

edit:
Before I forget, there is a nasty little bug in iRule that changes the gateway port on the handset to something other than 9090
like 9999 if you change other settings so be aware of that maybe.
Thanks for the earlier reply Houser.  I found the Kodi - Leia device in iRule, copied the existing panel and changed the button commands to reference that device using the updated JSON syntax.  I synced the iRule app, and the additional device appeared.  I created a new Network Gateway with the following config:
  • Name = Kodi
  • IPv4 = Address assigned to the Windows PC running Kodi
  • Port = 9090
  • TCP

I assigned the new Kodi Leia device to the new gateway, and nuthin.  FWIW the original XBMC device is still present in the iRule config and assigned to the HTTP gateway with the same IP address, port 80.

Am I missing something?  Any assistance would be appreciated.
Win10 64-bit
Kodi 20.1 / Mimic-LR
Reply
#27
Hi @dshorrosh 

You want network gateway for leia/matrix and onwards. Not http.
be sure to check that the gateway is at 9090 as it may reset to 9999 as mentioned.
best
Reply
#28
(2021-05-02, 20:19)dshorrosh Wrote:
(2021-04-27, 06:12)houser Wrote:
(2021-04-27, 06:02)dshorrosh Wrote: Thanks for the reply.  I have a pretty good remote that controls my receiver, blu-ray, TV and Kodi (or at least it controlled Kodi until Leia) - so I'll be changing the gateway, figuring out which device to add, and swap the existing button commands from the old Kodi / XBMC to one that works.

And yep I know iRule is a dead platform so trying to get it solid before the servers shut down, defer the complete do-over as long as possible.
I hear you. Have done the same, for the same reasons. Migrating to Kramer Control as I go.
FWIW. If you are on Leia, you are also good to go for Matrix with the same commands.
The port I am using for my gateway is 9090. Important: The gateway as of Leia-Matrix needs to be a gateway port and not http.
Here is a working example string for play/pause as initially asked:
​​​
jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1},"id":1}
Good luck again Wink

edit:
Before I forget, there is a nasty little bug in iRule that changes the gateway port on the handset to something other than 9090
like 9999 if you change other settings so be aware of that maybe.
Thanks for the earlier reply Houser.  I found the Kodi - Leia device in iRule, copied the existing panel and changed the button commands to reference that device using the updated JSON syntax.  I synced the iRule app, and the additional device appeared.  I created a new Network Gateway with the following config:
  • Name = Kodi
  • IPv4 = Address assigned to the Windows PC running Kodi
  • Port = 9090
  • TCP

I assigned the new Kodi Leia device to the new gateway, and nuthin.  FWIW the original XBMC device is still present in the iRule config and assigned to the HTTP gateway with the same IP address, port 80.

Am I missing something?  Any assistance would be appreciated.
DOH!  Nevermind, I fat-fingered the IP address - it's working!  No I just need to tweak my JSON strings for a few buttons that I need to open specific windows.
Win10 64-bit
Kodi 20.1 / Mimic-LR
Reply
#29
(2021-05-02, 20:38)dshorrosh Wrote:
(2021-05-02, 20:19)dshorrosh Wrote:
(2021-04-27, 06:12)houser Wrote: I hear you. Have done the same, for the same reasons. Migrating to Kramer Control as I go.
FWIW. If you are on Leia, you are also good to go for Matrix with the same commands.
The port I am using for my gateway is 9090. Important: The gateway as of Leia-Matrix needs to be a gateway port and not http.
Here is a working example string for play/pause as initially asked:
​​​
jsonrpc?request={"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1},"id":1}
Good luck again Wink

edit:
Before I forget, there is a nasty little bug in iRule that changes the gateway port on the handset to something other than 9090
like 9999 if you change other settings so be aware of that maybe.
Thanks for the earlier reply Houser.  I found the Kodi - Leia device in iRule, copied the existing panel and changed the button commands to reference that device using the updated JSON syntax.  I synced the iRule app, and the additional device appeared.  I created a new Network Gateway with the following config:
  • Name = Kodi
  • IPv4 = Address assigned to the Windows PC running Kodi
  • Port = 9090
  • TCP

I assigned the new Kodi Leia device to the new gateway, and nuthin.  FWIW the original XBMC device is still present in the iRule config and assigned to the HTTP gateway with the same IP address, port 80.

Am I missing something?  Any assistance would be appreciated.
DOH!  Nevermind, I fat-fingered the IP address - it's working!  No I just need to tweak my JSON strings for a few buttons that I need to open specific windows.

Well done Wink
Reply
#30
(2021-05-02, 20:40)houser Wrote:
(2021-05-02, 20:38)dshorrosh Wrote:
(2021-05-02, 20:19)dshorrosh Wrote: Thanks for the earlier reply Houser.  I found the Kodi - Leia device in iRule, copied the existing panel and changed the button commands to reference that device using the updated JSON syntax.  I synced the iRule app, and the additional device appeared.  I created a new Network Gateway with the following config:
  • Name = Kodi
  • IPv4 = Address assigned to the Windows PC running Kodi
  • Port = 9090
  • TCP

I assigned the new Kodi Leia device to the new gateway, and nuthin.  FWIW the original XBMC device is still present in the iRule config and assigned to the HTTP gateway with the same IP address, port 80.

Am I missing something?  Any assistance would be appreciated.
DOH!  Nevermind, I fat-fingered the IP address - it's working!  No I just need to tweak my JSON strings for a few buttons that I need to open specific windows.

Well done Wink
Thanks - trial and error and a little slow to connect the dots between JSON, built-in functions , Action IDs and Window IDs.  The only thing I'm still struggling with it how to enter a path to the contents of a specific Windows folder in a couple of the JSON commands.  Specifically: Computer/Concerts(LSmile/Concerts - which would then display the concert videos in that folder.

Here's the string that doesn't work - jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ActivateWindow","params":{"window":"library://concerts/concerts/,return"},"id":"1"}}

I've pulled out a lot of hair over the past week, so a quick tip would be very useful.
Win10 64-bit
Kodi 20.1 / Mimic-LR
Reply

Logout Mark Read Team Forum Stats Members Help
Leia Play/pause toggle example?0