shauntarves / wyze-sdk

A modern Python client for controlling Wyze devices.
The Unlicense
297 stars 49 forks source link

Bulbs are only ever returning is_on == False #126

Open stancubed opened 1 year ago

stancubed commented 1 year ago

I've written a function to iterate through a list of bulbs and get their is_on status, but no matter the state of the bulbs, it's returning False. Snippet:

api_response = client.bulbs.list()
    for bulb in api_response:
        if "Lab" in bulb.nickname:
            print(f"{bulb.nickname} ({bulb.product.model}) is set to status {bulb.is_on}")

Output:

Lab 2 (WLPA19C) is set to status False
Lab 5 (WLPA19C) is set to status False
Lab 4 (WLPA19C) is set to status False
Lab 3 (WLPA19C) is set to status False
Lab 6 (WLPA19C) is set to status False
Lab 7 (WLPA19C) is set to status False
Lab 8 (WLPA19C) is set to status False
Lab 1 (WLPA19C) is set to status False

Am I missing a step here or expecting something different from the intention?

Thanks for any help!

robughblah commented 1 year ago

Yeah, I was trying to do something similar with cameras and get the same result. I have 8 cameras, below is showing two with 'road north' unplugged and 'cedar' functioning.

cameraList = client.devices_list()
for device in cameraList:
    print(f"\nCamera: {device.nickname}")        
    print(f"product model: {device.product.model}")
    print(f"mac: {device.mac}")
    print(f"is_on: {device.is_on}")
    print(f"is_online: {device.is_online}")

Output: Camera: road north product model: WYZE_CAKP2JFUS mac: 7C78B29C07FE is_on: False is_online: False is_co_alarm: Property co_alarm_switch: False [API value: 0]

Camera: cedar product model: WYZE_CAKP2JFUS mac: 7C78B29C0756 is_on: False is_online: True is_co_alarm: Property co_alarm_switch: False [API value: 0]

Oddly is_online appears to be accurate, is_on always returns false and is_co_alarm returns oddly. I emailed Shaun and he replied with a snippet that returns a more accurate is_on and is_co_alarm result when the key is 'mac':

for device in cameraList:
    camera = client.cameras.info(device_mac=device.mac)
    if camera is not None:
        print(f"\nCamera: {device.nickname}")
        print(f"is_on: {camera.is_on}")
        print(f"is_online: {camera.is_online}")
        print(f"co alarm: {camera.is_co_alarm}")
    else:
        print(f"This MAC returns none")

Output: Camera: road north is_on: True is_online: False push switch: 1 co alarm: False

Camera: cedar is_on: False is_online: True push switch: 1 co alarm: False

This is somewhat at odds with the product page example on https://github.com/shauntarves/wyze-sdk https://github.com/shauntarves/wyze-sdk :

Listing devices in your Wyze account

One of the most common use-cases is querying device state from Wyze. If you want to access devices you own, or devices shared to you, this method will do both.

import os from wyze_sdk import Client from wyze_sdk.errors import WyzeApiError

client = Client(token=os.environ['WYZE_ACCESS_TOKEN'])

try: response = client.devices_list() for device in client.devices_list(): print(f"mac: {device.mac}") print(f"nickname: {device.nickname}") print(f"is_online: {device.is_online}") print(f"product model: {device.product.model}") except WyzeApiError as e:

You will get a WyzeApiError if the request failed

print(f"Got an error: {e}")

Also be aware that the values returned only reflect a snapshot of reality. 1) if you reboot your router and new dhcp IP are assigned to cameras that have not been power cycled, the api calls still return the old dhcp IP for each camera. This persists until the camera is power cycled. Bizarrely the Wyze app still streams video for affected cameras (and still reports the old IP under Settings->Device Info) but pinging the old IP fails. I can see the new IP assignment from my router and ping it successfully.

2) the is_on and is_online states for cameras do not properly reflect true conditions for different sequences of setting the camera OFF in the app, restarting the camera, powering the camera off.

Rob

On Jan 22, 2023, at 00:47, stancubed @.***> wrote:

I've written a function to iterate through a list of bulbs and get their is_on status, but no matter the state of the bulbs, it's returning False. Snippet:

api_response = client.bulbs.list() for bulb in api_response: if "Lab" in bulb.nickname: print(f"{bulb.nickname} ({bulb.product.model}) is set to status {bulb.is_on}") Output:

Lab 2 (WLPA19C) is set to status False Lab 5 (WLPA19C) is set to status False Lab 4 (WLPA19C) is set to status False Lab 3 (WLPA19C) is set to status False Lab 6 (WLPA19C) is set to status False Lab 7 (WLPA19C) is set to status False Lab 8 (WLPA19C) is set to status False Lab 1 (WLPA19C) is set to status False Am I missing a step here or expecting something different from the intention?

Thanks for any help!

— Reply to this email directly, view it on GitHub https://github.com/shauntarves/wyze-sdk/issues/126, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMXAXKIHLBIIBSKG5ZAD23WTTCXXANCNFSM6AAAAAAUCZQCZI. You are receiving this because you are subscribed to this thread.

shauntarves commented 1 year ago

@stancubed @robughblah ,

This one is a bit of a head-scratcher for me. The OLD bulb (first version, not color) used a device parameter called switch_state to report whether it was on/off. Newer bulbs, particularly the mesh color, had switched to the standard prop-based approach and used the P3 prop. It looks like at some point, that changed, but I can't figure out when/where. Maybe they standardized bulb logic/properties across all the models?

Anyway, please check out https://github.com/shauntarves/wyze-sdk/tree/126-bulbs-are-only-ever-returning-is_on-%3D%3D-false and see if this resolves your issue. I only have a color bulb, and I would really like to regression test this against the second-gen white bulb and the light strips. @anthonystabile would you be able to try this version against your light strips to see if bulb.is_on reports correctly?

shauntarves commented 1 year ago

@JohnMTorgerson @JRGould - could use your help on this one too if you have bulbs you can try

JRGould commented 1 year ago

I'm seeing the bulb power state coming back in the P3 prop on my HL_HWB2 bulbs - so if I change switch_state on this line: https://github.com/shauntarves/wyze-sdk/blob/d4663cd6a36f94de6ee550397497980f33415dce/wyze_sdk/models/devices/lights.py#L150 to P3, then bulb.is_on will accurately report the power state of the bulb.

here are the raw JSON responses for that bulb when it's on / off

# bulb on
{'ts': 1675802934728, 'code': '1', 'msg': '', 'data': {'property_list': [
      {'pid': 'P1', 'value': '1', 'ts': 0
      },
      {'pid': 'P1501', 'value': '1', 'ts': 1675751437426
      },
      {'pid': 'P1502', 'value': '2700', 'ts': 1671755346238
      },
      {'pid': 'P1503', 'value': '', 'ts': 0
      },
      {'pid': 'P1504', 'value': '-60', 'ts': 1675800512033
      },
      {'pid': 'P1505', 'value': '0', 'ts': 0
      },
      {'pid': 'P1506', 'value': '0', 'ts': 1664483890034
      },
      {'pid': 'P1509', 'value': '0', 'ts': 1664483890034
      },
      {'pid': 'P1511', 'value': '6918ab128e15486d', 'ts': 1664483906949
      },
      {'pid': 'P1513', 'value': '0', 'ts': 0
      },
      {'pid': 'P1514', 'value': '0', 'ts': 0
      },
      {'pid': 'P1527', 'value': '', 'ts': 0
      },
      {'pid': 'P1528', 'value': '0', 'ts': 1671755346238
      },
      {'pid': 'P1529', 'value': '1', 'ts': 1664483890034
      },
      {'pid': 'P1530', 'value': '1', 'ts': 1664483890079
      },
      {'pid': 'P1531', 'value': '1', 'ts': 1664483890079
      },
      {'pid': 'P3', 'value': '1', 'ts': 1675800512033
      },
      {'pid': 'P5', 'value': '1', 'ts': 1675303966709
      },
      {'pid': 'P7', 'value': '0', 'ts': 0
      }
    ]
  }
}

# bulb off
{'ts': 1675803097248, 'code': '1', 'msg': '', 'data': {'property_list': [
      {'pid': 'P1', 'value': '1', 'ts': 0
      },
      {'pid': 'P1501', 'value': '1', 'ts': 1675751437426
      },
      {'pid': 'P1502', 'value': '2700', 'ts': 1671755346238
      },
      {'pid': 'P1503', 'value': '', 'ts': 0
      },
      {'pid': 'P1504', 'value': '-60', 'ts': 1675800512033
      },
      {'pid': 'P1505', 'value': '0', 'ts': 0
      },
      {'pid': 'P1506', 'value': '0', 'ts': 1664483890034
      },
      {'pid': 'P1509', 'value': '0', 'ts': 1664483890034
      },
      {'pid': 'P1511', 'value': '6918ab128e15486d', 'ts': 1664483906949
      },
      {'pid': 'P1513', 'value': '0', 'ts': 0
      },
      {'pid': 'P1514', 'value': '0', 'ts': 0
      },
      {'pid': 'P1527', 'value': '', 'ts': 0
      },
      {'pid': 'P1528', 'value': '0', 'ts': 1671755346238
      },
      {'pid': 'P1529', 'value': '1', 'ts': 1664483890034
      },
      {'pid': 'P1530', 'value': '1', 'ts': 1664483890079
      },
      {'pid': 'P1531', 'value': '1', 'ts': 1664483890079
      },
      {'pid': 'P3', 'value': '0', 'ts': 1675803088534
      },
      {'pid': 'P5', 'value': '1', 'ts': 1675303966709
      },
      {'pid': 'P7', 'value': '0', 'ts': 0
      }
    ]
  }
}
shauntarves commented 1 year ago

Yeah, that's what I was assuming we'd see. I need some confirmation on the other bulb types though so I can put in more specialized logic.