home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.58k stars 29.91k forks source link

TP-Link switches in a strip are somtimes appearing as unnamed_device #28912

Closed newAM closed 3 years ago

newAM commented 4 years ago

Home Assistant release with the issue: Home Assistant 0.102.0, docker image b39e9b4c8272fc7a5c5ca7c66ec9874733009f020da128b8496b6857d546a6e1

Edit: Updated to 0.102.1, still present.

Last working Home Assistant release (if known): Unknown

Operating environment (Hass.io/Docker/Windows/etc.): docker on Ubuntu 18.04.3 LTS

Integration: https://www.home-assistant.io/integrations/tplink

Description of problem: With a TP-Link smart strip (HS300) devices sometimes appear as unamed_device in the entities; this sometimes occurs with 2/6 of the plugs on the strip, but it very reliably occurs with the first outlet on the strip (called nuc in my case). image I am expecting this device to be called switch.nuc, but that rarely occurs.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

tplink:
  discovery: false
  strip:
    - host: 10.0.0.24

Traceback (if applicable): N/A

Additional information: If this is an issue with the pyHS100 library handling of the HS300 I can help out with development there, I have contributed to that library before.

probot-home-assistant[bot] commented 4 years ago

Hey there @rytilahti, mind taking a look at this issue as its been labeled with a integration (tplink) you are listed as a codeowner for? Thanks!

rytilahti commented 4 years ago

This is likely related to some inner-structural problems of the pyhs100 library (and the way the integration is done here), causing the device being flooded with requests which in turn makes it non-responsive. See https://github.com/home-assistant/home-assistant/issues/28590#issuecomment-552248178 for my comment on the issue, we are working on fixing this in the backend library.

trentjw commented 4 years ago

okay since you closed my issue for the un_named devices what is your answer for tplink not found at all on a full restart of the system and it takes multible restarts of the server for them to be found

dbrown8674 commented 4 years ago

https://github.com/home-assistant/home-assistant/pull/30719 is the fix,. It's just nor merged yet.

rytilahti commented 4 years ago

Yes, the proper way to fix it is to avoid dozens of separate calls to fetch the data. The PR is still WIP as is the new backend lib, but it's slowly getting there. What hinders the progress most is that this change involves some fundamental changes to how these devices are handled internally, and developing & testing those changes with no test device is slow as we are dependent on feedback from someone with a device who can try it out.

trentjw commented 4 years ago

Did not fix mine just did a reboot still get unnamed and still not able to find tp link devices until multi restarts of home assistant.

I am running 4 devices all have to be manually added, it will not find any TPlink devices on its own. none of the devices will be found until multiple restarts of home assistant then they behave as stated below

  1. HS200 been Rock solid sometime a little slow to get found but always does.
  2. KP200 been rock solid after I figured out to put it under strip.
  3. HS110 will only be found if it is off or gets cycled.
  4. HS300 typically shows up with 2 unnamed devices updated to your PR and thought it fixed this but now after a a restart it popped a unnamed device again

I have these switches in their own yaml file now but tried it in the configuration file and with my other switches file made no difference in location for the issues. also tried both true and false on the discovery makes no difference at all.

`discovery: False switch:

HA version 105.4

trentjw commented 4 years ago

found this in my log thought it might help don't know, this is from a full metal reboot

2020-02-19 20:41:56 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry TP-Link Smart Home for tplink Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 117, in _query_helper request=request, File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/protocol.py", line 47, in query sock = socket.create_connection((host, port), timeout) File "/usr/lib/python3.7/socket.py", line 727, in create_connection raise err File "/usr/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/config_entries.py", line 215, in async_setup hass, self File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tplink/init.py", line 82, in async_setup_entry static_devices = get_static_devices(config_data) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tplink/common.py", line 122, in get_static_devices for plug in SmartStrip(host).plugs.values(): File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartstrip.py", line 43, in init children = self.sys_info["children"] File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 186, in sys_info return defaultdict(lambda: None, self.get_sysinfo()) File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 196, in get_sysinfo return self._query_helper("system", "get_sysinfo") File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 120, in _query_helper raise SmartDeviceException('Communication error') from ex pyHS100.smartdevice.SmartDeviceException: Communication error

trentjw commented 4 years ago

this is from the first server restart

2020-02-19 20:41:56 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry TP-Link Smart Home for tplink Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 117, in _query_helper request=request, File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/protocol.py", line 47, in query sock = socket.create_connection((host, port), timeout) File "/usr/lib/python3.7/socket.py", line 727, in create_connection raise err File "/usr/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/config_entries.py", line 215, in async_setup hass, self File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tplink/init.py", line 82, in async_setup_entry static_devices = get_static_devices(config_data) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tplink/common.py", line 122, in get_static_devices for plug in SmartStrip(host).plugs.values(): File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartstrip.py", line 43, in init children = self.sys_info["children"] File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 186, in sys_info return defaultdict(lambda: None, self.get_sysinfo()) File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 196, in get_sysinfo return self._query_helper("system", "get_sysinfo") File "/srv/homeassistant/lib/python3.7/site-packages/pyHS100/smartdevice.py", line 120, in _query_helper raise SmartDeviceException('Communication error') from ex pyHS100.smartdevice.SmartDeviceException: Communication error

trentjw commented 4 years ago

second server restart get this error

2020-02-19 20:56:39 ERROR (MainThread) [homeassistant.components.switch] Setup of platform tplink is taking longer than 60 seconds. Startup will proceed without waiting any longer.

and starts to load of the devices

and gives me unnamed devices

trentjw commented 4 years ago

so apparently I may not know how to manually install your Fix into Home assistant, anybody want to walk me through this My setup is raspberry pi with a Venv install of Home assistant that way I can give feedback on what it does

trentjw commented 4 years ago

well I took and dumped the PR into my custom_components folder for giggles and currently the behavior is different it cannot hold the switches as they drop off and go unavailable typically 3 at a time then a few minutes goes by and they come back and another 3 drop off this in on the HS300 my other switches drop off and come back random as well all in real time

trentjw commented 4 years ago

this issue still persists using 108.4

trentjw commented 4 years ago

still persists 108.6

trentjw commented 4 years ago

problem still persists in 109.4

trentjw commented 4 years ago

I am guessing that this is abandoned as no feedback from rytilahti as to the status of this issue that been ongoing since Nov 20th and still persists in 109.6

rytilahti commented 4 years ago

Hi and sorry for the radio silence, there are so many different issues that I must have forgotten to answer here.

It's not abandoned, the WIP PR already has a fix for this issue, iirc, by doing only a single request for all multiplug devices (I got donated a KP303, which I have been using for development and testing). The PR itself is unfortunately now lagging behind several releases, and as there has been so many changes in-between, rebasing the PR is not so simple so I have been postponing that for now.

The last missing piece missing (which affects bulbs, mostly) is reducing the number of requests to one also on devices which have a power meter. I have a proof of concept that it's working as expected (dropping requests to 1 on both KP303, KL50, and HS110), but I need to find time to get it cleaned up. When that gets done, python-kasa should be in a releasable state and I'll finally rebase that PR.

trentjw commented 4 years ago

thanks for the update

trentjw commented 4 years ago

Don't forget about the KP300 it has 6 plugs on it

Hi and sorry for the radio silence, there are so many different issues that I must have forgotten to answer here.

It's not abandoned, the WIP PR already has a fix for this issue, iirc, by doing only a single request for all multiplug devices (I got donated a KP303, which I have been using for development and testing). The PR itself is unfortunately now lagging behind several releases, and as there has been so many changes in-between, rebasing the PR is not so simple so I have been postponing that for now.

The last missing piece missing (which affects bulbs, mostly) is reducing the number of requests to one also on devices which have a power meter. I have a proof of concept that it's working as expected (dropping requests to 1 on both KP303, KL50, and HS110), but I need to find time to get it cleaned up. When that gets done, python-kasa should be in a releasable state and I'll finally rebase that PR.

rytilahti commented 4 years ago

Don't forget about the KP300 it has 6 plugs on it

I just created a PR to the backend lib and updated the homeassistant PR, which reduces the number of I/O requests to one per device, which should get rid of many problems caused by separate I/O requests.

I suppose you mean HS300 (I couldn't find KP300 anywhere), but that should also work fine. The only thing that is yet to be fixed is the presentation of emeter information. If you have a device, it'd be great if you could test https://github.com/python-kasa/python-kasa/pull/59 with the console tool kasa. Is the information it's reporting correct? If not, the debug log kasa -d emeter would be useful to have, as the KP303 has no energy meter.

trentjw commented 4 years ago

Don't forget about the KP300 it has 6 plugs on it

I just created a PR to the backend lib and updated the homeassistant PR, which reduces the number of I/O requests to one per device, which should get rid of many problems caused by separate I/O requests.

I suppose you mean HS300 (I couldn't find KP300 anywhere), but that should also work fine. The only thing that is yet to be fixed is the presentation of emeter information. If you have a device, it'd be great if you could test python-kasa/python-kasa#59 with the console tool kasa. Is the information it's reporting correct? If not, the debug log kasa -d emeter would be useful to have, as the KP303 has no energy meter.

I would like to try it but never could get these to intergrate into my Home assistant not sure the steps involved to get home assistant to intergrate the PR and not use the released version

trentjw commented 4 years ago

upgraded to 0110.0 still giving unnamed devices, and still not sure the steps involved to implement a PR so if you want feedback on the HS300 with the PR I will need instruction on getting the PR installed

trentjw commented 4 years ago

I guess I won't worry about giving feedback on the HS300

rytilahti commented 4 years ago

As I have no clue how you have set up your system, I have no idea what would be the best way to test the PR itself. I'm simply running homeassistant under virtualenv, and I just check-out the PR and restart homeassistant.. Perhaps it is better to wait at least a bit until all the pieces are there in place and hope it's working fine :-)

Anyway, if you simply want to test out the cli tool to make sure that is working, you can do the following:

  1. Install git-extras if you don't already have it: https://github.com/tj/git-extras/blob/master/Installation.md
  2. clone the repository, change to the PR branch and install it:
    git clone https://github.com/python-kasa/python-kasa.git
    git pr 59
  3. install the repository into an isolated environment using poetry (or if you are already in virtualenv, that will be used automatically instead of creating a new one):
    poetry install
  4. activate the environment (or simply use poetry run kasa):
    poetry shell
    kasa
trentjw commented 4 years ago

I built this one on Venv on pi4

trentjw commented 4 years ago

running 111.3 and Still having unnamed devices show up, so I take it there will not be a fix for this issue

trentjw commented 4 years ago

running 111.4 and still having unnamed devices and nothing on any progress or updates wish there was another solution for these switches

Sidlinger commented 4 years ago

I purchased three HS300s for use with python-kasa, since everything else worked so well. But either I don't understand how to individually address the outlets from the command-line tool (e.g., this doesn't work, it just turns off the entire strip: (kasa) MacBookPro133:kasa sidlinger$ kasa --strip --host 10.0.1.24 --alias 'Lizard Light' off ) or else something is still broken.

Here is status from a KP303 and an HS300:

(kasa) MacBookPro133:kasa sidlinger$ kasa --host 10.0.1.24 No --strip nor --bulb nor --plug given, discovering.. == TP-LINK_Power Strip_4C1B - KP303(US) == Host: 10.0.1.24 Device state: OFF

== Plugs ==
* Socket 'KP303 Plug 1' state: OFF on_since: None
* Socket 'Lizard Light' state: OFF on_since: None
* Socket 'Den Light' state: OFF on_since: None

== Generic information ==
Time:         2020-06-28 12:57:01
Hardware:     1.0
Software:     1.0.9 Build 191031 Rel.095941
MAC (rssi):   B0:95:75:17:4C:1B (-31)
Location:     {'latitude': 351851, 'longitude': -1116667}

== Device specific information ==
LED state: True
Childs count: 3
On since: None

(kasa) MacBookPro133:kasa sidlinger$ kasa --host 10.0.1.243 No --strip nor --bulb nor --plug given, discovering.. == TP-LINK_Power Strip_8D63 - HS300(US) == Host: 10.0.1.243 Device state: ON

== Plugs ==
* Socket 'Bedroom Fan' state: OFF on_since: None
* Socket 'HS300 Plug 2' state: OFF on_since: None
* Socket 'HS300 Plug 3' state: OFF on_since: None
* Socket 'Z! Node Titan' state: ON on_since: 2020-06-25 13:46:02.467499
* Socket 'Z! Area-51m 180W' state: ON on_since: 2020-06-25 13:01:05.467625
* Socket 'Z! Area-51m 240W' state: ON on_since: 2020-06-25 13:01:05.467717

== Generic information ==
Time:         2020-06-28 12:57:12
Hardware:     1.0
Software:     1.0.19 Build 200224 Rel.090814
MAC (rssi):   B0:95:75:72:8D:63 (-52)
Location:     {'latitude': 351851, 'longitude': -1116667}

== Device specific information ==
LED state: True
Childs count: 6
On since: 2020-06-25 13:46:02.504059

== Current State ==
{'voltage_mv': 113966, 'current_ma': 4, 'power_mw': 0, 'total_wh': 66, 'err_code': 0}

(kasa) MacBookPro133:kasa sidlinger$

How can I help? I would pay part of the cost of an HS300 to be donated to the developer, or could arrange remote access to my network, or offer a bounty, or whatever.

Or hopefully I'm just doing it wrong and someone can point out the error of my ways.

P.S.: I am actually more interested in per-outlet emeter than I am in per-outlet control.

rytilahti commented 4 years ago

@Sidlinger try kasa --strip --host 10.0.1.24 off --name 'Lizard Light' (the --name or --index for indexed access is an option for the off command).

Regarding to per-outlet emeter, that is an unsolved issue at the moment (https://github.com/python-kasa/python-kasa/issues/64). Unfortunately, there is no emeter supporting power strip for 220V, so this will require someone with access to such device to do the development work. The open question is whether it is possible to query the state from several plugs at once by defining a list of device ids for the request, instead of sending 6 separate requests for each individual plug.

Remote access a device could be workable when I'll be able to find some free time. Otherwise, having a network trace (PCAP file with the communication between the app and the device) could also be useful.

Sidlinger commented 4 years ago

Thank you! You have made an overheated lizard very happy.

Sidlinger commented 4 years ago

I have an HS300 that is not yet in service and probably an extra Wi-Fi-capable Raspberry Pi somewhere, and I have routable IP addresses, so I will see if I can set up a complete environment for you: Internet-router-eth-Pi-wlan-hs300 that you can do with as you wish and with no danger of cooking a lizard. You can install anything you need on the Pi, I will put the latest Raspberry Pi OS on it.

Should I associate the HS300 with Wi-Fi in advance or simply plug it the virgin unit? I am guessing the latter since your software allows discovery and I guess you have a way to turn up the Pi's wlan and find the Kasa's SSID.

Thank you so much for responding to my post!

rytilahti commented 4 years ago

That would be awesome! Having it associated already would be great as I'm mostly interested in testing that everything works fine on an already configured setup. Feel free to contact me via homeassistant discord, or per e-mail with the details.

I did some rethinking on how to approach the per outlet emeter, and it is most likely not possible to request it from all the plugs at once. So the way to go forward will be to do those requests per plug basis, which will increase the requests per cycle to 7. However, as the HS300 support works (at least sometimes) with current 19 requests, I don't think this will be a problem. If that's the case, maybe the emeter information needs to be made configurable.

morninglite commented 4 years ago

Maybe relevant? tl;dr: stable version of HA without modifications works much better, in fact almost perfectly, on first gen Raspberry Pi as compared to a normal PC. Maybe many requests is ok, as long as there is some delay between them?

trentjw commented 4 years ago

My setup is a raspberry pi 4 2gig ram

On Thu, Jul 2, 2020, 10:50 AM morninglite notifications@github.com wrote:

Maybe relevant? https://github.com/home-assistant/core/issues/28912#issuecomment-651955108 tl;dr: stable version of HA without modifications works much better, in fact almost perfectly, on first gen Raspberry Pi as compared to a normal PC. Maybe many requests is ok, as long as there is some delay between them?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/28912#issuecomment-653116355, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC5HQ5P5RY3BSJTSCPFAEFDRZS3EFANCNFSM4JP4LJ3Q .

rytilahti commented 4 years ago

Yes, that was (and is still, obviously) one of the main drivers of the python-kasa port, besides adding new features and future-proofing the library. I wrote a more detailed answer in the linked issue on the throttling topic :-)

Sidlinger commented 4 years ago

Teemu R., the Raspberry Pi and HS300 are all set up and tested for you and with Internet access but I don't know how to privately send you the login details. I am unfamiliar with discord but I did create an account there named "Sidlinger." You mentioned "or per e-mail" but I don't know how to send you an e-mail based on github information.

Thank you!

-Bruce

rytilahti commented 4 years ago

Hi @Sidlinger, I couldn't locate you. Are you on the same server (linked here https://www.home-assistant.io/help/)? I'm over there with the same username as here, I can send you my SSH key so there's no need to transmit credentials.

Sidlinger commented 4 years ago

The little network I set up just for you is still running and ready, I just need to send you login details. On discord, which which I am totally unfamiliar, it asked for your four-digit username suffix, so I couldn’t get past that. And I didn’t want to make my e-mail publicly available on Github.

If you can give me exact instructions for the SSH key strategy, I can try that. Or if you know anyone on Facebook, I am very easy to find there, and I believe anyone could send me a Messenger message.

I never had this situation before, so please forgive my ignorance.

Thank you.

-Bruce

Hopefully we can get you on-line within just a few minutes, if you are still seeing messages today.

Sidlinger commented 4 years ago

And I am now in Home Assistant Community, same username as here. I just set that up a few minutes ago.

rytilahti commented 4 years ago

Oh, sorry for not being clear, I meant the homeassistant's discord server. Anyway, my four-digit identifier is #7435 so that should work even when not in the same "instance" as they call them.

The SSH strategy with keys goes something like this: https://www.raspberrypi-spy.co.uk/2019/02/setting-up-ssh-keys-on-the-raspberry-pi/ . But instead of you generating the keys, I'll give you my public key you can add to the authorized_keys file and let me know the IP address and the account name and it will just work without having to transmit passwords over the wire.

Sidlinger commented 4 years ago

Thank you! I just sent a friend request on discord and I will study the following and be ready for your public key! -Bruce

Setting up SSH Keys on the Raspberry Pi - Raspberry Pi Spy

mikesalz commented 4 years ago

Hi @rytilahti! I just purchased an HS300 and am experiencing the unnamed_device issue. Just wondering if this is an issue that you think will be resolved soon, or should I return this thing? :)

rytilahti commented 4 years ago

Hi @mikesalz, see my proposed plan here: https://github.com/home-assistant/core/pull/30719#issuecomment-682661817 – shortly put, I'm open for someone taking over the maintainership and merging whatever needs to be done to make HS300s (and other devices) function until we have proper solution in place.

ghvader commented 4 years ago

@mikesalz here is an ugly hack i put together using some bash scripts that still works perfectly for my 4 HS 300's. if you are interested in putting in the work to set it up it will work for you until a proper python fix can be developed. @rytilahti Here