Enigma2 receivers integration

OK thanks - l’m happy to help test anything, and I would dig around in the code myself but Python is one of the few languages I’ve not worked with (must change that!)

Thanks so much for this - my Beyonwiz PVR is now added.

1 Like

I learned python over a weekend 2 years ago, and never touched it again, so my knowledge on Python is also very basic :slight_smile:

But it’s strange that you can get the xml from the hass.io and it doesn’t work.

I’ve just installed hass.io and copied enigma.py to /config/custom_components/media_player/ and both my box’s appeared and work fine.

Can you past the output of curl -u root:password http://192.168.1.44/web/getallservices |head -n 20

I would like to see the first 10 lines of the xml output.

Thanks

Here you are. Hope it helps.

<?xml version="1.0" encoding="UTF-8"?>
<e2servicelistrecursive>
                <e2bouquet>
                        <e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.abm.terrestrial_uk_freeview.main.tv" ORDER BY bouquet</e2servicereference>
                        <e2servicename>FreeView (UK) - All channels</e2servicename>
                        <e2servicelist>
                        <e2service>
                                <e2servicereference>1:64:0:0:0:0:0:0:0:0::FreeView (UK) - Entertainment</e2servicereference>
                                <e2servicename>FreeView (UK) - Entertainment</e2servicename>
                        </e2service>
                        <e2service>
                                <e2servicereference>1:0:19:4484:4085:233A:EEEE0000:0:0:0:</e2servicereference>
                                <e2servicename>BBC ONE HD</e2servicename>
                        </e2service>
                        <e2service>
                                <e2servicereference>1:0:19:4440:4085:233A:EEEE0000:0:0:0:</e2servicereference>
                                <e2servicename>BBC TWO HD</e2servicename>
                        </e2service>
                        <e2service>
                                <e2servicereference>1:0:19:44C5:4085:233A:EEEE0000:0:0:0:</e2servicereference>

I’ve got it working, so no need to investigate your code - that’s fine! :grinning:

I’ve made a few changes and I just need to narrow down which one was causing the problem and then I’ll post back here to help others who might have the same issue. Watch this space!

1 Like

I got the exact same error on my VU+ Ultimo 4k, hope you can figure out what caused this!

text in bold is the solution to my original error, other text is a new problem.

The cause of the original error was the password used for the enigma box. I am using a new enigma box that’s only a few weeks old and so I hadn’t changed the default password for the root account from literally “password”. SSH on to the enigma box and a quick “passwd” command to change the password to anything other than “password”, change the config in HA, restart, and the enigma media player controls appear as expected with no errors in the log.:grinning:

Changing the enigma box root password back to “password” and it all fails again! So something in the code is not dealing with specifically defining the password as “password”!

Now it’s up and running I have discovered a problem with the picon display in HA. Your custom component is attempting to load a picon (the card briefly slides down as if it is about to display the picon but then slides back up) and it seems to keep trying.

Looking at enigma.py and trying to understand the python (which I am now learning from your custom component! :wink:) the important code seems to be lines 178 to 194.

The call on line 179 gives:

<e2servicelist>
  <e2service>
    <e2servicereference>1:0:19:4484:4085:233A:EEEE0000:0:0:0:</e2servicereference>
    <e2servicename>BBC ONE HD</e2servicename>
  </e2service>
</e2servicelist> 

and the call made on line 187 returns:

<e2eventlist>
  <e2event>
    <e2eventid>47224</e2eventid>
    <e2eventstart>1520503200</e2eventstart>
    <e2eventduration>3600</e2eventduration>
    <e2eventcurrenttime>1520503977</e2eventcurrenttime>
    <e2eventtitle>Homes Under the Hammer</e2eventtitle>
    <e2eventdescription>
       A small garden with planning permission in Canterbury in Kent, a flat in London's Crystal Palace and a bungalow in the village of Branthwaite in Cumbria are sold at auction. [HD] [S]
    </e2eventdescription>
    <e2eventdescriptionextended/>
    <e2eventservicereference>1:0:19:4484:4085:233A:EEEE0000:0:0:0:</e2eventservicereference>
    <e2eventservicename>BBC ONE HD</e2eventservicename>
  </e2event>
</e2eventlist>

The picon_url built on line 191 uses the e2servicereference value resulting in a URL of:

http://192.168.1.44/picon/1_0_19_4484_4085_233A_EEEE0000_0_0_0.png

(including the username and password of course)

That URL returns a 404 no such resource error.

However on my system the correct picon for this channel should be:

http://192.168.1.44/picon/bbconehd.png

which is the e2servicename with the whitespace removed and converted to lowercase. This method works for all the channels to determine the correct png filename.

This may be because I am using terrestrial DVB-T2 tuners, or it could be a UK thing, I’m not sure exactly how it works as I am fairly new to enigma2 receivers so don’t understand the system properly yet.

Fantastic work so far and great to have basic control of the receiver from HA! Let me know if I can help any more with this picon issue supplying more info or testing code - very happy to help get this working fully!

[EDIT] Can I also put in a feature request to define which bouquet to use instead of it being the first bouquet it finds? Thanks!

Thanks Fran, I had already changed the default password. To be sure I tried something test only but no luck.
The authentication settings are good, if I change anything I see this:
ConnectionRefusedError: [Errno 111] Connection refused

I can acces both URL for the services & bouquets just fine when using http//user:pw@ipaddress//

But I am still getting this error HA:

2018-03-08 12:56:55 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform enigma
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py”, line 84, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.5/asyncio/tasks.py”, line 400, in wait_for
return fut.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 76, in async_setup_platform
config.get(CONF_TIMEOUT))
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 112, in init
self.load_sources()
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 117, in load_sources
reference = urllib.parse.quote_plus(self.get_bouquet_reference())
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 133, in get_bouquet_reference
bouquets_xml = self.request_call(’/web/getallservices’)
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 144, in request_call
return self._opener.open(uri, timeout=self._timeout).read().decode(‘UTF8’)
AttributeError: ‘bool’ object has no attribute ‘open’

Can you access the xml files from your Home Assistant server? So from the command line what happens if you do:

curl -u root:<your_password> http://<your_enigma_ip>/web/getallservices

Yep, works fine

Ok, finally got this working. The script seems to be unable to handle a custom port (port 81 in my case).
Changed OpenWebif to port 80 and works straight away.

Was almost at the point of flashing another image :smile:

1 Like

So those errors we have both seen are when the script can’t connect to the enigma receiver for some reason. @cinzas would it be possible for the script to check that and fail gracefully, perhaps also showing a meaningful message on the media player card?

I’m getting the following when trying to power on my enigma2 box. It repeats endlessly

2018-03-08 14:33:08 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.bedroom fails
Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 146, in request_call
return self._opener.open(uri, timeout=self._timeout).read().decode(‘UTF8’)
File “/usr/lib/python3.5/urllib/request.py”, line 472, in open
response = meth(req, response)
File “/usr/lib/python3.5/urllib/request.py”, line 582, in http_response
‘http’, request, response, code, msg, hdrs)
File “/usr/lib/python3.5/urllib/request.py”, line 510, in error
return self._call_chain(*args)
File “/usr/lib/python3.5/urllib/request.py”, line 444, in _call_chain
result = func(*args)
File “/usr/lib/python3.5/urllib/request.py”, line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 199, in async_update_ha_state
yield from self.async_device_update()
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 306, in async_device_update
yield from self.hass.async_add_job(self.update)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/init.py”, line 306, in wrapper
result = method(*args, **kwargs)
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 187, in update
xml = self.request_call(’/web/epgservicenow?sRef=’ + reference)
File “/home/homeassistant/.homeassistant/custom_components/media_player/enigma.py”, line 148, in request_call
_LOGGER.exception("Enigma: [request_call] - Error connecting to remote enigma %s: %s ", self._host, HTTPError.code)

Appears a reboot of the reciever after enabling http auth was required.

2nd vote for being able to select bouquet though

Hi guys

Great inputs. Thanks for that.
So, collecting the inputs.

  1. Using a port other than 80 is not working (I will test)
  2. If password=password then fails (easy to solve :slight_smile: )
  3. Picons not displaying
  4. Possibility to select bouquet.

The 2 is easy to solve. 1 should be working, I will try.
For 3, i got the impression that Enigma was seeking the picons by the reference in the internal picon folder. So it seems it also search for the channel name. In that case i will have to load one picon by default and if it fails then try to load the second way. I’ve to do more tests on this. Don’t know if all enigmas work on this way.

For 4, that’s also one of the things I would like. Since I’ve forked this from other git, I will have to take a look in detail to the way it is being loaded. The problem is it will take more time to load if we have to perform the parsing trough all channels (I’ve more than 3k channels on one of my set top boxes !!!).

Looking forward to have the time to look in to that :slight_smile:

2 Likes

Hi everyone

Just committed the new version to github.

It now accepts connections on distinct ports (was working only with port 80).
It accepts all passwords (even password=“password” :slight_smile: ).

Regarding the picons, and after reading in some enigma forums, I’m seeing that the standard is to use the channel reference. So I will kindly ask you to try that on your enigmas.
The url to the picon is passed directly to the media_player component. In order to solve this I would need to change my component to check the url in advance, and for each time, request it to the enigma box, check if it exists and then send it to the media_player so it does the same work again.

In case the picon request failed, I would have to check by the name (in lowercase, without special chars), and if the box ack the request, then send it again to the media_player component.

This means that it will at least double the http request to display a picon, and for those who have by channel name, it would triplicate the number of requests.

Unless there are a lot more people with the same problem, i would rather prefer to change the picons names in the box.

@Fran, would it work for you?

1 Like

Thanks @cinzas ! Renaming the picons is fine for me (I’ll write a simple script to do it for me) but you may come across other people with a similar problem if they are using terrestrial (DVB-T2) tuners. I’ve been doing a little reading and the e2servicereference name is based on the frequency (and other info of the channel). For a satellite (DVB-S) tuner system these would be the same for everyone and so the implemented system works.

However, on the terrestrial system the same TV channel could have different e2servicereference values depending on which transmitter your aerial is pointing towards. Because of this, I guess there is the alternative naming system on the enigma box for picons to deal with these regional variations and looks for a picon name based on the channel name rather than the channel frequency etc.

The openwebif displays picons when you look at the EPG in a browser, so I wonder if there is another way of determining which picon to use, maybe another API call that asks the enigma system which picon to use rather than trying to determine it yourself?

One last thing, would it be possible to make the display of the picon optional and not even attempt to load it? It would avoid problems if the picons are not present for any reason and also gives the option of not using up too much space on the user interface on a smaller screen.

Thanks for your hard work, very much appreciated! :grinning:

[EDIT] There is a function called getPicon() in services.py of the openwebif source which may be useful. I also notice there is another function called getPiconPath() (defined in info.py) that suggests picons may not always be in one place. Source for openwebif is on github here: https://github.com/E2OpenPlugins/e2openplugin-OpenWebif

Hi Fran

Making the picon optional should be easy.
If I’ve time during the weekend I will implement that.

The functions you reference are on server side and not exposed.
This is currently what is available via http requests: https://dream.reichholf.net/wiki/Enigma2:WebInterface#Client_API

Doesn’t mean that other stuff isn’t impossible to implement, but using enigma2 webinterface with http requests the available methods are restricted.

What I would like to look now is a way to use the notification componente from home assistant and integrate it with the enigma2 component, so we can have notifications sent to the TV whenever we want :slight_smile:

Rgds

That’s an interesting resource - I have not seen that before. I understand that something running on the enigma box will have more access, but I wondered if some of the code could be re-used (with changes) to deal with both types of picon naming as both the web UI and this HA custom component need to deal with both.

If you have no objections, I’m going to see if I can modify your code to work in my situation, and then if I am successful (and learning python at the same time!) we could look to merge that into your code.

Notifications on the TV would be great!

1 Like

Great I would appreciate that !

Learning by doing, that’s also what I’m doing