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
73.23k stars 30.58k forks source link

TP-Link Kasa hosts set to null for migrated switches that can't be discovered (different VLAN) #57276

Closed TomBrien closed 3 years ago

TomBrien commented 3 years ago

The problem

After 2021.10.0 my TP Link plugs are all unavailable with an error in logs and Integration UI of:

Config entry 'HS100-3' for tplink integration not ready yet: Unable to connect to the device: None; Retrying in background

What is version of Home Assistant Core has the issue?

core-2021.10.0

What was the last working version of Home Assistant Core?

core-2021.9.7

What type of installation are you running?

Home Assistant OS

Integration causing the issue

tplink

Link to integration documentation on our website

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

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Example config entry:

{
                "entry_id": "fe482d52e8e2eefc81638da164faa4e0",
                "version": 1,
                "domain": "tplink",
                "title": "TP-LINK_Smart Plug_B17B",
                "data": {
                    "host": null
                },
                "options": {},
                "pref_disable_new_entities": false,
                "pref_disable_polling": false,
                "source": "migration",
                "unique_id": "50:c7:bf:ef:b1:7b",
                "disabled_by": null
            }

Additional information

No response

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

Hey there @rytilahti, @thegardenmonkey, mind taking a look at this issue as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


tplink documentation tplink source (message by IssueLinks)

TomBrien commented 3 years ago

I was able to fix this by manually adding the hosts to the config entries but obviously this isn't ideal. Presumably if I were to delete and setup again it would be ok.

I should mention my switches are on a separate VLAN and blocked from internet so presumably wouldn't be found in discovery

TomBrien commented 3 years ago

Potentially related to #57215

TomBrien commented 3 years ago

Looks like route cause is when migrating legacy config entries we only try and pull the host from hosts_by_mac which is the discovered hosts. L54 below will give None in this case

https://github.com/home-assistant/core/blob/32889dbfbe2031aea3bf60b453200a88abf1b1c4/homeassistant/components/tplink/migration.py#L32-L59

bdraco commented 3 years ago

The old integration didn't store the ip address so if we can't find it by discovery at least once we cannot connect to it.

Once it is discovered, the ip address should get updated and the device will recover. If its just a case of it didn't respond to discovery the first time #57221 will fix it.

If it will never respond to discovery, it needs to be removed and added manually.

If you had them configured via yaml and it didn't import the ip address, then we have a bug

jfischerlaunch commented 3 years ago

I just updated today to Home Assistant 2021.10.0 and now all my TPLink Kasa swtches are unavailable. I had them set up before the upgrade. Mine are not on a separate VLAN, though unlike above. I do see this in the log. I've done the basic troubleshooting, such as click the reset button on the switch and reboot the TPLink integration, but the switches are still not connected.

Logger: homeassistant.components.tplink.coordinator
Source: helpers/update_coordinator.py:219
Integration: TP-Link Kasa Smart (documentation, issues)
First occurred: 3:26:37 PM (66 occurrences)
Last logged: 10:34:38 PM

Error fetching 192.168.68.62 data: Unable to connect to the device: 192.168.68.62
Error fetching 192.168.68.65 data: Unable to connect to the device: 192.168.68.65
Error fetching 192.168.68.159 data: Unable to connect to the device: 192.168.68.159
Error fetching 192.168.68.157 data: Unable to connect to the device: 192.168.68.157
Error fetching 192.168.68.158 data: Unable to connect to the device: 192.168.68.158

Any additional information I can provide?

bdraco commented 3 years ago

Looks like you have IP address. Would you please open a new issue, as it's a different problem, And whatever fix happens from this issue will not solve it.

Please include specific model number in the new case

Thanks 👍

jfischerlaunch commented 3 years ago

Thank you!

TomBrien commented 3 years ago

This is the old config entry from backup, I have the hosts, is it worth in the migration running through the list and trying to connect to each host and get it's mac before migrating:

            {
                "entry_id": "3b72d6d536bb4d048554151061d02537",
                "version": 1,
                "domain": "tplink",
                "title": "TP-Link Smart Home",
                "data": {
                    "switch": [
                        {
                            "host": "192.168.66.21"
                        },
                        {
                            "host": "192.168.66.10"
                        },
                        {
                            "host": "192.168.66.11"
                        },
                        {
                            "host": "192.168.66.20"
                        },
                        {
                            "host": "192.168.66.9"
                        },
                        {
                            "host": "192.168.66.12"
                        },
                        {
                            "host": "192.168.66.13"
                        },
                        {
                            "host": "192.168.66.14"
                        }
                    ],
                    "discovery": true,
                    "light": [],
                    "dimmer": [],
                    "strip": []
                },
                "options": {},
                "pref_disable_new_entities": false,
                "pref_disable_polling": false,
                "source": "import",
                "unique_id": null,
                "disabled_by": null
            },
bdraco commented 3 years ago

We already do that if it's still in the yaml. I take it the yaml was deleted ?

TomBrien commented 3 years ago

Yeah when it migrated to the now legacy config flow I commented out the yaml

bdraco commented 3 years ago

Can you give #57308 a shot?

TomBrien commented 3 years ago

Sure I'll give it a go today

TomBrien commented 3 years ago

Looks good to me. What I did:

All switches seem to have been correctly migrated now