Problem D-Link Switch

So today I wanted to install my D-Link W215 switch by adding the component and filling in all credentials etc.
The switch does not show up.

I got these errors in the logs.

16-03-13 16:01:48 homeassistant.loader: Loaded switch.dlink from homeassistant.components.switch.dlink
16-03-13 16:01:48 homeassistant.util.package: Attempting install of https://github.com/LinuxChristian/pyW215/archive/v0.1.1.zip#pyW215==0.1.1
16-03-13 16:01:59 homeassistant.components.switch: Error while setting up platform dlink
Traceback (most recent call last):
  File "/usr/lib/python3.4/urllib/request.py", line 1174, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 836, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 95, in _setup_platform
    discovery_info)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/dlink.py", line 44, in setup_platform
    name)])
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 145, in add_entities
    if self.component.add_entity(entity):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 116, in add_entity
    entity.update_ha_state()
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 147, in update_ha_state
    state = STATE_UNKNOWN if self.state is None else str(self.state)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 232, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/dlink.py", line 71, in is_on
    return self.smartplug.state == 'ON'
  File "/var/opt/homeassistant/lib/pyW215/pyW215.py", line 157, in state
    response =  self.SOAPAction('GetSocketSettings', 'OPStatus', self.moduleParameters("1"))
  File "/var/opt/homeassistant/lib/pyW215/pyW215.py", line 100, in SOAPAction
    auth = self.auth()
  File "/var/opt/homeassistant/lib/pyW215/pyW215.py", line 201, in auth
    response = urlopen(Request(self.url, payload, headers))
  File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.4/urllib/request.py", line 455, in open
    response = self._open(req, data)
  File "/usr/lib/python3.4/urllib/request.py", line 473, in _open
    '_open', req)
  File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 1202, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.4/urllib/request.py", line 1176, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 113] No route to host>
OSError: [Errno 113] No route to host

Is the IP address of the switch correct and the device online?

I can see it in myDlink app, I can login via browser on it’s webpage with admin and password and I see it in Fing.

It’s online at 192.168.0.146 that is the IP I filled out in the configuration.yaml along with admin and password.

Sorry, I missed this thread. Can you try to use module directly? Something like the sample below should work.

 from pyW215 import SmartPlug

 sp = SmartPlug('192.168.1.110', '******')
 plug = sp.current_consumption
 print(plug)

Apologies for adding to an old thread but I am having issues with setting up my Dlink Wi-Fi Smartplugs too.

I receive the following message in the logs:

16-06-04 23:46:19 homeassistant.components.switch: Error while setting up platform dlink
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 109, in _setup_platform
    discovery_info)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/dlink.py", line 44, in setup_platform
    name)])
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 166, in add_entities
    if self.component.add_entity(entity, self):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 136, in add_entity
    entity.update_ha_state()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 147, in update_ha_state
    state = STATE_UNKNOWN if self.state is None else str(self.state)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 232, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/dlink.py", line 71, in is_on
    return self.smartplug.state == 'ON'
  File "/home/hass/deps/pyW215/pyW215.py", line 157, in state
    response =  self.SOAPAction('GetSocketSettings', 'OPStatus', self.moduleParameters("1"))
  File "/home/hass/deps/pyW215/pyW215.py", line 100, in SOAPAction
    auth = self.auth()
  File "/home/hass/deps/pyW215/pyW215.py", line 231, in auth
    raise Exception("Failed to authenticate with SmartPlug")
Exception: Failed to authenticate with SmartPlug

I have tried multiple combos of IP address with and without the leading “http://”.

@dennisaion, were you able to get yours installed?

Any help or advice would be appreciated. Thank you :relaxed:

I gave up on this.

So did I. I have them sort of working using IFTTT triggers to turn them on and off, but basically I’m putting them on unimportant things and eventually replacing them with WeMo switches.

I agree with @dennisaion and @LazerPanther - I took my 2x D-Link WiFi SmartPlugs back to the store this morning and swapped them for 2x WEMO Insight Switches.

Up and running with the WEMO’s in minutes. Worth the extra $ to save my sanity. Happy Days!!! :smiley:

In case anyone needs a solution and hopefully a dev can amend this. The problem is that in pyW215.py, there are strings for making http requests in this format: ’ “string” '. The inner set of parentheses need to be deleted and then it at least doesn’t reaise an exception. The on and off part doesn’t work and I think the code is missing that bit. Since I have one I may work on it.

1 Like

@ggamble22 - did you have time to look into this?

Anybody else still having issues? I’m getting the following errors (using WSP215 plugs). Seems like the same issue to me.

16-10-04 15:28:50 pyW215.pyW215: Unable to open a connection to dlink switch http://192.168.178.xx/
16-10-04 15:28:50 homeassistant.components.switch: Error while setting up platform dlink
Traceback (most recent call last):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 107, in _setup_platform
discovery_info)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/dlink.py”, line 55, in setup_platform
name)])
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 198, in add_entities
if self.component.add_entity(entity, self):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 134, in add_entity
entity.update_ha_state()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 159, in update_ha_state
device_attr = self.device_state_attributes
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/dlink.py”, line 76, in device_state_attributes
ui_temp = self.units.temperature(int(self.smartplug.temperature),
TypeError: int() argument must be a string or a number, not ‘NoneType’

Shortly after I started looking into it the original author of the library fixed the major error. If you delete the pyW215 library in your deps folder, HA should download the fixed one or you may have to go the github page and replace it manually.

Also it does generate warnings about not finding total consumption since the library does not support that in the US version of the plug.

Thanks for your quick response! Deleted the files/directory, got replaced by new versions, but still receiving exactly the same errors. Any advice/thoughts?

1 Like

Try downloading the source from https://github.com/LinuxChristian/pyW215 and replace the files in the deps/pyW215.

Thanks - but…still doesn’t work. Keep getting exactly the same error messages. I’m not sure what else to do. I see in the forum that others have similar issues.

I’m having the same issues. Tried upgrading pyW215 but still doesn’t work. It’s probably worth noting I’m using the UK version of the plug.

So I just tried this again for this first time in ages, and something definitely changed cause all of a sudden they work like a champ. Still buying WeMo ones in the future, but at least I don’t have to use IFTTT triggers now.

Did you do anything specifically? I’m still having issues

I kept trying and also had a close look in the files that are reported in the log file. I can’t figure it out. Just to be sure - I’m using a W215, hardware revB with software version 2.22, a Fritzbox 6490 in Germany. Configuration in .yaml is the following:
platform: dlink
host: http://192.168.178.xx
name: Plug
username: admin
password: xxxxxx

And now they’re back to not working :frowning: Back to troubleshooting.

Anybody any luck with this?