ha-wyzeapi icon indicating copy to clipboard operation
ha-wyzeapi copied to clipboard

Add energy sensors to outdoor plug

Open brg468 opened this issue 1 year ago • 10 comments

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.

brg468 avatar Jan 19 '24 20:01 brg468

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.

JoeSchubert avatar Jan 19 '24 21:01 JoeSchubert

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

IMG_0452 IMG_1464

brg468 avatar Jan 19 '24 21:01 brg468

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.

brg468 avatar Jan 19 '24 21:01 brg468

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.

JoeSchubert avatar Jan 19 '24 21:01 JoeSchubert

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 avatar Jan 19 '24 22:01 brg468

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

Thanks for reviewing @JoeSchubert!

IMG_0454 IMG_9F4E060E4F15-1

brg468 avatar Jan 19 '24 22:01 brg468

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

The hourly bars, not the total.

JoeSchubert avatar Jan 19 '24 22:01 JoeSchubert

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.

brg468 avatar Jan 19 '24 22:01 brg468

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.

SecKatie avatar Feb 01 '24 18:02 SecKatie

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

brg468 avatar Feb 01 '24 22:02 brg468

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.

github-actions[bot] avatar Mar 18 '24 01:03 github-actions[bot]

Keep

brg468 avatar Mar 18 '24 01:03 brg468

@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.

SecKatie avatar Mar 19 '24 20:03 SecKatie

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

brg468 avatar Mar 19 '24 20:03 brg468

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

brg468 avatar Mar 21 '24 16:03 brg468