TPLink HS110 smart plug configuration help/error

Nothing missing from the log file that I can see. Using those commands, I get

<SmartPlug at 192.168.17.209 (Garden Spray Pump), is_on: True - dev specific: {‘LED state’: True, ‘On since’: datetime.datetime(2017, 11, 26, 8, 5, 9, 917993)}>

and

defaultdict(<function SmartDevice.sys_info.. at 0x7f0bfc8f0e18>, {‘sw_ver’: ‘1.2.10 Build 170828 Rel.104625’, ‘hw_ver’: ‘2.0’, ‘type’: ‘IOT.SMARTPLUGSWITCH’, ‘model’: ‘HS110(AU)’, ‘mac’: ‘70:4F:57:FF:9D:D5’, ‘dev_name’: ‘Smart Wi-Fi Plug With Energy Monitoring’, ‘alias’: ‘Garden Spray Pump’, ‘relay_state’: 1, ‘on_time’: 14500, ‘active_mode’: ‘schedule’, ‘feature’: ‘TIM:ENE’, ‘updating’: 0, ‘icon_hash’: ‘’, ‘rssi’: -72, ‘led_off’: 0, ‘longitude_i’: 1747493, ‘latitude_i’: -367080, ‘hwId’: ‘A28C8BB92AFCB6CAFB83A8C00145F7E2’, ‘fwId’: ‘00000000000000000000000000000000’, ‘deviceId’: ‘80061332763BC320A64E79C6488A70EE19524C17’, ‘oemId’: ‘6480C2101948463DC65D7009CAECDECC’})

and

{‘day_list’: [{‘year’: 2017, ‘month’: 11, ‘day’: 15, ‘energy_wh’: 6}, {‘year’: 2017, ‘month’: 11, ‘day’: 16, ‘energy_wh’: 0}, {‘year’: 2017, ‘month’: 11, ‘day’: 17, ‘energy_wh’: 1}, {‘year’: 2017, ‘month’: 11, ‘day’: 18, ‘energy_wh’: 0}, {‘year’: 2017, ‘month’: 11, ‘day’: 19, ‘energy_wh’: 1}, {‘year’: 2017, ‘month’: 11, ‘day’: 20, ‘energy_wh’: 435}, {‘year’: 2017, ‘month’: 11, ‘day’: 21, ‘energy_wh’: 308}, {‘year’: 2017, ‘month’: 11, ‘day’: 22, ‘energy_wh’: 325}, {‘year’: 2017, ‘month’: 11, ‘day’: 23, ‘energy_wh’: 1765}, {‘year’: 2017, ‘month’: 11, ‘day’: 24, ‘energy_wh’: 1147}, {‘year’: 2017, ‘month’: 11, ‘day’: 25, ‘energy_wh’: 789}, {‘year’: 2017, ‘month’: 11, ‘day’: 26, ‘energy_wh’: 283}]}

As a quick hack/experiment, I changed smartdevice.py so that the line

else:
key = ‘energy’
to
else:
key=‘energy_wh’

and it all burst into life.

My take is that for some reason that if self.emeter_units: set to True is not being picked up as a true condition. Should it be set to true or 1 or something else perhaps? It is currently set to be False as you previously mentioned.

Still some good progress

1 Like

Sorry just noticed this. The data brought back in the current entities seems to be a factor of 10 out. For example voltage is 2326.26 whereas it is actually 232.726. The other data coming back is

voltage: 2327.26 V
current: 29.8 A
current_consumption: 6374.2 W
total_consumption: 51.73 kW
daily_consumption: 379.00 kW
friendly_name: Garden Spray Pump

On the tplink app, it shows (for example) current consumption as 637W

Yes, your change is what I tried to achieve with the boolean “emeter_units”. If set to True, you should match the ‘if’ condition and use ‘energy_wh’ instead of ‘energy’. Can’t explain why setting the boolean to True before calling this function didn’t work.
The modification you made makes smartdevice.py incompatible with previous firmware. I wanted to have a generic modification and also not touch the underlaying library.
We’ll need someone better than I am with python to make it work !

About the units, not only the labels have changed in the new firmware but also the value is in another unit ! Power is in mw now instead of W. And of course, the line 91 “div = 100” should be “div = 1000” :crazy_face:
We need someone better with python AND more cautious when writing code ! :sweat_smile:

I’m happy it’s sort of working for me and I’m sure when the authors of this bit get a chance to look at it, all will be well. I’m very grateful for the assist and learned a lot while rummaging around. I guess as other people buy these newer versions, they might find this thread too and realise they are not alone :slight_smile:

The emeter_units in pyhs100 is currently used for the bulbs, so it looks like the newer firmwares for plugs are adapting the same style, too. It would be very welcome if someone would provide a sysinfo output here: https://github.com/GadgetReactor/pyHS100/issues/103 or even provide a patch (and inclusion of new sysinfo to test suite) to fix this issue.

I’d be happy to do that - I don’t quite know what a sysinfo output is, but if you point me in the right direction I’d be happy to run/upload

There is pyhs100 command line tool available (it’s installed as a dependency for the tplink support of homeassistant). pyhs100 emeter returns the emeter information and pyhs100 sysinfo that of system, both would be interesting to have. You may want to mask some values such as hwId, latitude, longitude and mac before pasting it there.

here is the first one:

$ pyhs100 emeter
No IP given, trying discovery…
Discovering devices for 3 seconds
== Garden Spray Pump - HS110(AU) ==
Device state: ON
IP address: xxx.xxx.xxx.xxx.xxx
LED state: True
On since: 2017-12-03 13:05:09.032522
== Generic information ==
Time: 2017-12-03 13:07:08
Hardware: 2.0
Software: 1.2.10 Build 170828 Rel.104625
MAC (rssi): mm:mm:mm:mm:mm:mm (-70)
Location: {‘latitude’: 0000000, ‘longitude’: 0000000}
== Emeter ==
Current state: {‘voltage_mv’: 970801, ‘current_ma’: 291751, ‘power_mw’: 283233130, ‘total_wh’: -1}

Traceback (most recent call last):
File “/srv/homeassistant/bin/pyhs100”, line 11, in
sys.exit(cli())
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/click/decorators.py”, line 63, in new_func
% object_type.name)
RuntimeError: Managed to invoke callback without a context object of type ‘SmartDevice’ existing
(homeassistant) homeassistant

and here is the second:
pyhs100 sysinfo
No IP given, trying discovery…
Discovering devices for 3 seconds
== Garden Spray Pump - HS110(AU) ==
Device state: ON
IP address: xxx.xxx.xxx.xxx.xxx
LED state: True
On since: 2017-12-03 13:08:19.847611
== Generic information ==
Time: 2017-12-03 13:10:36
Hardware: 2.0
Software: 1.2.10 Build 170828 Rel.104625
MAC (rssi): mm:mm:mm:mm:mm:mm (-69)
Location: {‘latitude’: 0000000, ‘longitude’: 0000000}
== Emeter ==
Current state: {‘voltage_mv’: 233581, ‘current_ma’: 74, ‘power_mw’: 1405, ‘total_wh’: 0}

Traceback (most recent call last):
File “/srv/homeassistant/bin/pyhs100”, line 11, in
sys.exit(cli())
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/srv/homeassistant/lib/python3.6/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/click/decorators.py”, line 63, in new_func
% object_type.name)
RuntimeError: Managed to invoke callback without a context object of type ‘SmartDevice’ existing
(homeassistant) homeassistant@ubuntu-dms:/home/dms$

Sorry for not getting back to you before, somehow I forgot to answer to this. Can you check what version of pyhs100 are you running? pip freeze|grep pyHS100 will return the infromation to you. I have 0.3.0, but in your case the output from sysinfo command is something unexpected,:

$ pyhs100 sysinfo
No --bulb nor --plug given, discovering..
Discovering devices for 3 seconds
== System info ==
defaultdict(<function SmartDevice.sys_info.<locals>.<lambda> at 0x762c89c0>,
            {'active_mode': 'schedule',
             'alias': 'My Smart Plug',
             'dev_name': 'Wi-Fi Smart Plug With Energy Monitoring',
             'deviceId': '8006588E50AD389303FF31AB6XXX',
             'feature': 'TIM:ENE',
             'fwId': '3A1C9C60B93A090DF07XXXX',
             'hwId': '45E29DA8382494D2E826XXXX',
             'hw_ver': '1.0',
             'icon_hash': '',
             'latitude': X,
             'led_off': 0,
             'longitude': X,
             'mac': '50:C7:BF:01:F8:CD',
             'model': 'HS110(EU)',
             'oemId': '3D341ECE302C0642C99E31CE2430544B',
             'on_time': 4377720,
             'relay_state': 1,
             'rssi': -72,
             'sw_ver': '1.0.8 Build 151101 Rel.24452',
             'type': 'smartplug',
             'updating': 0})

p.s. you may want to filter out your latitude and longitude, alongside with "id"s.

I have the same version I’m afraid. If I use the commands further up this discussion to get sys_info, I get:

defaultdict(<function SmartDevice.sys_info.. at 0x7fece2c86e18>, {‘sw_ver’: ‘1.2.10 Build 170828 Rel.104625’, ‘hw_ver’: ‘2.0’, ‘type’: ‘IOT.SMARTPLUGSWITCH’, ‘model’: ‘HS110(AU)’, ‘mac’: ‘70:4F:57:FF:9D:D5’, ‘dev_name’: ‘Smart Wi-Fi Plug With Energy Monitoring’, ‘alias’: ‘Garden Spray Pump’, ‘relay_state’: 0, ‘on_time’: 0, ‘active_mode’: ‘schedule’, ‘feature’: ‘TIM:ENE’, ‘updating’: 0, ‘icon_hash’: ‘’, ‘rssi’: -76, ‘led_off’: 0, ‘longitude_i’: 1747493, ‘latitude_i’: -367080, ‘hwId’: ‘A28C8BB92AFCB6CAFB83A8C00145F7E2’, ‘fwId’: ‘00000000000000000000000000000000’, ‘deviceId’: ‘80061332763BC320A64E79C6488A70EE19524C17’, ‘oemId’: ‘6480C2101948463DC65D7009CAECDECC’})

I guess if someone can and is prepared to update their device to the later firmware, they might see the same issue.

I’ve just purchased a HS110 and I’m encountering the same issue.
ERROR (MainThread) [homeassistant.components.switch] Error on device update!
Which breaks down to
File “/usr/lib/python3.6/site-packages/homeassistant/components/switch/tplink.py”, line 103, in update
= “%.1f W” % emeter_readings[“power”]
KeyError: ‘power’

Device shipped with 1.2.10
but I updated to 1.5.2
Unfortunately I found no mention in the components page that there were any issues with updated different firmware.

So while I’m regretting my decision not to spend more on the Aeotec… just wondering if there’s anything I can do to help debug this issue?

The problem is known, it is just that no one has put time into fixing it (properly). The issue itself is tracked here https://github.com/GadgetReactor/pyHS100/issues/103 .

If you want to modify it locally (that switch/tplink.py - around line 103), you could just change your copy to use the renamed keys as seen above in this thread.

1 Like

I bought two of these (Australian) plugs yesterday, but I only came across this thread after I realised they weren’t working.
I have v2.0 with 1.5.2.
HA 0.58.0.

I hope the people more skilled than I am are able to get this back on track so these devices can be used.
Until then, I’ll sit tight and throw out my appreciation for those working on the issue. :clap:

1 Like

Hi, I’m using HA 0.61.1 with 2x v2.0 HS110(AU) with the “1.5.2 Build 171201 Rel.084625” software.

Like others, I found that the switches either didn’t show up in HA, or showed up with only partial emeter data, or showed up with data in incorrect units for this sw version. While pyHS100 Issue 103 is being worked on, I thought I’d share what I’ve done.

After reading through the above, and keeping in mind the above HS110 (I only have 2 and they are both V2.0 with sw 1.5.2):

(homeassistant) [homeassistant@homeassistant homeassistant]$ python -i ./lib/python3.6/site-packages/homeassistant/components/switch/tplink.py
>>> from pyHS100 import SmartPlug
>>> smart = SmartPlug('192.168.1.244')
>>> smart
<SmartPlug at 192.168.1.244 (Iron), is_on: False - dev specific: {'LED state': True, 'On since': datetime.datetime(2018, 1, 18, 20, 47, 52, 515181)}>
>>> smart.sys_info
defaultdict(<function SmartDevice.sys_info.<locals>.<lambda> at 0x7f9b90fcbe18>, {'sw_ver': '1.5.2 Build 171201 Rel.084625', 'hw_ver': '2.0', 'type': 'IOT.SMARTPLUGSWITCH', 'model': 'HS110(AU)', 'mac': '50:C7:BF:4A:43:19', 'dev_name': 'Smart Wi-Fi Plug With Energy Monitoring', 'alias': 'Iron', 'relay_state': 0, 'on_time': 0, 'active_mode': 'none', 'feature': 'TIM:ENE', 'updating': 0, 'icon_hash': '', 'rssi': -43, 'led_off': 0, 'longitude_i': XXXXXXX, 'latitude_i': XXXXXXX, 'hwId': 'A28C8BB92AFCB6CAFB83A8C001XXXXXXX', 'fwId': '00000000000000000000000000000000', 'deviceId': '8006DD821AF03DAD777FAAABCD15349818XXXXXXX', 'oemId': '6480C2101948463DC65D7009CAXXXXXXX'})
>>> smart.get_emeter_realtime()
{'voltage_mv': 248370, 'current_ma': 12, 'power_mw': 0, 'total_wh': 929}
>>> smart.get_emeter_daily()
{9: 101, 10: 474, 11: 71, 12: 0, 13: 0, 14: 622, 15: 0, 16: 0, 17: 0, 18: 141}
>>> 

The following works for me:

def update(self):
    """Update the TP-Link switch's state."""
    from pyHS100 import SmartDeviceException
    try:
        self._available = True
        self._state = self.smartplug.state == \
            self.smartplug.SWITCH_STATE_ON

        if self._name is None:
            self._name = self.smartplug.alias

        if self.smartplug.has_emeter:
            emeter_readings = self.smartplug.get_emeter_realtime()
            for value in emeter_readings :
              try :
                  name, unit = value.split("_",1)
                  div = 1000
              except ValueError:
                  name = value.split("_",1)[0]
                  div = 1

              if name == "power":
                  self._emeter_params[ATTR_CURRENT_POWER_W] \
                      = "%.1f W" % (float(emeter_readings[value])/div)
              if name == "total":
                  self._emeter_params[ATTR_TODAY_ENERGY_KWH] \
                      = "%.2f kW" % (float(emeter_readings[value])/div)
              if name == "voltage":
                  self._emeter_params[ATTR_VOLTAGE] \
                      = "%.2f V" % (float(emeter_readings[value])/div)
              if name == "current":
                  self._emeter_params[ATTR_CURRENT_A] \
                      = "%.1f A" % (float(emeter_readings[value])/div)

            emeter_statics = self.smartplug.get_emeter_daily()
            try:
                self._emeter_params[ATTR_TODAY_ENERGY_KWH] \
                    = "%.2f kW" % (float(emeter_statics[int(time.strftime("%e"))]/1000))
            except KeyError:
                # Device returned no daily history
                pass

    except (SmartDeviceException, OSError) as ex:
        _LOGGER.warning("Could not read state for %s: %s", self.name, ex)
        self._available = False

It gives the following in HA:

voltage  249.60 V
current a  0.0 A
current power w  0.0 W
today energy kwh  0.14 kW

… which is good enough for me :slight_smile:

Hope this helps someone else as much as I’ve been helped from the above comments!

I just created a pull request to fix the first part of this in pyhs100 https://github.com/GadgetReactor/pyHS100/pull/107 - it would be nice if someone could test and report back at https://github.com/GadgetReactor/pyHS100/issues/103 .

I’m having problems with my AU HS110 - not sure what I need to update or exactly which files to edit. Is anyone able to point me in the right direction? Looking at the current version of smartdevice.py it seems the changes have now been merged but I’m still not able to see the device in hass.io and get errors in the error log.

File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch/tplink.py”, line 103, in update
= “{:.2f}”.format(emeter_readings[“power”])
KeyError: ‘power’

Same as webscience2. Running hass.io 0.62.0 but not sure how I can test the changes.

Yes I popped this into place and the error moves on to the follow (which might what you expected to see!). This is with 0.62.1

Error while setting up platform tplink
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 189, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.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 “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/tplink.py”, line 38, in setup_platform
from pyHS100 import SmartPlug
File “/srv/homeassistant/lib/python3.5/site-packages/pyHS100/init.py”, line 17, in
from .smartplug import SmartPlug
File “/srv/homeassistant/lib/python3.5/site-packages/pyHS100/smartplug.py”, line 8, in
from … import SmartPlug, SmartDeviceException
ValueError: attempted relative import beyond top-level package

Hopefully this problem is resolved in the next month or so