Logic Machine Forum
Control KODI - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Control KODI (/showthread.php?tid=743)



Control KODI - Superchango - 18.04.2017

Good afternoon,

Has anyone tried to control KODI through homelynk?
I would like to know if it is possible and how it can be done in such a case.


Thank you so much,



RE: Control KODI - gjniewenhuijse - 19.04.2017

(18.04.2017, 15:32)Superchango Wrote: Good afternoon,

Has anyone tried to control KODI through homelynk?
I would like to know if it is possible and how it can be done in such a case.


Thank you so much,

Hello, yes i use it but my code is very basic and needs some beautification Sad

the library
Code:
function kodiHandler(iServer,iPort,sendPort)
 -- first call
 if not ready then
   require('socket')
   
   lastdatareceived = nil
   ready = true
 end
 
 -- client connected
 if connected then
   while true do
     char, err = client:receive(1)
     -- error while receiving, closed socket
     if err == 'closed' then
         connected = false
       sleep(1)
       break
     end
       
     if char ~= nil then
       lastdatareceived = os.time()
       warningclosed = true
       warningfailed = true
       warningerrors = true
       warningtimeou = true
       
                table.insert(buffer, char)
       tmpbuf = table.concat(buffer)
       if ( json.pdecode(tmpbuf) ) then
         data = tmpbuf
         parse(data)
         buffer = {}
       end
     else
       now = os.time()
       deltatime = now - lastdatareceived
     end
       
     -- receive incoming send requests
         msg, ip, port = sendServer:receivefrom()
            if msg then
       -- send command
       --log("send: "..msg)
       client:send(msg)
            end
     
     --[[ clear not complete buffer
     if deltatime > 10 and #buffer > 0 then
       log( #buffer )
       buffer = {}
       lastdatareceived = os.time()
     end
     -]]
   end
   
   -- first call or previously disconnected
 else
   -- close previous connection when disconnected
   if client then
     client:close()
     client = nil
   end
   if sendServer then
     sendServer:close()
     sendServer = nil
   end
   
   -- create tcp client
   client = socket.tcp()
   client:settimeout(5)
   connected, err = client:connect(iServer, iPort)
   
   -- connect ok, reset buffer
   if connected then
     lastdatareceived = os.time()
     warningclosed = true
     warningfailed = true
     warningerrors = true
     warningtimeou = true
     --log('[KODI-client] connection ok: '..iServer)
     buffer = {}
     
     -- create udp server to receive incoming send requests
            if not sendServer then
              sendServer = socket.udp()
              sendServer:setsockname('*', sendPort)
              sendServer:settimeout(0.1)
            end
     
     sleep(5)
     
     -- send initial command
     --client:send( '{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1}' )
     
   
     -- error while connecting,
   else
            --log(err)
     if warningfailed then log('[KODI-client] connection failed (conn): '.. err) end
     warningfailed = false
     sleep(5)
   end
 end
 
 -- incoming command parser
 function parse(data)
   -- log other info, not mapped, if useful
   --log("data received: "..data)
   --log(json.pdecode(data))
 end
end

the resident script
Code:
require('user.nit_kodi')
require('json')

kodiHandler("192.168.x.x","9090","18007")

-- callback from handler
-- tv recording play
function tvrecPlay()
 log("test1")
end
-- tv recording - pause or stop
function tvrecStop()
  log("test2")
end
in another script u can use for example:
Code:
udpsend( '{ "jsonrpc": "2.0", "id": 1, "method": "Application.SetVolume", "params": { "volume": 50 } }', "18007" )



RE: Control KODI - Superchango - 19.04.2017

Thanks I will put with it to see if I am able to perform a control of my HTPC with KODI


RE: Control KODI - baggins - 19.04.2017

Hi,

My "solution" is even more basic.

I installed an USB IR Flirc receiver on my Kodi box and programmed it with a Samsung remote control. I then use a Global Caché IR transmitter that is controlled through simple TCP commands.

In my visualisation I have programmed a "universal" remote control with which I can control my cable decoder, AVR, Kodi and TV.


RE: Control KODI - leonidas - 19.04.2017

One more simple KODI control solution:


Code:
require('socket.http')
socket.http.TIMEOUT = 5

-- play ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "play" }, "id": 1 }')

-- pause --------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "pause" }, "id": 1 }, "id": 1 }')

-- down ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Down", "id": 1}')

-- up -----------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Up", "id": 1}')

-- right --------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Right", "id": 1}')

-- left ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Left", "id": 1}')

-- home ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Home", "id": 1}')

-- select -------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Select", "id": 1}')



RE: Control KODI - gjniewenhuijse - 19.04.2017

(19.04.2017, 14:23)leonidas Wrote: One more simple KODI control solution:


Code:
require('socket.http')
socket.http.TIMEOUT = 5

-- play ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "play" }, "id": 1 }')

-- pause --------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "pause" }, "id": 1 }, "id": 1 }')

-- down ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Down", "id": 1}')

-- up -----------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Up", "id": 1}')

-- right --------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Right", "id": 1}')

-- left ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Left", "id": 1}')

-- home ---------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Home", "id": 1}')

-- select -------------------------------------------------------------------------------------------
data1 = socket.http.request('http://192.168.1.79:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Input.Select", "id": 1}')

With this solution you have no incoming data, so you can't turn off your lights when a movie starts for example.


RE: Control KODI - leonidas - 20.04.2017

(19.04.2017, 14:28)gjniewenhuijse Wrote: With this solution you have no incoming data, so you can't turn off your lights when a movie starts for example.

Yes, but it's better than using Global Cache.


RE: Control KODI - gjniewenhuijse - 20.04.2017

(20.04.2017, 07:25)leonidas Wrote: Yes, but it's better than using Global Cache.

yes, you're right.


RE: Control KODI - Bart - 11.09.2017

(19.04.2017, 12:04)baggins Wrote: Hi,

My "solution" is even more basic.

I installed an USB IR Flirc receiver on my Kodi box and programmed it with a Samsung remote control. I then use a Global Caché IR transmitter that is controlled through simple TCP commands.

In my visualisation I have programmed a "universal" remote control with which I can control my cable decoder, AVR, Kodi and TV.

Hi Baggins,

Since I see the "Telenet" symbol on your visualisation I assume we live in the same country. 
To avoid re-inventing hot water, here Could you share some tcp commands you use to control your cable decoder + give some insight on how you built the visualisation shown in the screenshot of your post?

kr,

B.


RE: Control KODI - baggins - 13.09.2017

(11.09.2017, 21:02)Bart Wrote:
(19.04.2017, 12:04)baggins Wrote: Hi,

My "solution" is even more basic.

I installed an USB IR Flirc receiver on my Kodi box and programmed it with a Samsung remote control. I then use a Global Caché IR transmitter that is controlled through simple TCP commands.

In my visualisation I have programmed a "universal" remote control with which I can control my cable decoder, AVR, Kodi and TV.

Hi Baggins,

Since I see the "Telenet" symbol on your visualisation I assume we live in the same country. 
To avoid re-inventing hot water, here Could you share some tcp commands you use to control your cable decoder + give some insight on how you built the visualisation shown in the screenshot of your post?

kr,

B.

Hi,

As I've stated, I use a Global Caché (it actually is the Basalte version) transmitter attached to the Telenet Digicorder.
Here is the script I use to control the Digicorder:

Code:
--[[
   Command: Command for execution by controller of Global Cache. To transmit IR command Command=sendir. See full list in GLobal Cache manual.
   Modul: The module containing the appropriate IR port (e.g. for iTach=1
   NumDev: Number of port in the module starting with 1.
   Id: Id number of the command in range 0 – 65535
   Freq: IR channel frequency in Hz, from 20000 – 500000
   Repeat: on 0 – repeat the command up to 65535 times or while the command transmit is terminated
   Offset: Time period to repeat the telegram in the next transmissions (Repeat<>1), 1 – 255
   P0,…,Pn: String sequence defining impulse sequence in IR telegram
   ^: Symbol defining the end of command string, OD (Hex)

--]]


local socket = require("socket")

function send_Digicorder(command)
 log('send_Digicorder called; command ' .. command)
tcp = assert(socket.tcp())
tcp:settimeout(0.5)

 Device = '192.168.0.26'                                                      
 Header =  "sendir,1:2,1,38000,1,1,"
                                           
 connected, err = tcp:connect(Device, '4998')                                                    
--print (connected)
--print (err)
Digicorder = {}

Digicorder["BACK"] =             "11,12,12,24,12,12,23,24,12,12,23,24,23,25,11,12,23,12,12,12,11,13,11,24,23,3362\r"
Digicorder["CHANNEL DOWN"] =     "11,12,11,25,11,13,23,25,11,13,23,25,22,25,11,13,23,25,23,12,11,25,23,3359\r"
Digicorder["CHANNEL UP"] =       "11,12,11,25,11,13,22,25,11,13,23,25,23,25,11,13,22,25,23,25,23,25,11,3348\r"
Digicorder["CLEAR"] =            "11,13,11,25,11,13,23,25,11,13,23,25,23,25,11,13,23,13,11,13,11,25,11,13,23,3364\r"
Digicorder["COMMUNICATION"] =    "12,12,11,25,11,13,22,25,11,12,23,25,23,24,12,13,11,12,23,13,11,12,12,24,23,3362\r"
Digicorder["CURSOR DOWN"] =      "11,13,11,25,11,12,23,25,12,12,23,25,23,25,11,13,23,13,11,24,23,25,23,3360\r"
Digicorder["CURSOR ENTER"] =     "11,12,11,25,11,13,22,25,11,13,23,25,23,25,11,13,22,13,11,25,23,13,11,25,11,3348\r"
Digicorder["CURSOR LEFT"] =      "11,13,11,25,11,12,23,25,11,12,23,25,23,25,11,13,23,13,11,25,11,12,11,13,23,3360\r"                                                        
Digicorder["CURSOR RIGHT"] =     "11,13,11,25,11,12,23,25,11,12,23,25,23,25,11,13,23,13,11,25,11,12,23,25,11,3351\r"
Digicorder["CURSOR UP"] =        "11,13,11,25,11,13,23,25,11,13,23,24,23,25,11,12,23,25,22,13,11,13,11,25,11,3349\r"
Digicorder["DIGIT 0"] =          "11,13,11,25,11,12,23,25,11,12,23,25,23,25,11,13,11,12,23,25,23,25,23,3365\r"
Digicorder["DIGIT 1"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,11,12,12,13,11,13,11,12,23,25,11,3347\r"
Digicorder["DIGIT 2"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,11,12,11,13,11,13,23,25,23,3360\r"
Digicorder["DIGIT 3"] =          "11,13,11,25,11,13,23,25,11,13,22,25,23,25,11,13,11,13,11,13,11,13,22,13,11,25,11,3348\r"
Digicorder["DIGIT 4"] =          "11,13,11,25,11,13,23,25,11,13,22,25,23,25,11,13,11,13,11,12,23,25,11,12,23,3360\r"
Digicorder["DIGIT 5"] =          "11,12,11,25,11,13,22,25,11,12,23,25,23,24,11,13,11,13,11,12,23,24,23,25,11,3327\r"
Digicorder["DIGIT 6"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,11,13,11,12,23,12,11,25,23,3362\r"
Digicorder["DIGIT 7"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,11,13,11,12,23,12,11,13,11,25,11,3353\r"
Digicorder["DIGIT 8"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,11,13,23,25,11,13,11,12,23,3359\r"
Digicorder["DIGIT 9"] =          "11,12,11,25,11,13,23,25,11,13,23,25,23,24,11,13,11,13,23,25,11,13,23,25,11,3345\r"
Digicorder["ENTER"] =            "11,25,11,13,23,25,11,13,11,13,22,25,22,25,11,13,23,25,11,13,22,25,23,3363\r"
Digicorder["EXIT"] =             "11,12,11,25,11,13,23,25,11,13,23,25,23,25,11,13,23,12,11,13,11,25,23,25,11,3350\r"
Digicorder["EXTRA"] =            "12,13,11,25,11,12,23,25,11,12,23,25,22,25,11,13,11,12,23,12,12,12,11,13,11,24,12,3351\r"
Digicorder["FORWARD"] =          "11,13,11,25,11,13,23,25,11,13,23,25,23,25,23,25,11,13,11,13,11,13,11,13,23,3360\r"
Digicorder["FUNCTION BLUE"] =    "11,12,12,24,12,12,23,24,12,13,23,24,23,24,23,25,23,24,11,13,23,24,11,3351\r"
Digicorder["FUNCTION GREEN"] =   "12,12,11,25,11,12,23,25,11,12,23,25,23,25,23,24,12,12,23,12,11,13,11,25,11,3350\r"
Digicorder["FUNCTION RED"] =     "11,13,11,24,12,12,23,24,12,12,23,24,23,25,23,24,12,13,23,12,11,25,23,3358\r"
Digicorder["FUNCTION YELLOW"] =  "12,12,12,25,11,13,22,25,11,13,22,25,23,24,23,25,22,25,11,12,12,12,23,3364\r"
Digicorder["GUIDE"] =            "11,13,11,25,11,12,23,25,11,12,23,25,23,25,11,13,11,13,23,12,11,25,23,24,12,3356\r"
Digicorder["HELP"] =             "11,13,11,24,12,12,23,24,12,12,23,24,23,25,11,12,23,25,11,12,23,25,23,3359\r"
Digicorder["MENU MAIN"] =        "11,12,12,25,11,13,22,25,11,13,23,25,23,25,11,12,23,25,12,12,11,13,11,13,23,3362\r"
Digicorder["MUTE TOGGLE"] =      "11,13,11,25,11,12,23,25,11,12,23,25,22,25,11,13,23,25,11,13,11,13,23,25,11,3347\r"
Digicorder["PAUSE"] =            "11,13,11,25,11,12,23,25,11,12,23,25,23,25,23,25,11,13,11,13,11,13,23,24,12,3345\r"
Digicorder["PLAY"] =             "11,13,11,25,11,12,23,25,11,12,23,25,23,25,23,25,11,13,23,25,11,13,23,3363\r"
Digicorder["POWER TOGGLE"] =     "11,12,12,24,12,12,23,24,12,12,23,24,23,24,12,12,12,12,23,24,23,12,12,24,12,3349\r"
Digicorder["PREVIOUS CHANNEL"] = "11,13,11,25,11,12,23,25,11,12,23,25,23,25,11,13,23,13,11,12,11,13,11,25,22,3361\r"
Digicorder["RECORD"] =           "11,13,11,24,12,13,23,24,11,13,23,24,23,25,23,25,11,13,11,12,23,25,23,3363\r"
Digicorder["REVERSE"] =          "11,13,11,25,11,13,23,25,11,13,23,25,22,25,11,13,23,13,11,13,12,12,11,13,11,25,11,3352\r"
Digicorder["STOP"]   =           "11,12,11,24,11,12,23,24,11,12,23,24,22,25,22,24,11,12,11,12,22,12,11,24,12,3297\r"
Digicorder["TELETEXT"] =         "11,12,12,24,12,12,23,24,12,12,23,24,23,24,23,25,11,12,23,25,23,24,11,3346\r"
Digicorder["VOLUME DOWN"] =      "11,13,11,24,12,13,23,24,11,13,23,24,23,25,11,12,23,25,23,25,11,13,22,3362\r"
Digicorder["VOLUME UP"] =        "11,13,12,24,11,13,23,24,11,13,23,25,23,25,11,12,23,25,11,12,23,12,11,25,11,3345\r"                                                            

                                                       

   if command == 'OK' then
     command = 'CURSOR ENTER'
   end
    result = tcp:send(Header .. Digicorder[command])  
    --log('Result: ' .. result)
    rec = tcp:receive()
    --log(rec)
    tcp:close()  

                                                                                               
                                                     
end


As far as the visualisation is concerned: Inkscape and GIMP are your friends...


RE: Control KODI - Kellystewart - 02.10.2018

You can go one step further with Kodi web interface and stream content to your computer from your Kodi system.