Error setting up UPnP component

I’m trying to make my home assistant accessible from the internet so I can use Google Home for control with the Google Assistant component. I’m assuming the best way to configure the router to forward traffic to my instance is the UPnP component. However, when I put it in the config and restart, I get an error in the log. I’m running HA inside docker, which is inside a VirtualBox Ubuntu server. Any help would be appreciated.

Here is the relevant part of the config:

upnp:
  local_ip: 192.168.0.39
  ports:
    hass: 8000

And here is the error I’m getting:

Log Details (ERROR)
Sat Jun 02 2018 21:30:46 GMT+1000 (Australian Eastern Standard Time)

Error during setup of component upnp
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/setup.py", line 143, in _async_setup_component
    hass, processed_config)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/upnp.py", line 116, in async_setup
    await service.add_port_mapping(internal, external, host, 'TCP',
AttributeError: 'BaseService' object has no attribute 'add_port_mapping'

This is a bug. Could you create an issue here: https://github.com/home-assistant/home-assistant/issues

Thanks!

Hi!

Can you provide more information such as version of HA ?

I just tried to replicate the issue, using the configuration you provided and had no issue :frowning:

Just realised something… is your Virtualbox Ubuntu server bridged with the network of your router or is it NAT’ed ?

The server is bridged. If I use “ifconfig” it shows the expected IP address in my LAN (although hassio is there with a different range - 172… instead of 168… - could that be docker doing magic?). I’m using the latest version of HA - 0.70.1

What sort of router do you have ?
DSL, Fiber, DOCSIS ?

It’s a Netgear D6200 DSL modem/router. The router already has a couple of UPnP entries for other ports (probably set up years ago). Full disclosure - I’m also having problems with the Netgear component timing out, although it does find some attached devices. The error message does sound “bug-like” - I don’t know Python but in the languages I do know, it would be a bad thing to expect an object to call ‘add_port_mapping’ if it doesn’t implement it. Having said that, I’m new to everything in this field, so it’s probably my fault.

Well I think I might know the problem, but will need to walk you through some tests in order to pin point and find a possible solution. Can you find me on Discord ? I use the same handle (@dgomes)

That’s a generous offer, but it’s 2am here and I need sleep. Can you point me in the right direction for the morning?

It’s 17h30 here :slight_smile:

I’m sure the issue is in the upstream library pyupnp_async, which was not tested with a PPP setup (as still used by some ISP’s)

What I’ll ask from you is to clone my github fork of the library (https://github.com/dgomes/pyupnp-async/) and run the test msearch.py, posting the results on hastebin.com.

If you have enough patience we can still use discord :smiley: and avoid spamming the forum, we will just take a longer time to reply each other.

You’re right, my modem is configured as PPPoE - it seems freaky you can deduce that from the error. If the world has moved beyond PPP, nobody told Australia - my street has to wait another 2 years for the next substandard upgrade. At least the top two ISPs here use PPP, so the implication is nobody in Australia on DSL has the UPnP component working (really?). I’m not going to get the chance to look at this until next weekend. I will try the clone&test then, and contact you on Discord. In the meantime, do you think I should raise a defect?

1 Like

Well you can raise the issue to make it easier to track. But in the end it will probably be me correcting the situation :wink:

I will see if I can find a way to test PPP with someone else meanwhile, and hopefully by next week have a patch ready for you to test.

I have run msearch.py, although I’m not sure how to get it off the box in text format, so I took a screen shot. One thing that stands out is 192.168.0.5, which is my v1.0 Philips Hue hub. If I turn the hub off it seems to crash earlier - the first DEBUG line comes out but not the second, and then an exception occurs at line 40, 'NoneType' object has no attribute 'src_ip'.

I also probably ran it the hardest way - I used pip install to get the package and then wget to get the raw version of msearch.py.

Hi since last week :slight_smile:

I really need you to use the version from my git repository and not the version from pip … I already did some changes there that have not been pushed upstream.

Ah yes, that was my intention, so I must be doing it wrongly. I did pip3 install --upgrade git+https://github.com/dgomes/pyupnp-async/ and then wget to get the raw msearch.py.

After some Googling, I used -e instead of --upgrade and added #egg=pyupnp_async which gave me a local copy. I then went to the directory and did python3 setup.py install, which all seemed to go ok. On rerunning I got the error below. Note there are two errors - the first seems to happen occasionally (no attribute src_ip). The second shows the source is the local copy of your version, so hopefully I got it right this time. Learning all the time! BTW I had a quick look at Discord, and it did my head in. How about email instead? Although being in different parts of the world, carrier pigeon might be just as quick. Also, why is it looking at the hub for the lights, rather than the router? My router is at 192.168.0.1.

well in order to use my version, best way is to actually clone my GitHub repository:

# git clone https://github.com/dgomes/pyupnp-async.git

this will download all the code without any need to install anything system wide. I would go one step further and remove existing pyupnp-async installs:

# pip uninstall pyupnp-async

Afterwards just run all the stuff from inside the pyupnp_async directory you downloaded using git.

I find very strange that only the Hue light shows up… can you disconnect the Hue hub temporarily and run msearch ?

Lets keep the pigeon exchange here, hoping to find someone else in a closer timezone :slight_smile:

Hey, Did you guys ever managed to work this out?
I’m using a Netgear R8000 and connected over PPPoE to the internet.
I’ve added this to my configs (with the right numbers of course):

 upnp: 
   port_mapping: true
   ports: 
     1xx0: 11xx0
     3xx8: 13xx8
     7xx1: 17xx1
     8xx1: 18xx1
     9xx1: 19xx1
     hass: 443

and now I have this error:

Error setting up entry R8000 (Gateway) for upnp
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py", line 236, in async_setup
result = await component.async_setup_entry(hass, self)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/__init__.py", line 113, in async_setup_entry
device = await Device.async_create_device(hass, ssdp_description)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 36, in async_create_device
upnp_device = await factory.async_create_device(ssdp_description)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 848, in async_create_device
service = await self.async_create_service(service_desc_xml, description_url)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 875, in async_create_service
return self.create_service(service_description_xml, scpd_xml)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 882, in create_service
state_vars = self.create_state_variables(scpd_xml)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 902, in create_state_variables
state_var = self.create_state_variable(state_var_xml)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 908, in create_state_variable
state_variable_info = self._state_variable_parse_xml(state_variable_xml)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 927, in _state_variable_parse_xml
state_variable_xml.find('service:sendEventsAttribute', NS).text == 'yes'
AttributeError: 'NoneType' object has no attribute 'text'

Is this the same problem?
I’m going to fall back to my original static port forward, but I would so love to have these handled by upnp. Please let me know if you need any testing, I’ll try my best.

B

Well, version 0.80 has a brand new UPnP implementation :slight_smile:

Have you test it ?

Oh. Yeah, I am seeing that error on 0.80. sorry, I was not crystal clear on that.

Ok, so can you fill a proper issue on GitHub for that ? So we can do a proper follow up