Kasa Token for Cloud Keeps Reverting to Null

I'm not sure how to fix this, but it seems like every few days, my hub will not control my kasa devices. The ones I have appear to only work with Kasa cloud. If I request a new token using the app, then the devices work. I did this a few days ago. But then today, I saw one of my lights was still on. I went into the Kasa app, and then token was null again. I requested a new one through the app, and now it works. I read somewhere you should turn off two-factor authentication, so I did.

Anyone know why I keep losing my token? If I could make these devices work without the cloud, that would be great, too? I have EP10, HS110, and HS210 devices, so if anyone knows how to make them work LAN only, that would be great.

Recommended to give them a static IP via DHCP lease on your router config (not required). Then go into each device and turn OFF cloud binding. I do not even have the integration app logged into the cloud at ALL. I do it all locally.

Also, if you had 2FA turned on for your account, if it was trying to renew the token and hitting the 2FA question that might be why it goes null. I don't use the Kasa cloud at all except the mobile app to pair new devices so not totally sure.

Assuming you are using this? @djgutheinz [RELEASE] TP-Link/Kasa Plug, Switch, and Bulb integration

1 Like

I do have static ips assigned in my eero router, so that’s good.

I noticed most devices had the “cloud binding” off already. But most of them had “use Kasa cloud for device control” enabled, so I disabled it on all the devices. The devices seem to still work through the hub, so I’m assuming it’s not using the cloud anymore?

When I look at the data section at the bottom of the device page, the ip and port still say CLOUD? Shouldn’t this now have a local ip instead? When I use the app and click the bottom to scan devices, no new ones come up, but then when I click next, they all list ip:port as CLOUD:CLOUD.

Couple of things you can check, in the Kasa mobile app they would say "Local only" under them if the cloud binding is off. I will add a screenshot from my phone in a minute. The app author has mentioned some newer models do not allow the cloud binding to be disabled anymore, thats why he made the cloud integration in the first place I think.

Also if you enable debugging for a device and send it a command, check the logs. Mine I can see it says sendLanCmd with the IP

Last thing you could try is to clear out the cloud config so that it cannot even log in anymore, thats what I did with mine so the only option for the Hubitat app is local control.

You might need to go into the utilities section and clear the DB then re-discover the devices to get rid of the "CLOUD" in the DB entry, not sure. But if those are some of the devices that only work on the cloud then it wont help.

Kasa app when cloud binding is off

If you are on the current version (and may of the previous versions), simply running the app, find devices, and exiting will update the IP address. If a local address is found, the address is updated (even if changed). If not, the address is NOT found, no change is made.

Refresh the browser page and see if the address changes. There is a delay in updating the IP address after exiting Save Preferences and the data section will require updating.

My recommendation to everyone is to get off the cloud.

  • Go to app and run standard (LAN) discovery.
  • Wait 2 minutes.
  • Open each device and check:
    • In data section, value deviceIP is an IP address and devicePort is a number (9999). If CLOUD, do not proceed. Keep cloud. Otherwise,
    • In the currentStates, check value of "connection".
  • if currentState connection is NOT LAN
    • set preference "use Kasa cloud for device control" to false
    • save Preferences.
  • the currentState connection should be LAN and the preference should be false.
  • Check device control

Over COVID and out of Hospital (gallbladder), so I will start being more involved.

1 Like

Thanks, with your suggestion I was able to get it to work. Documenting steps just in case anyone else needs to do this:

  1. First, I had to clear out the Kasa cloud token. I did this by going to the section where you enter your Kasa cloud credentials and then entered invalid credentials. By doing this and attempting to validate the credentials, it cleared the token out (token - null).
  2. Second, I had to remove each Kasa device. Tested it with one device first, then did the rest.
  3. Third, once I removed the device, I looked up the ip that I assigned in my router for each Kasa device. The scan would not find them, but I was able to use the option to manually enter the IP address of each Kasa device. When I did that, I was able to add each Kasa device, and it added it with the ip instead of saying CLOUD.

Now all my Kasa devices are controlled by local IP address/lan. No more cloud control. Yay!

Thanks so much for your help, much appreciated.

Unfortunately this approach did not work. See my earlier post - I had to remove each cloud device and re-add it using the assigned Ip. Scan would not work, but manually re-adding each device using ip worked.

So, are you running????? What are the IP addresses of your devices (all)?

Yes, everything appears to be working locally now. Here is a screenshot of what the ip addresses look like after adding each device using its ip:

I got the IPs from my ip reservations in my eero router. Scan feature in Kasa app did not work, but was able to manually add each device using its IP address.

From my eero router:

Whats your config set to at the top of the main page? You have devices on different subnets, etc... so not surprised the scan failed unless you have it set for a huge range.
Example:
image

1 Like

Here’s my config:

Hm well it should have found at least the 192.168.4 devices, but you should have it like this:
192.168.4, 192.168.5, 192.168.6

Could be something with your router firewall that somehow blocked the scan. Either way, since you got it working just know if you get more devices you will need to give them static IPs and probably always put them in manually.

1 Like

Okay thanks for the suggestion. I thought it would have found the .4 devices too. Not sure how the eero works. I’ll try modifying these settings the next time I add a new device and see if I can get the scan to work. Thanks!

1 Like

Thanks for the inputs. I will beef up installation instructions. I am also working on the cloud null token on auto update issue. Believe it is due to the recent updates to the Kasa Platform to add two-factor impacting the base method (even if you turn off two factor in the Kasa App.

But, first I will be issuing a trouble report. hub.localIP is suddenly returning an null value (causes quick crash in app). It is on the latest version only (I have to verify this also.) May be issuing error report today.

Update. Latest hub updated fixed issue with hub.localIP and the app will now run.

Dave

All users seeing this. If you have issues, the first thing to do is read the instruction/help available by the ? icon in the app and Kasa Help button in the devices. Major sections for problem resolution is "Troubleshooting".

I started getting 'token lost' issue about 2 weeks ago. I had recently updated the Kasa Integration code to the latest version (v6.6.0), don't know if that introduced the problem.

Every 24 hours the cloud token is getting set to null and it causes my cloud devices to not be controllable by hubitat, until i manually go in and get a new token.

I will try the steps above to assign static IP addresses and add those manually.

Update: Cannot get the HS103 switch to get added as a local device.
Here is what I tried.

  1. lose the KASA token by entering an invalid password and update.
  2. remove the HS103 device from hubitat
  3. open the Kasa integration app and scan the LAN for local devices, it finds one, add it
    Also tried manually adding the ipv4 address in "Added Devicse Segment Addresses (ex: 21, 22)"
  4. Summary shows Living room lamp 2 - HS103 : [CLOUD:CLOUD, -50, 6.6.0, Yes]

See the link: [RELEASE] TP-Link/Kasa Plug, Switch, and Bulb integration - #1851 by djgutheinz.

Recommend you go to the LAN communications from the cloud. See the Help text for descriptions of how.

Thanks, eagerly waiting for your fix.
In the mean time I commented out line 500, hope it helps. Will post an update after 24 hours.
update: It fixes the issue, kasa token from 2 days ago is still shown and devices work.

def getToken() {
logInfo("getToken ${userName}")
//app?.removeSetting("kasaToken")

I was also curious why only half of my kasa devices got an IP address, the same half showed up as "local control" in the Kasa app.
Apparently Kasa allows you to set up devices without creating (or logging in to) an account and those devices become local-only.

Update: even after setting up a device as 'guest' in the kasa app, and it now shows "local only" in the kasa app, the lan scan picks it up as "ip:cloud" :frowning: , changing the hubitat device setting about cloud binding does not change it.

My app searches for IP address for all devices and updates same. Some router configurations (multiple segments, port forwarding) are handled by manual user inputs. If the app does not find your device's IP it can never be LAN controlled. Note, there are a LOT of router configurations and some issues with different configurations.

As far as making devices local, my drivers have a setting to bind/unbind from the Kasa cloud (have had this for years). When unbound, they become local only.

Hi @djgutheinz, first of all, thanks for the great work on this app. I guess the best way for me to “hard test” this would be to unplug my fiber optic modem from my WiFi mesh, thus disabling internet, then see if my Kasa switches are still controllable from Hubitat via my LAN?