cbpowell / SenseLink

A tool to create virtual smart plugs and inform a Sense Home Energy Monitor about usage in your home
MIT License
60 stars 14 forks source link

Sense does not detect SenseLink #17

Closed poptix closed 2 years ago

poptix commented 2 years ago

My Sense does not detect SenseLink as-is. After debugging with espsense and some other tools I noticed the responses were different from SenseLink.

Making the following changes resolved the issue for me, SenseLink devices immediately appeared in Sense.

diff --git a/PlugInstance.py b/PlugInstance.py
index 336cc17..b1973e4 100644
--- a/PlugInstance.py
+++ b/PlugInstance.py
@@ -126,12 +126,12 @@ class PlugInstance:
                     "sw_ver": "1.2.5 Build 171206 Rel.085954",
                     "hw_ver": "1.0",
                     "type": "IOT.SMARTPLUGSWITCH",
-                    "model": "SenseLink",
+                    "model": "HS110(US)",
                     "mac": self.mac.upper(),
-                    "deviceId": self.device_id.upper(),
+                    "deviceId": self.mac.upper(),
                     "alias": self.alias,
                     "relay_state": 1,  # Assuming it's on, not sure it matters
-                    "on_time": time() - self.start_time,
+                    "updating": 0,
                 }
             }
         }
cbpowell commented 2 years ago

Interesting! I’ll take a look sometime next week probably. Back when I was originally testing it seemed like a lot of those fields had no effect, but maybe that’s changed?

What firmware version is your monitor on? Mostly out of curiosity, I don’t have a record of which have worked in the past or anything.

poptix commented 2 years ago

Firmware 1.35.3347-432344a0-master.

I did notice that the notifications now say "Sense noticed new TP-Link Kasa HS110s. They have been added to your devices." so perhaps they have a list of known/approved devices and ignore everything else.

mlebaugh commented 2 years ago

Can Confirm. Was setting this up for a friend, they weren't being detected. Changing the model to HS110(US) worked. Curiously, I added a device to my own setup and it was picked up (using the old model). So it seems only if you disable and re-enable, or setup new does the model matter.

cbpowell commented 2 years ago

@mlebaugh Thanks for the confirmation! Especially the check on new/re-enabled setups.

After a reset of my TPLink integration on Sense, I was able to get it to recognize a new static plug type with only the changes to the updating and deviceId fields. No change to the model field, and the popup in the Sense app still said (paraphrasing) "has recognized your TP-Link Kasa SenseLinks" (because it just pulls from the model field, it seems).

@poptix did you happen to try multiple combinations of those fields you changed?

I'm certainly not opposed to changing the model to match the HS110s to make it work, but I had tried to make it unique for SenseLink such that the Sense team could differentiate data if they ever wanted to (not that someone couldn't manually change it anyway).

poptix commented 2 years ago

I did not try multiple combinations but I'm willing to do so. I'll report back.

poptix commented 2 years ago

Well, I can't reproduce it now. Previously I had waited about 24 hours and rebooted the Sense but nothing would pop up until I made the changes I mentioned (after which they immediately appeared in Sense).

I'm unwilling to reset my Sense to factory defaults to see if it's some kind of 'first use' issue. Hopefully nobody else experiences this issue, or if they do, they find this thread.

mlebaugh commented 2 years ago

I'm fairly sure its a first use issue. The setup I was helping my friend with was brand new. It detected an HS110 normally. It wasn't until after i found this thread and changed only the model to HS110(US) were the senselink devices detected.

cbpowell commented 2 years ago

Well I don't mind resetting my TPLink integration so I gave it a shot. So far haven't been able to replicate it but it does seem like the monitor has some kind of cache of plugs? If you don't leave the integration disabled for long enough, it will immediately tell you it found new plugs, and populate previously-identified plugs in the device list - even if they're offline. I've temporarily blocked all my plugs from the network for testing, especially since all the ESPSense plugs do use the HS110 model*.

Going to give it a solid 30 minute disabled period and see if it flushes out the cache.

*I can't remember why I stuck with the HS110 model on ESPSense, considering I made ESPSense after SenseLink...

cbpowell commented 2 years ago

Well I wasn't able to reproduce, but who knows - I believe your findings on it being a first-use issue. I want it to work for first time users, so we'll go ahead and spoof the HS110 model! Thank you both @poptix and @mlebaugh for your help and testing!