D-link W215 Switch firmware update stopped them from working with HA

Hi guys, I just bought one AU plug as well and got updated to 1.25 straight away.
Same as you HA cannot talk with it for now.
But I have reported the bug to the pyW215 author and just found a way where we could have it working again.
(https://github.com/LinuxChristian/pyW215/issues/22)
So hopefullly a permanenet fix can be in place soon and later integrated to HA again.

Otherwise, when investigating for smartplug with power monitor (and support in HA), I could not find much else with AU plug, so interested as well if someone has some other options!

Cheers

@hcooh I literally just found your issue thread over at pyW215 and headed here to post about the progress being made.

My investigations were not as scientific but I did find that the plug was returning an ERROR response to an auth request. I did think it was something to do with session timeouts but didn’t have the time to look into it.

Thanks for your work on this!!!

No worries,

The code change has been pushed to HA, so it should work from the next release onward for 1.25 firmware.
Unfortunately we have not tested if the changes are still working on 1.24 firmware or if it breaks things…
So if someone has 1.24 and experiences issues at the next HA release, let us know!

Just what I was looking for, thanks guys.
BTW how often does HA update?

Usually every 1 or 2 weeks…
See stats here: HA Release stats

So, I’ve got the update 0.53, but D-Link W215 switches are still not working, does 0.53 contain the fix?
Log message ->
2017-09-12 07:28:24 WARNING (SyncWorker_8) [pyW215.pyW215] Unable to open a connection to dlink switch http://192.168.1.*

Hi @bedo2405,
You are on dlink firmware 1.25, right?
Yes, looking at the git commit for 0.53, the fix for firmware 1.25 has made its way in.
While updating HA, it should have pulled the version 0.6 of pyW215 library. Maybe you can start by checking that this is the version of the lib installed in the HA environment?
Make sure you have the “use_legacy_protocol: True” line in your configuration file.
I am sure you have checked but is the IP address correct?
Also, looks unrelated to your problem, but looking at the history, some changes in the name of the switch attributes occured:
history of dlink for 0.53

1 Like

Thanks heaps for the reply.
My config looks like this ->

switch:

  • platform: dlink
    name: Bedroom Lamp
    host: http://192.168.1.51
    username: admin
    password: ******
    use_legacy_protocol: true
  • platform: dlink
    name: Mood Lighting
    host: http://192.168.1.50
    username: admin
    password: ******
    use_legacy_protocol: true

I’ve double checked the IPs and pin numbers. What else could it be?
BTW, I’m running hassio, how do I check I have 0.6 of pyW215 library?

after update to 0.53 and checking my /usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/dlink.py

I think my dlink.py is still on 0.5.1 (REQUIREMENTS = [‘pyW215==0.5.1’])
The attribute name are still in capitals.
ATTR_CURRENT_CONSUMPTION = ‘Current Consumption’
ATTR_TOTAL_CONSUMPTION = ‘Total Consumption’
ATTR_TEMPERATURE = ‘Temperature’

Did a manual replace of the file and restart the service and its now WORKING!! woohoo! honestly it was the very reason I started to use HA. Still new to this but I can cant wait to automate all of it.

@Leo-R_Lee, Glad that it is working again for you. Not too sure why it did not pull pyW215 0.6 by itself…
I just upgraded HA to 0.53.1 and it did pull pyW215 0.6 normally.

@bedo2405, I am not too sure how to check on Hassio… but maybe by increasing the log level, it will tell us more. you could put the following in your configuration.yaml (and restart HA):

logger:
 default: error
 logs:
   homeassistant.components.switch: debug

This is all I get ->
2017-09-21 21:15:27 INFO (MainThread) [homeassistant.components.switch] Setting up switch.dlink
2017-09-21 21:15:27 INFO (SyncWorker_3) [pyW215.pyW215] Enabled support for legacy firmware.
2017-09-21 21:15:27 WARNING (SyncWorker_3) [pyW215.pyW215] Unable to open a connection to dlink switch http://192.168.1.50
2017-09-21 21:15:28 WARNING (SyncWorker_14) [pyW215.pyW215] Failed to open url to http://192.168.1.50

Hi @bedo2405,

So it seems, the pyW215 cannot establish a proper request to the url of the plug… Coming from:

try:
            response = urlopen(Request(self.url, payload, headers))
        except URLError:
            if self._error_report is False:
                _LOGGER.warning('Unable to open a connection to dlink switch {}'.format(self.ip))
                self._error_report = True
            return None

At this stage the authentication process has not even started so it seems there is something wrong with either the plug not being reachable or your hassio installation has some broken things around the needed requests ?
The issue you are experiencing is not connected with the recent changes in the library.

Are you able to control the plug with the dlink app ? In which case it would indicate something is wrong with hassio…
I am not familiar with hassio, is there a way we can execute some custom python code to try to debug what is wrong ?

I have been having issues for a number of weeks now (after the upgrade to 0.53), but it is nof for all W215 plugs I’m using. I’m on HASSIO. First, all switches can still be controlled through the D-Link App. Four switches which are directly connected to the WLAN of my Fritzbox router work perfectly fine through HA. Three switches I have connected to an access point on the second floor of my house, I no longer can control through HA (these still work with the DLink App). I also went back to my old all-in-one installed HA on 0.52 and everything worked fine again. I then upgraded the all-in-one installer to 0.55 and the same problem is there. My log is showing “unable to open a connection to dlink switch xyz”. Very interesting why switched work that are directly connected to my Fritzbox WLAN, but not to the access point. Is there a delay factor or something in the component?

Hi @Felix ,

That is really interesting indeed. It looks like it could be the same issue as @bedo2405 . And you are both using Hassio.

Are all the switches identical? Have you tried to switch one from downstairs to upstairs? (or reverse, just as a sanity check)
Can you check the firmware version for each plug ? (in the dlink app)
Are you using the legacy protocol ?

The changes in the dlink library that got merged for 0.53, only changes the way the legacy protocol talks to the switch, nothing else.
And given the error you have it does not seem to even reach that stage as it does not get an answer from the plug.
Let me know the details mentioned above and if you are available there are a few things we can try to find out what is going on…

Yes I’m on Hasio

I’m on Hassio. However, I also did go back to my old installation (all in one installer) and all plugs worked again. Then I upgraded to to the latest version and I have exactly the same issues as with Hassio (certain plugs not working). I did move switches around but the switches on the second floor don’t work. All plugs have firmware version 2.22. I do not have legacy protocol activated. Appreciate your help!

Hi,

Okay, so are not using the legacy protocol. The recent changes in the PyW215 was only affecting the legacy protocol. It does not change anything for the newer protocol…
And it seems that the issue arises as soon as the first connection to the plug. My suspicion is that it more comes from a change in another library.
One way to confirm it is not the pyW215, is if you can place in the config folder of HASS or HASSIO the following:
Create folders /custom_components/switch/
Add the file dlink.py from there: https://raw.githubusercontent.com/home-assistant/home-assistant/0.52.1/homeassistant/components/switch/dlink.py
Restart HA. It basically forces HA to use the dlink version from HA 0.52.1

Can you please test on an updated version of HA ?
(or else, you could do contrary and try the new version of the dlink on an old version of HA, it would be this dlink file then:
https://raw.githubusercontent.com/home-assistant/home-assistant/0.56.2/homeassistant/components/switch/dlink.py)

Now, to help correctly fix the issue going forward, we would need to understand what exactly go wrong.
If you are able to help us, in the /custom_components/switch/ folder replace the dlink.py file available here: https://pastebin.com/TmentLhN
Also make sure you have this in the configuration.yaml:

logger:
  default: error
  logs:
    custom_components.switch: debug

Restart HA (possibly test under 0.52 and 0.53+)
Paste here the output

Let me know if you need clarifications

Thank you so much for your time to respond and the detailed instructions. I tried all of the options you listed above:

  1. HA 56.2 with current dlink.py
  2. HA 56.2 with dlink.py from 52.1
  3. HA 52.1 with current dlink.py
  4. HA 52.1 with dlink.py from 52.1
  5. HASSIO 56.2
    The results for all are identical and some switches show up, other switches don’t show up. To be clear, the same switches show up or don’t show up across all three combinations. The error is the same every time - copied the error below. I’m also following another thread which seems like a similar (the same) issue: https://community.home-assistant.io/t/d-link-motion-sensor-dch-s150/9850/17

Here is the error
2017-11-02 17:21:51 ERROR (MainThread) [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 170, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File “/usr/lib/python3.4/asyncio/tasks.py”, line 372, in wait_for
return fut.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 450, in setup_platform
use_legacy_protocol))
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 77, in init
self.model_name = self.SOAPAction(Action=“GetDeviceSettings”, responseElement=“ModelName”, params = “”)
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 148, in SOAPAction
self.authenticated = self.auth()
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 325, 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 461, in open
response = meth(req, response)
File “/usr/lib/python3.4/urllib/request.py”, line 571, in http_response
‘http’, request, response, code, msg, hdrs)
File “/usr/lib/python3.4/urllib/request.py”, line 499, in error
return self._call_chain(*args)
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 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

Sorry for the late reply, but I noticed that the supplied module (from HA 0.52.1) does not appear to include a PIN code (password).

Could that explain why some plugs respond, and others don’t? IE: they are expecting different passwords?

My dlinks (also AU/NZ) are on version 1.26 and are not working. My log reports:
Failed to connect to D-Link switch

14:47:37 – dlink (WARNING) - message first occurred at 14:25:36 and shows up 10 times

Waiting 4.001320883333333 s to retry

14:47:37 – dlink (WARNING) - message first occurred at 14:29:37 and shows up 14 times

Error doing job: Task exception was never retrieved

14:25:42 – components/stream/worker.py (ERROR)

Failed to receive initial authentication from smartplug.

14:25:36 – /usr/local/lib/python3.8/site-packages/pyW215/pyW215.py (WARNING) - message first occurred at 14:25:36 and shows up 2 times

There is no dlink.py anywher in my configurtaion, yet these switches workwed till recently. I looked in /usr/share/hassio and in the python-3.8 folders and then ran 'find; across my entire Ubuntu configuration. Is dlink.py still used. The log above refers to pyW215.py