TP-LINK HS-110 Smart switch not connecting

I’ve a smart switch not connecting to home assistant …

The error message in the log :

16-12-28 16:45:24 INFO (MainThread) [homeassistant.loader] Loaded switch.tplink from homeassistant.components.switch.tplink
16-12-28 16:45:24 INFO (MainThread) [homeassistant.bootstrap] Setting up switch
16-12-28 16:45:24 INFO (MainThread) [homeassistant.components.switch] Setting up switch.tplink
16-12-28 16:45:24 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform tplink
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 150, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/components/switch/tplink.py", line 41, in setup_platform
    add_devices([SmartPlugSwitch(SmartPlug(host), name)], True)
  File "/Users/thesuperflycrib/.homeassistant/deps/pyHS100/pyHS100.py", line 73, in __init__
    self.initialize()
  File "/Users/thesuperflycrib/.homeassistant/deps/pyHS100/pyHS100.py", line 83, in initialize
    self.sys_info = self.get_sysinfo()
  File "/Users/thesuperflycrib/.homeassistant/deps/pyHS100/pyHS100.py", line 161, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "/Users/thesuperflycrib/.homeassistant/deps/pyHS100/pyHS100.py", line 100, in _query_helper
    request={target: {cmd: arg}}
  File "/Users/thesuperflycrib/.homeassistant/deps/pyHS100/pyHS100.py", line 560, in query
    sock.shutdown(socket.SHUT_RDWR)
OSError: [Errno 57] Socket is not connected

My configuration.yaml:

switch:
  - platform: tplink
    host: 192.168.0.154
    name: Kettle Power Switch

The ip address is correct, the plug is responding to pings, ports 80 and 9999 are open, 80 returns a content-type of ‘text/html’ with the body ‘…’ and 9999 will accept a telnet connection.

Hass version : 0.35.2
Python version: 3.5

Having a root through the source (not great with python, but I’ll try)

It looks like it could be when my mac is trying to listen for the response from the plug that it craps out.

do host and name need to be indented under the platform? And you may need to put the name in quotes. I’m not sure, I’m just guessing.

switch:
  - platform: tplink
      host: 192.168.0.154
      name: "Kettle Power Switch"

Googling that revealed this:

So looks like OSX behaves somehow differently, this needs to be fixed in pyHS100. Could you please file an issue to the upstream: GitHub - GadgetReactor/pyHS100: Python Library to control TPLink Switch (HS100 / HS110)

Fix works perfectly locally. Opened a pull request