Home Assistant release with the issue:
Home Assistant 0.67.0
Last working Home Assistant release (if known):
N/A
Operating environment (Hass.io/Docker/Windows/etc.):
Using https://hub.docker.com/r/homeassistant/home-assistant/ on a Synology NAS.
Component/platform:
Description of problem:
According to the logs, home-assistant is not able to even add the device. The new HS110 firmware seems to have changed the API output. The issue was already reported in the pyHS100 issue tracker.
A good solution (other than waiting for this library to fix this problem) could be to create a way to disable the energy meter through a setting key or just fail more gracefully in these kinds of cases.
Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):
switch:
- platform: tplink
host: 192.168.1.34
Traceback (if applicable):
tplink: Error on device update!
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 188, in _async_add_entity
await 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/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/app/homeassistant/components/switch/tplink.py", line 108, in update
= "{:.2f}".format(emeter_readings["power"])
KeyError: 'power'
Additional information:
None
Yes, the same here...
Same here (0.67.0 and 0.67.1)- setting up new device added config as per OP and components doco, logging shows the following - I've obfuscated/removed anything that I think identifies my device or location:
2018-04-28 17:37:18 INFO (MainThread) [homeassistant.components.switch] Setting up switch.tplink
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] > (31) {"system": {"get_sysinfo": {}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] < (586) {"system":{"get_sysinfo":{"sw_ver":"1.5.2 Build 171201 Rel.084625","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(AU)","mac":"<obfuscated>","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":"Blanky","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-63,"led_off":0,"longitude_i":<obfuscated>,"latitude_i":<obfuscated>,"hwId":"<obfuscated>","fwId":"<obfuscated>","deviceId":"<obfuscated>","oemId":"<obfuscated>","err_code":0}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] > (31) {"system": {"get_sysinfo": {}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] < (586) {"system":{"get_sysinfo":{"sw_ver":"1.5.2 Build 171201 Rel.084625","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(AU)","mac":"<obfuscated>","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":"Blanky","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-63,"led_off":0,"longitude_i":<obfuscated>,"latitude_i":-<obfuscated>,"hwId":"<obfuscated>","fwId":"<obfuscated>","deviceId":"<obfuscated>","oemId":"<obfuscated>","err_code":0}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] > (31) {"system": {"get_sysinfo": {}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] < (586) {"system":{"get_sysinfo":{"sw_ver":"1.5.2 Build 171201 Rel.084625","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(AU)","mac":"<obfuscated>","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":"Blanky","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-63,"led_off":0,"longitude_i":<obfuscated>,"latitude_i":-<obfuscated>,"hwId":"<obfuscated>","fwId":"<obfuscated>","deviceId":"<obfuscated>","oemId":"<obfuscated>","err_code":0}}}
2018-04-28 17:37:18 DEBUG (SyncWorker_5) [pyHS100.protocol] > (32) {"emeter": {"get_realtime": {}}}
2018-04-28 17:37:19 DEBUG (SyncWorker_5) [pyHS100.protocol] < (104) {"emeter":{"get_realtime":{"voltage_mv":238222,"current_ma":15,"power_mw":0,"total_wh":0,"err_code":0}}}
2018-04-28 17:37:19 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'
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: timestamp=1524901039.1635952, level=ERROR, message=tplink: Error on device update!, exception=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'
, source=components/switch/tplink.py>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=group, service=set, service_data=object_id=all_switches, name=all switches, entities=[], visible=False, service_call_id=1967660080-3>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=group.all_switches, old_state=None, new_state=<state group.all_switches=unknown; entity_id=(), order=2, auto=True, friendly_name=all switches, hidden=True @ 2018-04-28T17:37:19.199754+10:00>>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=turn_off>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=turn_on>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=toggle>
2018-04-28 17:37:19 INFO (MainThread) [homeassistant.setup] Setup of domain switch took 21.4 seconds.
Here my log after the upgrade from home assistant to 0.68
tplink: Error on device update!
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 188, in _async_add_entity
await entity.async_device_update(warning=False)
File "/srv/homeassistant/lib/python3.5/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.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.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 108, in update
= "{:.2f}".format(emeter_readings["power"])
KeyError: 'power'
I created simple fix for this until it will be fixed on Home Assistant side. This will allow new users to use TP-Link HS110 smart sockets:
https://gist.github.com/AdamStrojek/4d7dbdea48f6e9e3efd8ca52b21c0864
@AdamStrojek maybe you can submit this as a PR
@gerardo This is only temporary fix based on branch that will be merged to pyHS100. When new version of pyH100 will be released to PyPI we can start about creating proper fix. Also I couldn't test it for older version of HS110 and HS100
I fixed the missing parts in pyhs100 to fix this issue for good, the code from this PR should work without any changes on homeassistant's side: https://github.com/GadgetReactor/pyHS100/pull/107 -- it would be nice if someone could test if that's the case and report back, I only have tested it with the older version of HS110.
Can confirm its purely HS110
The hs100 (hw 1.0 fw 1.2.5) works, the hs110 (hw 2.0 fw 1.4.3) doesn't. Maybe I can help get the PR merged
Did you try the code in the linked PR? And it is not working for you?
My changes do not persist after reboot. (running hassio docker image)
I have the Previous exception stack, and not sure what version I have running. Im new
Try to install with -e. I'm unsure of how the mechanism of homeassistant works in these cases, I personally just use -e for pip installs for my local copies.
Ok I had no luck with the git repo, but I managed to implement the fix from @AdamStrojek in the custom_components directory and now I'm able to use the switch.toggle features in HA.
Looks like inroads are being made in https://github.com/GadgetReactor/pyHS100/pull/107, so hopefully we'll see that PR land and the dependency can be updated in a future Home Assistant release.
I wrote a fix for the problem and tested it locally with my HS110 v2.0. Should I wait for the fix to pyHS100 or submit a pull request?
@thomaskr I'm against having that fix in place, as it will break as soon as https://github.com/GadgetReactor/pyHS100/pull/107 gets released. I'm currently just waiting for input from someone who has a v2 & can confirm that the fix works also with homeassistant. If you can give it a try and report back, it would be nice.
@rytilahti I check the current dev of Home Assistant against
REQUIREMENTS = ['https://github.com/rytilahti/pyHS100/archive/emeter_for_new_firmwares.zip#pyHS100==0.3.0']
and everything seems to work fine with my HS110 (hardware version 2.0, firmware version 1.4.3). Home Assistant starts as expected, switching works, the metrics have reasonable values and are updated in intervals.
and everything seems to work fine with my HS110 (hardware version 2.0, firmware version 1.4.3). Home Assistant starts as expected, switching works, the metrics have reasonable values and are updated in intervals.
+1 Working for me too!
== My Smart Plug - HS110(AU) ==
OFF
Host/IP: REDACTED
LED state: True
On since: 2018-06-16 14:57:06.889013
== Generic information ==
Time: 2018-06-16 14:57:06
Hardware: 2.0
Software: 1.5.2 Build 171201 Rel.084625
MAC (rssi): REDACTED (-77)
Location: {'latitude': REDACTED, 'longitude': REDACTED}
== Emeter ==
Current state: {'voltage_mv': 247235, 'current_ma': 20, 'power_mw': 0, 'total_wh': 21}
Thanks for testing and reporting back :+1:
Ok guys, can confirm this is working. Received the fix in home assistant 0.72.0
https://github.com/home-assistant/home-assistant/releases/tag/0.72.0
Ich got this message after the Upgrade:
tplink: Error on device update!
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 248, in _async_add_entity
await entity.async_device_update(warning=False)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 320, in async_device_update
yield from self.hass.async_add_job(self.update)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.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 122, in update
emeter_statics = self.smartplug.get_emeter_daily()
File "/srv/homeassistant/lib/python3.5/site-packages/pyHS100/smartdevice.py", line 417, in get_emeter_daily
for entry in response['day_list']}
File "/srv/homeassistant/lib/python3.5/site-packages/pyHS100/smartdevice.py", line 417, in <dictcomp>
for entry in response['day_list']}
KeyError: 'energy'
@Ener-G It looks like you are using an older version (0.3.0) of pyHS100 that does not fit the REQUIREMENTS (0.3.1) in HA 0.72.
Can you check that…
Most helpful comment
I created simple fix for this until it will be fixed on Home Assistant side. This will allow new users to use TP-Link HS110 smart sockets:
https://gist.github.com/AdamStrojek/4d7dbdea48f6e9e3efd8ca52b21c0864