SecKatie / ha-wyzeapi

Home Assistant Integration for Wyze devices.
733 stars 112 forks source link

Add energy sensors to outdoor plug #541

Closed brg468 closed 5 months ago

brg468 commented 7 months ago

Add total and daily energy sensors to the outdoor plug.

As requested here https://github.com/SecKatie/ha-wyzeapi/issues/425 forever ago and finally ready.

Upstream: https://github.com/SecKatie/wyzeapy/pull/79

A couple notes:

Power usage is combined from both outlets just like in the app. The power use is displayed on the device called Wyze Plug Outdoor. If you have more than one of these plugs they all show up named the same thing, but you can change that in device settings. Updates only happen 1-2 times an hour, so if you're comparing to the app there might be slight differences based on when HA pulled the latest usage. Because of above, the hourly data in the energy dashboard will not be accurate. It only looks at current and last hour’s usage. So when you first install it’ll be at 0 and count up from there. Add it to the energy dashboard to see day/month etc usage. Now also has a daily usage sensor that resets at midnight.

JoeSchubert commented 7 months ago

When I originally looked at this a long while back... Wyze's delay/random updates for the hourly usage made it basically impossible to update Home Assistant's hourly power usage, because it only lets you update the current usage for the current hour, when you update it. Meaning you'd get different numbers than Wyze showed.

Does this implementation not have that problem? If it does, implementing it will get just as many "this sensor is wrong" reports as requests to implement it.

brg468 commented 7 months ago

It’s darn close, within .01KWh, and that is probably rounding error.

IMG_0452 IMG_1464

brg468 commented 7 months ago

What I did was take current and last hour values at every update and calculate the change from the previous update, then add that to a running total restore sensor.

JoeSchubert commented 7 months ago

It’s darn close, within .01KWh, and that is probably rounding error.

I think you're just taking about the daily total. The code looks like it added the hourly sensor as well from my quick scan over the code... That's what I was saying would end up incorrect.

brg468 commented 7 months ago

There is no hourly sensor. That wouldn’t work for the reasons you said. Just a total (never resetting) and a daily sensor that resets at midnight.

brg468 commented 7 months ago

One more example of what’s actually shown in HA:

Thanks for reviewing @JoeSchubert!

IMG_0454 IMG_9F4E060E4F15-1

JoeSchubert commented 7 months ago

Right... That bottom image is what I was talking about that all always be incorrect.

The hourly bars, not the total.

brg468 commented 7 months ago

Yea it will, I guess I’m hoping that since I made the sensors daily and total that the understanding will be that’s the accuracy we’re going for. The only place to see hourly will be the energy dashboard.

SecKatie commented 6 months ago

It seems like we might need some more checks. I can see multiple places where we could have bad data in the json and it could cause issues.

brg468 commented 6 months ago

@SecKatie can you point me in the direction of what needs changed?

github-actions[bot] commented 5 months ago

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

brg468 commented 5 months ago

Keep

SecKatie commented 5 months ago

@SecKatie can you point me in the direction of what needs changed?

I added review comments that point to a couple places. Basically I am wondering what will happen if the indexes don't exist. They change random things like that so often I am concerned that this will break in a bad way.

brg468 commented 5 months ago

Sorry about that, for some reason I cant see any of those review comments..

brg468 commented 5 months ago

I have no idea why but as soon as you closed this your review comments finally showed up! 😆