TPLink HS110 smart plug configuration help/error

I answered @dmshimself already here: https://github.com/GadgetReactor/pyHS100/issues/103 - as I don’t have a device to test, I would like someone to test the proposed fix before getting it merged and updated to homeassistant, so I’m currently waiting for some input from someone who has such a problematic plug.

Hi Temprrr

I’m happy to test the new code with the device i have here, what is the process?

Craig

Yep. Same here.

I’ll write up the process tonight once I’ve made the changes on my stack

1 Like

Any update?

If you cen tell me how to test I am happy to (I don’t know how to update sorry). I run home assistant in docker on my NAS.

I’ve been following this post and still am unable to see a solution that’s easy for people to implement and test.

I’ll list the two files I use on my Pi. I only have the latest TP Link firmware on my switch so this hasn’t been tested on the older firmware.

I did a dodgy workaround in smartdevice.py where it uses TRYs and EXCEPTIONs in place of the IF THEN statements that are currently used.

I’ve used onlinewarrior40’s solution for tplink.py.

I’ve uploaded smartdevice.py and tplink.py to my Google Drive.

Link to files …

Put tplink.py in the config\custom_components\switch folder on your HA installation.


You’ll need to overwrite the other smartdevice.py file that’s currently in your HA build.
You’ll need to ssh as root, change to the root directory of the installation and run the following command:

find “.” -name “smartdevice.py”

You’ll see a number of results, one will look like this:
/var/lib/docker/aufs/diff/somelargehexnumber/usr/lib/python3.6/site-packages/pyHS100/smartdevice.py

That’s the file you need to replace so copy the smartdevice.py over that one, reboot and it should work.

It will stop working when you update HA next as the smartdevice.py will get overwritten so you will need to repeat the bits from the line break to get it working again.

Hi @mattyman I’ve just tried your solution but it is still throwing out the same error. I have created a switch folder in custom_components and put the tplink.py in there. I’ve replaced the smartdevice.py with the one that you’ve uploaded. Below is the error. Any ideas?

edit: looks like I have multiple directories with smartdevice.py so I’ll update all of them
edit 2: I had to change smartdevice.py in three locations (one of the may of worked but I don’t know which one) and it works, cheers

tplink: Error on device update!
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 197, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/usr/src/app/homeassistant/helpers/entity.py", line 327, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/switch/tplink.py", line 122, in update
    emeter_statics = self.smartplug.get_emeter_daily()
  File "/usr/local/lib/python3.6/site-packages/pyHS100/smartdevice.py", line 417, in get_emeter_daily
    for entry in response['day_list']}
  File "/usr/local/lib/python3.6/site-packages/pyHS100/smartdevice.py", line 417, in <dictcomp>
    for entry in response['day_list']}
KeyError: 'energy'

Kind of looks like the Smartdevice.py file didn’t copy across as it still looks like it’s returning ‘energy’ instead of ‘energy_wh’.

It will try ‘energy’ first and if it fails it will catch it as an exception and then will try ‘energy_wh’ instead. Yours doesn’t seem to be catching the exception.

Can you double check the file that you copied across?

Yes it worked, I edited the original post. It seems I had the smartdevice.py in several locations. I’m not sure which one was the correct so I changed them all and it works now. Good job.

1 Like

If it helps, I tried this on 0.64.5 with a virtual environment and an HS100 with the latest firmware and after copying those files in place I get:

Error while setting up platform tplink
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py”, line 82, 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/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/switch/tplink.py”, line 43, in setup_platform
add_devices([SmartPlugSwitch(SmartPlug(host), name, leds_on)], True)
File “/srv/homeassistant/lib/python3.5/site-packages/pyHS100/smartplug.py”, line 37, in init
SmartDevice.init(self, host, protocol)
File “/srv/homeassistant/lib/python3.5/site-packages/pyHS100/smartdevice.py”, line 50, in init
socket.inet_pton(socket.AF_INET, ip_address)
OSError: illegal IP address string passed to inet_pton

OSError: illegal IP address string passed to inet_pton

Indicates that you have an invalid IP address setup in your config under the TP Link switch settings.

Are you sure that the IP address you’ve configured for your TP Link device is correct in the config on your virtual environment?

Cheers. Such a schoolboy error as the docs say to use the IP address and I used a name to resolve. I got out of the habit of using static IP for devices. I’ve put the real IP address in and all is well.

When running the numbers on usage look a bit odd - the voltage shows 970.80 V, the current 291.8 A, but hey I can switch it on and off no problems.

That extra help was really appreciated.

This worked for me!

I now have control of my HS110 (EU) device and also see the meter-readings within HomeAsssitan (virtualenv).

One thing to mention, I didn’t place tplink.py in a custom_components directory, but just replaced /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/tplink.py with it. Otherwise it didn’t work.

1 Like

I actually haven’t really looked at the reported voltage figures. I just used the scripts that were posted above.

The reported voltage was right for me. It reports around 230 Volt here.

Hi,
I’ve been following this topic for a while. I did not have time to implement the solutions discussed, and I’m hoping that it’ll make it into the official version of HA. Will this eventually be the case?
Thanks.

Hello,

I am getting a similar error. can anyone please help

2018-04-18 21:47:26 ERROR (MainThread) [homeassistant.components.switch] tplink: Error on device update!
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 188, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 327, in async_device_update
yield from self.hass.async_add_job(self.update)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/switch/tplink.py”, line 108, in update
= “{:.2f}”.format(emeter_readings[“power”])
KeyError: ‘power’

Firmware details:
Hass.io supervisor
Version 0.101
Latest version 0.101

TPLink:
Model: HS110
Firmware 1.5.2
Hardware: 2.0

I can confirm @mattyman fix works. The error you are getting is if you don’t update tplink.py

Of the different versions of tplink.py the one under switch needs to be updated.

Yep. As jtitley pointed out, that error looks like tplink.py hasn’t been updated. Are you running on a Pi or on some other architecture?

If you’re on a Pi you just need to navigate to the device in a file manager (like windows explorer) and navigate to the config folder.

If you know your Pi’s IP address it will be something like this:
\\[Pi IP Address]\config

Once you are in that folder you may need to create the other folders, custom_components and switch:
\\[Pi IP Address]\config\custom_components\switch

Copy tplink.py into that folder and it should stop throwing the error message.

If you aren’t running on a Pi you’ll have to search for the file in your installation. SSH in, navigate back to the root folder and do a find “.” -name “tplink.py”. This will list all the locations where tplink.py is found. You’ll need to find the one for the switch and replace it (I recommend renaming it and copying the new file across).