Sky Q set-top box custom media_player component

I’ve decided to remove this - basically, the interfaces this component used to talk to the box are far too brittle, and pretty much every time the box’s firmware updated something broke in new and strange ways. This is obviously not ideal, as it means the script needs constant updates/maintenance.

I’d hoped to build this into a stable component to integrate upstream, however it looks like we will have to wait and see if an official, documented API or developer integration point for the box is ever released (which is not impossible, but I wouldn’t hold your breath). Sorry!

6 Likes

Nice work! Just wish I wasn’t still on the old Sky+ STB :wink:

I’d rather have the £12/month :slight_smile:

2 Likes

So you should :wink:

The only thing that really annoys me about the Sky+ box, from an HA point of view, is no discreet off command and, as far as I can see, no way to tell whether it’s on or off across the network. My Harmony hub happily takes care of the rest.

When they decide my 30 odd years of loyal custom is worth a free Q I’ll take one, as it stands you still don’t even get 1080p so no point in paying for it.

I have created a folder named custom_components. it is in the Home Assistant folder that also hosts these folders

Is this correct ?

I also get the following error message when running a script check.

This is my config file.

Please help. What am i doing wrong.

Your configuration looks incorrect. Try this:

media_player:
  - platform: skyq
    name: Sky Q
    host: 192.168.1.91
    xmltv_feed_url: http://www.xmltv.co.uk/feed/6482

I’ve also tried that

media_player:

and

media_player:
platform: skyq
name: Sky Q
host: 192.168.1.91
xmltv_feed_url: http://www.xmltv.co.uk/feed/6482

also

media_player:

and they all get this error

but if i add just the google cast media player, all is good, the script check is successful.

Can you post the full text of the error log? The one you’ve posted above is truncated and cuts off before it shows any useful info. It’s likely that you’re missing a dependency or something but it could equally be a syntax error in your configuration.

Here it is. Although, i have managed to clear the errors so the script check is all good, however i also fail to see the media_player.skyq in the developer tools/state/current entities.

2017-08-16 14:08:18 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 61, in async_setup_component
return (yield from task)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 160, in _async_setup_component
conf_util.async_process_component_config(hass, config, domain)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/config.py”, line 593, in async_process_component_config
platform = get_platform(domain, p_name)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/loader.py”, line 104, in get_platform
return get_component(PLATFORM_FORMAT.format(domain, platform))
File “/usr/lib/python3.4/unittest/mock.py”, line 896, in call
return _mock_self._mock_call(*args, **kwargs)
File “/usr/lib/python3.4/unittest/mock.py”, line 962, in _mock_call
ret_val = effect(*args, **kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/scripts/check_config.py”, line 179, in mock_get
module = MOCKS[‘get’]1
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/loader.py”, line 142, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.4/importlib/init.py”, line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 2254, in _gcd_import
File “”, line 2237, in _find_and_load
File “”, line 2226, in _find_and_load_unlocked
File “”, line 1200, in _load_unlocked
File “”, line 1129, in _exec
File “”, line 1467, in exec_module
File “”, line 1572, in get_code
File “”, line 1532, in source_to_code
File “”, line 321, in _call_with_frames_removed
File “/home/homeassistant/.homeassistant/custom_components/media_player/skyq.py”, line 1
“”"
^
IndentationError: unexpected indent
(homeassistant) homeassistant@raspberrypi:/home/pi $

So that looks like Python is complaining about the source code not being indented properly, which probably means some extra spaces were added by mistake when copying/pasting the script into the file. Python is particularly anal about this sort of thing so it doesn’t take much to throw it off. Try erasing the contents of the skyq.py file and copy the script over again.

If it helps, use a tool like Notepad++ (or a MacOS equivalent) to view the whitespace characters in the file, both to make sure that copying hasn’t added unnecessary whitespace, and to make sure that the indentation matches the above script.

(At some point I’ll put this up on github to avoid people having to copy/paste from this thread and let them download the script directly.)

Also worth mentioning when posting copied code to be sure to highlight it and hit the “</>” button in the toolbar so people can see what you’ve really done, ie…

media_player:
  - platform: skyq
    name: Sky Q
    host: 192.168.1.91
    xmltv_feed_url: http://www.xmltv.co.uk/feed/6482

instead of…

media_player:

1 Like

Thanks bobby. I genuinely wasn’t aware of that. I wondered why it was incorrect.

  • Rookeh
    I have cleared all of my errors, but i still fail to see the media_player.skyq as mentioned in my previous post above. Do you have any idea why. Thanks for your time.

I recreated the skyq.py file and no change.

Otherwise i have a pal who will probably be reading this thread later…i will ask him for help ;o)

No worries. :slight_smile: As to why you’re still not seeing the entity, I would take an educated guess that, assuming the config is now valid and the script was copied correctly, your system might be missing a dependency that the script requires (there is a list of required modules in the first post). If you take a close look at your homeassistant log file, you might be able to confirm if this is the issue by looking for messages similar to “No module named…”.

If so, use pip to install these dependencies from the terminal, for example to install the pytz dependency you would use the command:

pip install pytz

Repeat for each module listed in the OP, then restart HA and see if that helps.

That may be the reason. I used the following command to install them all - sudo pip3 install X
I will try installing them all again.

edit - ok, it’s not that either.

pi@raspberrypi:~ $ sudo systemctl restart [email protected] pi@raspberrypi:~ $ pip install pytz -bash: pip: command not found pi@raspberrypi:~ $ sudo pip install pytz sudo: pip: command not found pi@raspberrypi:~ $ sudo pip3 install pytz Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/local/lib/python3.4/dist-packages Cleaning up... pi@raspberrypi:~ $

Ah, yes, you will need to use pip3 instead of pip (my mistake).

Something else to check, are you running HA directly from the command line as your currently logged in user, or is it running in a python virtual environment under a dedicated user account?

I’ve been caught out before by using sudo to install pip packages, only to realise that if you do this the packages will be installed for the root user and not the homeassistant user, therefore HA will be unable to find whatever packages you’ve installed. The solution therefore would be to run the pip command when logged in as whatever user account HA runs under and not to use sudo (you shouldn’t need elevation for this anyway).

Also, if running under a venv remember to activate the environment before running the command, e.g:

source /srv/homeassistant/bin/activate

I think you’ve found the problem. i’ve been installing all packages from root.
I will feedback once installed from the venv.

Damn. Thought we had it.

I managed to install the 2 of the 4 packages. 2 were already present in the venv. I also thought i forgot my password, then realised it was not required.
After a successful reboot, and error free script check, media_player.skyq still does not appear.

A new file and folder has appeared which is good news. They are the ones highlighted.

`Cleaning up…
pi@raspberrypi:~ $ sudo su -s /bin/bash homeassistant
homeassistant@raspberrypi:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@raspberrypi:/home/pi $ sudo pip3 install pytz

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for homeassistant:
Sorry, try again.
[sudo] password for homeassistant:
Sorry, try again.
[sudo] password for homeassistant:
Sorry, try again.
sudo: 3 incorrect password attempts
(homeassistant) homeassistant@raspberrypi:/home/pi $ pip3 install pytz
Requirement already satisfied: pytz in /srv/homeassistant/lib/python3.4/site-packages
(homeassistant) homeassistant@raspberrypi:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@raspberrypi:/home/pi $ pip3 install requests
Requirement already satisfied: requests in /srv/homeassistant/lib/python3.4/site-packages
(homeassistant) homeassistant@raspberrypi:/home/pi $ pip3 install ws4py
Collecting ws4py
Downloading ws4py-0.4.2.tar.gz (40kB)
100% |████████████████████████████████| 40kB 672kB/s
Installing collected packages: ws4py
Running setup.py install for ws4py … done
Successfully installed ws4py-0.4.2
(homeassistant) homeassistant@raspberrypi:/home/pi $ pip3 install xmltodict
Collecting xmltodict
Downloading xmltodict-0.11.0-py2.py3-none-any.whl
Installing collected packages: xmltodict
Successfully installed xmltodict-0.11.0
(homeassistant) homeassistant@raspberrypi:/home/pi $ exit
exit
pi@raspberrypi:~ $ sudo systemctl restart [email protected]
pi@raspberrypi:~ $ sudo su -s /bin/bash homeassistant
homeassistant@raspberrypi:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@raspberrypi:/home/pi $ hass --script check_config
`

So the new pycache folder and files would indicate that HA is trying to load the script but is running into some sort of issue. Is there anything else in the HA log file that looks out of place? Perhaps copy it to your local machine, open it up and Ctrl+F for “skyq” to see if there is anything at all being logged for the component, I would expect to at least see some sort of setup error if the entity just straight up isn’t appearing.

The log is picking up two of my sky q boxes. Not sure if the 3rd one is plugged in.

2017-08-16 20:10:39 WARNING (Thread-12) [netdisco.ssdp] Found malformed XML at http://192.168.1.34:49153/description0.xml:

No mention of skyq, but it definitely has the correct ip addresses.

I will keep playing, and sorry to ruin your project thread.

No problem, hopefully you can figure it out!

Also, those last log lines aren’t actually written out by the skyq script, but rather homeassistant’s discovery service.

Basically it sniffs the network for UPnP compatible devices, which the Sky Q box is (well, sort of). However, the Q’s UPnP services are a bit fiddly, so the discovery component just spits out those errors as it doesn’t know how to get a meaningful response…In short, those particular errors are unrelated and nothing to worry about. :slight_smile: