Enigma2 receivers integration

Tags: #<Tag:0x00007f7803286158>

Hi

Some already started with this, but i would like to bring it again for discussion
I’ve published on github the work i did on integration enigma2 receivers.

Currently working with my 2 boxes (gigablue and dreambox).
What works:

  • Power status: on, off, standby.
    
  • Loads all sources from first bouquet. (Current channel and possibility to change channels)
    
  • Volume regulation (mute, set, step)
    
  • Change channel (Selecting from source list or via Right/Left - from remote controller)
    
  • Current channel and current event
    
  • Picon from current channel
    
  • Supports authentication and multiple receivers
    

More and more could be done. I’m just doing my first steps with Python, so be gentle :slight_smile:

Next idea, if I have the time, is to create the notify component for enigma2. I believe it can also be very useful.

Would like to get feedback from you.

Find the custom component from github: https://github.com/cinzas/homeassistant-enigma-player

Screenshots

312

3 Likes

Hi,

I thought I would give this a go with my Vu+Duo2 but I’m getting errors in the log (and no media player controls):

Error while setting up platform enigma
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/config/custom_components/media_player/enigma.py", line 78, in async_setup_platform
    config.get(CONF_TIMEOUT))
  File "/config/custom_components/media_player/enigma.py", line 114, in __init__
    self.load_sources()
  File "/config/custom_components/media_player/enigma.py", line 119, in load_sources
    reference = urllib.parse.quote_plus(self.get_bouquet_reference())
  File "/config/custom_components/media_player/enigma.py", line 135, in get_bouquet_reference
    bouquets_xml = self.request_call('/web/getallservices')
  File "/config/custom_components/media_player/enigma.py", line 146, in request_call
    return self._opener.open(uri, timeout=self._timeout).read().decode('UTF8')
AttributeError: 'bool' object has no attribute 'open'

I hope that means more you than it does to me! OpenWebIF works fine via a browser on the IP and port that I’ve set in the configuration:

   - platform: enigma
     host: 192.168.1.44
     port: 80
     name: VuDuo2
     icon: mdi:satellite-variant
     timeout: 20
     username: root
     password: password

I’m on a Hassio install v0.64.1

Hi Fran

I’m currently in a business trip to the US.
Let me take a look over that next week.

Meanwhile, please set the log to debug, and copy paste the error again. Should bring more useful information.

Thanks

Sorry for the delay - I’ve not had the opportunity to try again until now. With debug logging there is a little more info but not much, so hope that helps!

2018-03-05 09:11:34 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.enigma
2018-03-05 09:11:34 DEBUG (MainThread) [custom_components.media_player.enigma] Enigma: [request_call] - Call request http://192.168.1.44/web/getallservices 
2018-03-05 09:11:34 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform enigma
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/config/custom_components/media_player/enigma.py", line 78, in async_setup_platform
    config.get(CONF_TIMEOUT))
  File "/config/custom_components/media_player/enigma.py", line 114, in __init__
    self.load_sources()
  File "/config/custom_components/media_player/enigma.py", line 119, in load_sources
    reference = urllib.parse.quote_plus(self.get_bouquet_reference())
  File "/config/custom_components/media_player/enigma.py", line 135, in get_bouquet_reference
    bouquets_xml = self.request_call('/web/getallservices')
  File "/config/custom_components/media_player/enigma.py", line 146, in request_call
    return self._opener.open(uri, timeout=self._timeout).read().decode('UTF8')
AttributeError: 'bool' object has no attribute 'open'
2018-03-05 09:11:34 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: timestamp=1520241094.109678, level=ERROR, message=Error while setting up platform enigma, exception=Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/config/custom_components/media_player/enigma.py", line 78, in async_setup_platform
    config.get(CONF_TIMEOUT))
  File "/config/custom_components/media_player/enigma.py", line 114, in __init__
    self.load_sources()
  File "/config/custom_components/media_player/enigma.py", line 119, in load_sources
    reference = urllib.parse.quote_plus(self.get_bouquet_reference())
  File "/config/custom_components/media_player/enigma.py", line 135, in get_bouquet_reference
    bouquets_xml = self.request_call('/web/getallservices')
  File "/config/custom_components/media_player/enigma.py", line 146, in request_call
    return self._opener.open(uri, timeout=self._timeout).read().decode('UTF8')
AttributeError: 'bool' object has no attribute 'open'
, source=custom_components/media_player/enigma.py>

Hi Fran,

Are you using authentication ?

Can you please open with your browser the following pages, and let me know if any works (gives an xml output):

In your config of webinterface, in the box, do you have configured it to work on port 80 or only on port 443 ?

Thanks

Both the direct links provide the nicely formatted XML you would expect.

I’ve tried with and without openwebif authentication (and proving the authentication works via a browser) and have both port 80 and 443 open in the openwebif config (both http and https links to openwebif working fine in a browser)

Still getting exactly the same error as posted before.

I also just tried this from the hassio CLI and got the expected XML, so the hassio system can see the enigma box fine.

curl -u root:password http://192.168.1.44/web/getallservices

Thanks for looking into this - would be great to get basic control on the box!

Thanks

It seems I will very likely need to install hass.io :slight_smile:
I will manage to get a old raspberry pi, a sd card and install hass.io

I will try that

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:[email protected]//

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)