TPLink HS110 smart plug configuration help/error

I have no idea how to even go about getting the fix in. Also, the cobbled together ‘fix’ is more a workaround and I don’t know if it will even work with switches that have the older firmware.

We kind of need someone who actually knows what they are doing to come and have a look at it and maybe try to turn it into a usable end product.

@mattyman : Thank you so much. have proceed 1 step further. now it throws following error. I am on pi3. I dont know where the smartdevice.py is stored and there is no file locations as /usr/local/lib/python3.6/site-packages/pyHS100/

2018-04-19 18:39:34 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 “/config/custom_components/switch/tplink.py”, line 122, in update
emeter_statics = self.smartplug.get_emeter_daily()
File “/usr/lib/python3.6/site-packages/pyHS100/smartdevice.py”, line 417, in get_emeter_daily
for entry in response[‘day_list’]}
File “/usr/lib/python3.6/site-packages/pyHS100/smartdevice.py”, line 417, in
for entry in response[‘day_list’]}
KeyError: ‘energy’

I am in the same position. Anyone found a solution to this problem yet? Have two new HS-110’s sitting around that I cant do anything with.

I’ve successfully applied this change to both Windows and Raspberry Pi setups. Try installing tplink.py directly over the switch component file instead of in custom_components. At least that is what I did.

When I have some time I will debug this and see if I can make a proper fix for submission.

So i took these changes, with some slight modifications, and turned then into full blown custom components, but even then i get the Error on device update issue :frowning:

Unfortunately, if i overwrite the existing classes, it makes the HS100’s i ALSO have not work :frowning:

Oh dear: I’ve just seen this thread and it’s not what I wanted to see on a Sunday morning! I am about to do a product review of the HS110 and it working with HA. I have never had any problems with mine, which is one of reasons I am recommending it to my followers/viewers. That being said, I have had my unit for well over a year and so it will be old firmware that isn’t affected (I only read up to about post 20/65 so I may have it wrong).

It looks like my video is not getting done today while I research this and maybe find a new energy monitoring socket to test/review/recommend.

1 Like

I was looking for a good value device and thought the tplink would be the one, but no. If your review comes up with a good alternative, do please let us know or point us at your review?

1 Like

You haven’t copied across smartdevice.py like I mentioned in my previous post.

Follow these instructions.

This has been fixed in git of pyhs100, so that’ll be fine in the future :slight_smile:

Regarding to fixing this properly, there is this partial patch/PR from me, but unfortunately I haven’t had time to finish it to include historical records. So if here’s someone who wants to step in and make it happen it’d be very welcome, but if not, I’ll try to look into it again at some point. The only reasonable way to fix this is not by creating partially working custom components, but fix it in upstream.

1 Like

Because i have a mixture of HS100s and HS110s, all the manual patching suggested in these threads breaks the 100s :frowning:

For the time being ive just setup the 110 I have as a rest switch, connected to the TP Link cloud API. Atleast that way I can use it as a switch (albeit an expensive one!)

Can you put up the config for the rest switch for the 110 please.

I must have misunderstood something as my hassio build doesn’t seem to have a smartdevice.py anywhere on the pi at all. I have added the switch component, so I get the ‘energy’ error rather than the ‘power’ error now but not sure what to do now.

Here for anyone that wants to setup their HS110 purely with code using appdaemon

You will need to find your device id and token using the info
http://itnerd.space/2017/06/19/how-to-authenticate-to-tp-link-cloud-api/

create an app in apps.yaml

tpswitch_iron:
  module: tpswitch
  class: SwitchControl
  device_id: "YOUR_DEVICE_ID"
  token_id: "YOUR_TOKEN"

And then create a tpswitch.py file with the following code

#The aim of this is turn off and on the tp switch

import appdaemon.plugins.hass.hassapi as hass
import requests


class SwitchControl(hass.Hass):

    url = "https://aps1-wap.tplinkcloud.com/?token="
    
    payload_s = '''{
        "method":"passthrough",
        "params":{
        "deviceId":"'''
    payload_on = '''",
        "requestData":"{\\"system\\":{\\"set_relay_state\\":{\\"state\\":1}}}"
        }
        }'''
    payload_off = '''",
        "requestData":"{\\"system\\":{\\"set_relay_state\\":{\\"state\\":0}}}"
        }
        }'''
    urlt = ""
    payload = ""
    token_id = ""
    device_id = ""        

    def initialize(self):
        
        self.device_id = self.args["device_id"]
        self.token_id = self.args["token_id"]

        #see if morning changes
        self.listen_state(self.modechange, "input_boolean.bool_iron")
        #see if morning changes
        self.listen_state(self.modechange, "input_boolean.mode_morning")
        #listen to see if everyone leaves
        self.listen_state(self.modechange, "input_select.presence")
    
    def modechange(self, entity, attribute, old, new, kwargs):
        if entity == "input_select.presence" and new == "All Away":
            self.turnoffflag()
        elif entity == "input_boolean.mode_morning" and new == "on":
            self.turnonflag()
        elif entity == "input_boolean.mode_morning" and new == "off":
            self.turnoffflag()
        elif entity == "input_boolean.bool_iron" and new == "on":
            self.turnonswitch()
        elif entity == "input_boolean.bool_iron" and new == "off":
            self.turnoffswitch()
        
    #turn on the flag
    def turnonflag(self):
        self.turn_on("input_boolean.bool_iron")

    #turn on the flag
    def turnoffflag(self):
        self.turn_off("input_boolean.bool_iron")

    #turn on the switch
    def turnonswitch(self):
        self.urlt = self.url + self.token_id
        self.payload = self.payload_s + self.device_id + self.payload_on
        r = requests.post(self.urlt, data=self.payload)
        #self.log(r)
        
        
    #turn off the switch
    def turnoffswitch(self):
        self.urlt = self.url + self.token_id
        self.payload = self.payload_s + self.device_id + self.payload_off
        r = requests.post(self.urlt, data=self.payload)
        #self.log(r)
1 Like

Supposedly TP link released new firmware on the 19 June 2018. This code no longer works, does anyone knows how to find the new JSON messages?

Does anyone who is following this thread have any alternative, not too expensive switches they can recommend that work with HA?

I use the HS110, but I also have the Broadlink switches, cheaper and reliable too.

thanks very much for that. I’ve not managed to find a supplier in NZ where I live, but I’ll keep looking.

For those who have issues, the latest is that there is a fix to the underlying pyHS100 module. So you no longer need to patch any HA tplink files (they will be overwritten with the latest update anyhow).

See here:

After upgrading HA just overwrite the two files in this commit and all is well. Next version of pyHS100 should include these fixes so hopefully this is the last patch for this issue.

I’ve come back to this subject today after a while and the HS switch itself comes up fine which is excellent news. However the suggestions on https://www.home-assistant.io/components/switch.tplink/ to set up sensors gives me very odd numbers. The switch is on for about 7 hours a day and has been on for many days - with the switch off at the moment and doing nothing, I get:

Current Consumption 283233.0
Current 292.0
Total Consumption -0.0010
Todays Consumption 0
Voltage 971

This is version 1.2.10 of the firmware

Has anyone managed to find a way to get correct values displayed?

I’m using this which seems to work;

'{{ states.switch.x.attributes["current_power_w"].split(" ")[0] }}'