ndg63276 / alexa-sky-hd

A smart home skill for Alexa to control a Sky+HD or SkyQ box
33 stars 15 forks source link

Multiple devices control #11

Closed binc0 closed 4 years ago

binc0 commented 4 years ago

Hey there would be possible to use two Sky Q devices ?

I tried to use this code but it doesn't work well as I'm new to python:

def send_command(command): if commands[endpointid]== 'skybox-001': if command == 'sleep': time.sleep(1) return code=commands[command] commandBytes = [4,1,0,0,0,0,224 + (code/16), code % 16] b=bytearray() for i in commandBytes: b.append(i) l = 12 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((environ['HOST'], int(environ['PORT']))) recv=s.recv(64) while len(recv)<24: s.sendall(recv[0:l]) l = 1 recv=s.recv(64) s.sendall(b) commandBytes[1]=0 b=bytearray() for i in commandBytes: b.append(i) s.sendall(b) s.close() elif commands[endpointid]== 'skybox-002': if commands == 'sleep': time.sleep(1) return code=commands[command] commandBytes = [4,1,0,0,0,0,224 + (code/16), code % 16] b=bytearray() for i in commandBytes: b.append(i) l = 12 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((environ['HOST'], int(environ['PORT_2']))) recv=s.recv(64) while len(recv)<24: s.sendall(recv[0:l]) l = 1 recv=s.recv(64) s.sendall(b) commandBytes[1]=0 b=bytearray() for i in commandBytes: b.append(i) s.sendall(b) s.close()

I added the second device in appliances and it works fine alone but I'm unable to control both using the up code.

{ "applianceId": "skybox-001", "manufacturerName": "Sky", "modelName": "Digibox", "version": "1", "friendlyName": sky_box_name, "description": "Sky Digibox", "isReachable": True, "displayCategories":["TV"], "actions": [ "turnOn", "turnOff", ], "cookie": {} }, { "applianceId": "skybox-002", "manufacturerName": "Sky", "modelName": "Digibox", "version": "1", "friendlyName": sky_box_name_1, "description": "Sky Digibox", "isReachable": True, "displayCategories":["TV"], "actions": [ "turnOn", "turnOff", ], "cookie": {} },

ndg63276 commented 4 years ago

Haven't tested it or anything, but this commit might help. Obviously you need to add your skybox-002 in appliances again. It won't work for any 'scenes' eg netflix, spotify etc, as then the endpointId becomes the scene name. If you wanted them, you could add them in appliances as well, with a different applianceId, and different friendly name. Then you could edit the code to something like:

if endpointID == 'skybox-002' or endpointID == 'skyq-netflix-2':

Hope that helps, let me know if it works.

binc0 commented 4 years ago

I tried and I got this error:

channel_request: Sky Cinema Uno +24 HD /var/runtime/botocore/vendored/requests/api.py:64: DeprecationWarning: You are using the get() function from 'botocore.vendored.requests'. This dependency was removed from Botocore and will be removed from Lambda after 2020/03/31. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.get() function instead. DeprecationWarning [INFO] 2020-02-04T00:19:41.992Z 9408a0a3-a3ee-410e-b9a3-e3e6df21d459 Starting new HTTPS connection (1): raw.githubusercontent.com plus_one_request: False 8866 21 8865 22 340 92 310 100 [Errno 111] Connection refused: error Traceback (most recent call last): File "/var/task/lambda_function.py", line 196, in lambda_handler response = handle_non_discovery(request) File "/var/task/lambda_function.py", line 427, in handle_non_discovery send_command(command, endpointId) File "/var/task/lambda_function.py", line 474, in send_command s.connect((environ['HOST'], port)) File "/usr/lib64/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 111] Connection refused

ndg63276 commented 4 years ago

Have you set environment variables called PORT and PORT_2, that are different numbers? Have you mapped those ports, one to each Sky box, in your router? You can test them both at https://repl.it/@ndg63276/PortForwardingTester - click run at the top.

binc0 commented 4 years ago

Yes, I've set them and each one works.

ndg63276 commented 4 years ago

Do you get that error for both, or just for one?

ndg63276 commented 4 years ago

Found a silly typo when I tried it myself, should have given a different error, but make sure you change endpointID to endpointId on line 472.

binc0 commented 4 years ago

Do you get that error for both, or just for one?

For both.

Found a silly typo when I tried it myself, should have given a different error, but make sure you change endpointID to endpointId on line 472.

I have already fixed it and the lambda test results gives that error.

This is event test: { "directive": { "header": { "namespace": "Alexa.ChannelController", "name": "ChangeChannel", "messageId": "<message id>", "correlationToken": "<an opaque correlation token>", "payloadVersion": "3" }, "endpoint": { "scope": { "type": "BearerToken", "token": "<an OAuth2 bearer token>" }, "endpointId": "skybox-002", "cookie": {} }, "payload": { "channel": { "number": "301" }, "channelMetadata": { "name": "Sky Cinema Uno HD", "image": "<url for image>" } } } }

ndg63276 commented 4 years ago

How odd. Did it ever work with 1 device?

The message is connection refused, which suggests a problem at your end, nothing's really changed with the code, apart from the possibility of 2 devices.

binc0 commented 4 years ago

Now it works perfectly I set PORT_1 instead that PORT_2

swythan commented 4 years ago

Found a silly typo when I tried it myself, should have given a different error, but make sure you change endpointID to endpointId on line 472.

Hi Guys. Just setting this up for the first time, and got caught out by this. The zip file in the root of the repo still has this typo in it.

I was able to find the problem by looking in the logs (thanks for the Cloudwatch links in other issues!), so no worries. I thought it best to let you know, though.

Thanks for all the great work. Looking good so far!

ndg63276 commented 4 years ago

Thanks @swythan , have fixed the typo in the zip file now (hopefully!)