SecKatie / ha-wyzeapi

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

Wyze Bulb/Switch Status does not change when there is no power to the bulb/switch #22

Closed war1000 closed 4 years ago

war1000 commented 4 years ago

This is great work! However, I noticed that when a bulb is offline due to no power or other reason, in HA the bulb shows up as On instead of unavailable. Is there any solution to this? Thanks!

SecKatie commented 4 years ago

I am not sure. I don't have any switches. I can do some research!

aeckard87 commented 4 years ago

I haven't setup my light-bulbs yet - though I have several switches, I'd be happy to test them out to see if it yields similar results.

aeckard87 commented 4 years ago

Confirmed switches are seeing the same issue and also setup one of my wyze bulbs and compared the "unavailable" status against my lifx bulb. It took lifx about 2 minutes to report unavailable. I have another switch brand (wemo) somewhere... But regardless I'll search around api's.

aeckard87 commented 4 years ago

Dug a little into the Wyze API /app/v2/home_page/get_object_list endpoint - it has a different param for determining if a device is offline:

conn_state - which nicely shows 0 (unavailable) for my test switch and lightbulb.

vs switch_state - which maintains last state if conn_state is 0 <- this would explain why we're seeing a "current state on" if the device loses connection while it was on. This is an intended wyze api setting.

Also updated to latest release v0.4.0 <- If I don't get around to updating the code today, this hopefully sets the "where to start" for anyone interested. Hoping I can get back to this later today though.

markrickert commented 4 years ago

I can confirm this behavior with the Wyze official app. It took at least 2 minutes after unplugging a wyze plug (or manually turning off a light at the switch) for the official app to mark it as "offline". I had to do a pull-to-refresh in the app to get it to show as offline.

We can probably set a polling interval to get the device status at 2 minutes and not run afoul of Wyze's server admins.

It looks like we're not polling the server after the initial startup script (can you confirm this @JoshuaMulliken ?). We should probably add this to the capability so that when someone accidentally turns off a light or a unplugs a switch manually it shows up as offline.

aeckard87 commented 4 years ago

Yea confirmed this as well @markrickert - was working on setting up grabbing connection state for lights and I was never getting 0 (unavailable), decided to check my wyze app and what do ya know... it is also showing still online despite having no power.

Switches do update in the wyze app, you have to be patient though. Roughly 5-10 min <- this is avail in the /v2/app/device/get_properties_list pid P5 == connection status to wyze server

SecKatie commented 4 years ago

I can confirm this behavior with the Wyze official app. It took at least 2 minutes after unplugging a wyze plug (or manually turning off a light at the switch) for the official app to mark it as "offline". I had to do a pull-to-refresh in the app to get it to show as offline.

We can probably set a polling interval to get the device status at 2 minutes and not run afoul of Wyze's server admins.

It looks like we're not polling the server after the initial startup script (can you confirm this @JoshuaMulliken ?). We should probably add this to the capability so that when someone accidentally turns off a light or a unplugs a switch manually it shows up as offline.

@markrickert @aeckard87 from what I understand home assistant will call the update function on some schedule. I am not sure what that timing is but we can definitely add a check to the update function that will set it to unavailable.

SecKatie commented 4 years ago

@all please see this commit for this feature in the lights: https://github.com/JoshuaMulliken/ha-wyzeapi/commit/1f4ac77d8c4bfef4c1643df8d3fcc3d956d366e9

war1000 commented 4 years ago

@JoshuaMulliken , will this update show up in HACS? or is it a manual update? Thanks!

SecKatie commented 4 years ago

@JoshuaMulliken , will this update show up in HACS? or is it a manual update? Thanks!

@war1000 it is in the master branch so you can switch to that on HACS but for right now it is not yet in a release. I want to get the same implemented for switches if this works. Watch for a beta!

SecKatie commented 4 years ago

Please try v0.4.1-beta.1 and let me know if it works for you!

markrickert commented 4 years ago

Damn, i'd love to help test but i'm out of town for a week. 1f4ac77 looks good though! Can't wait to try it out!

SecKatie commented 4 years ago

From my testing, this seems to work well so I will be making this into a full-fledged release

SecKatie commented 4 years ago

I will be closing this issue as it is fixed in v0.4.1