plasticrake / homebridge-tplink-smarthome

TP-Link Smarthome Plugin for Homebridge
MIT License
474 stars 70 forks source link

Smart Plug HS110 Consumption Characteristics are always 0 #57

Closed williamli closed 5 years ago

williamli commented 6 years ago

I have added a HS110 to my network. It is used to control my TV. In TP-Link's own app, it is shown to be drawing around 45w (current power).

img_6155 img_6156

However, inside Eve, its consumption level is always 0 (and it is saying that the outlet is not even in use)...

img_0310

williamli commented 6 years ago

tplink-smarthome-api getInfo [__IP___]

returns

emeter: 
  { realtime: 
     { voltage_mv: 219341,
       current_ma: 369,
       power_mw: 43536,
       total_wh: 884,
       err_code: 0 } },

so I guess the hardware and api can still communicate well.

lint2015 commented 6 years ago

I also have this problem. Any suggestions on a fix? Happy to help debug the issue.

williamli commented 6 years ago

i will see if i have time to work on it. the api that is used by this plugin seems to be returning all the necessary data correctly.

Sent from my iPhone

On 10 May 2018, at 23:34, lint2015 notifications@github.com wrote:

I also have this problem. Any suggestions on a fix? Happy to help debug the issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

lint2015 commented 6 years ago

Just curious what region plug you have? I suspect this may have something to do with it not displaying usage data.

kiwisapo commented 6 years ago

I likewise have this problem, the plug is an Australian model HS110(AU)

lint2015 commented 6 years ago

As is mine. I’m suspecting the Australian plug reports slightly differently because the TP-Link extension for Smartthings has this in the changelog:

Fixed Energy Monitor to accommodate HS110(AU) data formats.

I’ll take a compare the code when I have time and see if I can get it working.

kiwisapo commented 6 years ago

I've had a quick look and it seems that the latest firmware update changed from Voltage / Ampage etc to Millivolts / Milliamps, etc. I updated my plug.js to use the new emeter fields I can now pull back data (but is obviously out by a factor of 1000.)

williamli commented 6 years ago

@kiwisapo can't you divide everything by 1000? i still haven't had to time to look at it yet.

lint2015 commented 6 years ago

Spent some time on it this evening and modified both homekit.js and plug.js.

For plug.js, I added checks for each consumption characteristic, for example: if (emeterRealtime.variable == null) { callback(null, Math.round(emeterRealtime.variable_withUnits) / 1000 ); } else { callback(null, Math.round(emeterRealtime.variable_) ); }

For homekit.js, I modified some of the number formats from UINT16 or UINT32 to FLOAT based on information taken from this page.

Tested it on my devices and all the values are getting populated correctly except In Use. It also takes a while for values to update in the Eve app, even though the home bridge debug log is updating them fairly often. ¯_(ツ)_/¯

Not sure if the slow update is an inherent issue with this plugin but I guess I should just try and figure out how to make In Use work first.

lint2015 commented 6 years ago

Another update from my previous post, I've changed the code for the OutletInUse characteristic so that works as documented in the README.md for the HS110:

HS110 plug OutletInUse (based on energy monitoring)

My changes almost certainly break OutletInUse functionality for the HS100 and HS105 though it should be fairly easy to add an additional check whether the model is a HS110 or not.

One thing I'm concerned about is the original code sounds like it works as advertised for the author of this issue whereas I could not get it to work without my modifications (and I could not find any code that was even checking against the inUseThreshold value).

Perhaps @plasticrake could shed some light on it...

Anyway, I've shared my code changes here. I haven't put it on Github because I'm not well versed with the git business and because of the above-mentioned issues (admittedly my OutletInUse code is a bit of a hack at the moment), but if anyone wants to fix it up and commit it, please feel free.

My next goal when I have more time is to try implement the Eve Energy's usage history graph using fakegato-history as requested in this issue though that seems a lot more difficult and possibly requires a more thorough understanding of HomeKit, homebridge and this project than I currently have...

krmkrx commented 6 years ago

My HS110 is an EU model and I am encountering the exact same issue.

kiwisapo commented 6 years ago

Sorry for the delay in responding, been tied up at work.
@lint2015 I've had a look at your changes and they've certainly addressed all my issues. Well done. Hopefully, @plasticrake has time to review and merge. Nice work all, appreciate all your efforts.

lint2015 commented 6 years ago

@krmkrx try the modified code I posted above, it should fix it.

Anyway, just an update - I’ve found the OutletInUse code in tplinksmarthome-api and applied the fix for that part there. It’s much more elegant than the hack job I did earlier, so I've removed the hack job code from plug.js. I will post the code later when I’m at a computer.

I’ve also added a bunch of code to feed metrics to Graphite and have some pretty good usage graphs showing up in Grafana using that data. Here is what it looks like so far:

Energy Monitor via Graphite + Grafana Energy Monitor via Graphite + Grafana

This is in lieu of getting the usage history showing through fakegato-history, which I’d say is most of the way there, but I haven’t been able to get working yet. I've had some great help from the fakegato-history devs, so that shouldn't be far off either, I think.

lint2015 commented 6 years ago

I have forked both this project and tplink-smarthome-api to properly fix this issue. You can find my forks here. I've created pull requests to have these changes merged into the main projects.

The following file is changed in tplink-smarthome-api (to fix the inUseThreshold check): /src/plug/index.js

The following files are changed in homebridge-tplink-smarthome: /lib/homekit.js /lib/plug.js

I've also gotten the usage history to show up in the Eve app. I will post a branch with that feature soon.

ghost commented 6 years ago

Does the EU Version work now properly with the latest updates on that project?

I just want to avoid buying it when it is still under development. I appreciate the work of every developer who integrates product to HomeKit in any way, I am just a person who wants to use it directly when I have them and not waiting until it is fixed :D

Thanks in advance!

JimBeam1 commented 5 years ago

I am also looking for a version that supports the eu-version of the hs110. Is this possible to integrate?

JimBeam1 commented 5 years ago

Information for users of the EU Version: Hardware Revision 1 and Software 1.2.5 works fine. Hardware Revision 3 and Software 1.5.4 does not work for energy monitoring with this plugin.

Since the project "tplink-energy-monitor" is able to get the information needed for energy monitoring from both of the Hard- and Software-Versions, it should be possible to integrate this feature in this plugin, shouldn't it?

Scream4Life commented 5 years ago

An let me guess, downgrades are not possible?! I'm here with HS110 (EU) sw_ver: '1.5.4 Build 180815 Rel.121440', hw_ver: '2.0',...also seeing a couple of measure with tplink-smarthome-api { voltage_mv: 231333, current_ma: 89, power_mw: 6905, total_wh: 545, err_code: 0, current: 0.089, power: 6.905, total: 0.545, voltage: 231.333 } but I'm not able to see them in Eve. Thinking about returning the device :-(

JimBeam1 commented 5 years ago

@Scream4Life Since you also see the data in the tplink-smarthome-api-Application it should really be a small issue to fix it in the homebridge-project, I guess.

@plasticrake Could you please have a short look at it and tell us if it can be fixed or not?

lint2015 commented 5 years ago

@JimBeam1 I'm not familiar with this newer EU hardware and firmware, but...

@Scream4Life it looks like this new one returns power data in both the original format (current, voltage, power, etc) as well as the newer format (current_ma, voltage_mv, power_mw, etc) rather than one or the other.

At first glance, I'm not sure why that would cause this plugin to trip up, so it would require a closer look at where it's going wrong. What it currently is doing is checking if data is available from the plug in the original format. If not, it'll switch to the newer one. Since this variant is returning both, it should just use the original format and ignore the newer one.

Are there more detailed debug logs available?

plasticrake commented 5 years ago

Hi everybody, support for the newer plugs was added to the underlying API package tplink-smarkthome-api, however this plugin wasn't changed to use the new version until now. I still don't have a plug to test this myself, so please let me know if after upgrading to v3.11.1 if it doesn't work. If you're still having problems please open a new issue so I can see it.

Scream4Life commented 5 years ago

thank you obi-wan kenobi. you were my only hope. everything works fine now

JimBeam1 commented 5 years ago

I also shout a big thank you to all people working on the tplink-smarthome-projects here! It works for the newer EU-Plugs now.

Although the „in use“-indicator is not shown in Eve, its status is electable for making automation rules.

lint2015 commented 5 years ago

@JimBeam1 Huh, it used to be there but it seems like it's gone. Wonder if it's still there for proper Eve devices.

You should check out Hesperus as a companion app to Eve and Home. It displays everything that a HomeKit device sends, which makes it good for troubleshooting.

JimBeam1 commented 5 years ago

@lint2015 I recognized that for the ver. 1.0 devices the „in use“-indicator is also not shown anymore in Eve. But nobody will miss this „feature“, I guess. The most important feature is that this value (in use true or in use not true) is transmitted. And obviously this is the case. Automatation rules using this value do work.

I use the app Controller for making the HomeKit-rules.