skyQ integration/control

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

skyQ integration/control

Post by emme »

Ciao,

I recently installed the new SkyQ decoder which looks very nice (finally!!!)
I know there are some few differences between the italian software and the EU software, but the hardware is almost the same.

The decoder looks to have a small API available that can be used to send the remote commands...

I found the script in another forum :P :P but I had to change it a bit to handle the 4digits channels

here it is:

Code: Select all

#!/usr/bin/env python
import sys
import socket
import math
import array
from time import sleep
host_ip = "192.168.0.11" #Sky Q box address
port = 49160

def sendcommand(host,command):
   code = getcode(command)
   cmd1 = int(math.floor(224 + (code/16)))
   cmd2 = int(code % 16)
   command1 = array.array('B', [4, 1, 0, 0, 0, 0, cmd1, cmd2]).tostring()
   command2 = array.array('B', [4, 0, 0, 0, 0, 0, cmd1, cmd2]).tostring()

   s = socket.socket()
   s.connect((host,port))  #connect to SkyQ box
   reply = s.recv(12)      #receive handshake
   s.send(reply)           #send handshake
   reply = s.recv(2)       #receive 2 bytes
   s.send(reply[0])        #send 1 byte
   reply = s.recv(4)       #receive 4 bytes
   s.send(reply[0])        #send 1 byte
   reply = s.recv(24)      #receive 24 bytes

   s.send(command1)        #send command bytes part 1
   s.send(command2)        #send command bytes part 2

   s.close()               #close connection

def getcode(cmdname):
   commands = {
      "power": 0,
      "select": 1,
      "backup": 2,
      "dismiss": 2,
      "channelup": 6,
      "channeldown": 7,
      "interactive": 8,
      "sidebar": 8,
      "help": 9,
      "services": 10,
      "search": 10,
      "tvguide": 11,
      "home": 11,
      "i": 14,
      "text": 15,
      "up": 16,
      "down": 17,
      "left": 18,
      "right": 19,
      "red": 32,
      "green": 33,
      "yellow": 34,
      "blue": 35,
      "0": 48,
      "1": 49,
      "2": 50,
      "3": 51,
      "4": 52,
      "5": 53,
      "6": 54,
      "7": 55,
      "8": 56,
      "9": 57,
      "play": 64,
      "pause": 65,
      "stop": 66,
      "record": 67,
      "fastforward": 69,
      "rewind": 71,
      "boxoffice": 240,
      "sky": 241
   }
   return commands[cmdname]

def getchannelno( channel ):
  chno = {
    'sky_news': 100,
    'sky_discovery': 401,
    'sky_fox_animation': 127
  }
  return chno[channel]

if len(sys.argv) == 1:
  print "no parameters"
  sys.exit(2)

if sys.argv[1] == "channel":
  if len(sys.argv) < 3:
    print 'USAGE:',sys.argv[0],'[<command>|channel <channel name>]'
    sys.exit(2)

  chno = getchannelno(sys.argv[2])

  for x in range(0,len(str(chno))):
    sendcommand(host_ip,str(chno[x]))
    sleep(0.2)

elif sys.argv[1] == "chno":
  chno = sys.argv[2]

  for x in range(0,len(chno)):
    sendcommand(host_ip,str(chno[x]))
    sleep(0.2)
else:
  sendcommand(host_ip,sys.argv[1])
save it where you prefer with extension .py then make it executable (sudo chmod +x <filename> ) and then in domoticz you can create a selector switch for each action you can call the script with parameters:

./skyQ.py command <remote command>
./skyQ.py chno <channel number>
./skyQ.py channel <channel name> (this must be configured into the def getchannelno( channel ) )

Hope you enjoy it
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest