Package: wyze-sdk
Python Wyze SDKA modern Python client for controlling Wyze devices.Whether you're building a custom app, or integrating into a third-party service like Home Assistant, Wyze Developer Kit for Python allows you to leverage the flexibility of Python to get your project up and running as quickly as possible.ThePython Wyze SDKallows interaction with:wyze_sdk.client.bulbs: for controlling Wyze Bulb, Wyze Bulb Color, Wyze Bulb White, and Wyze Light Stripwyze_sdk.client.entry_sensors: for interacting with Wyze Entry Sensorwyze_sdk.client.cameras: for interacting with Wyze Cameraswyze_sdk.client.events: for managing Wyze alarm eventswyze_sdk.client.locks: for interacting with Wyze Lock and Wyze Lock Keypadwyze_sdk.client.motion_sensors: for interacting with Wyze Motion Sensorwyze_sdk.client.plugs: for controlling Wyze Plug and Wyze Plug Outdoorwyze_sdk.client.scales: for controlling Wyze Scalewyze_sdk.client.switches: for controlling Wyze Switchwyze_sdk.client.thermostats: for controlling Wyze Thermostat and Wyze Room Sensorwyze_sdk.client.vacuums: for controlling Wyze Robot VacuumDisclaimer: This repository is for non-destructive use only. WyzeLabs is a wonderful company providing excellent devices at a reasonable price. I ask that you do no harm and be civilized.As this repository is entirely reverse-engineered, it may break at any time. If it does, I will fix it to the best of my ability, but feel free to file a GitHub issue or patch yourself and submit a pull request.RequirementsThis library requires Python 3.8 and above. If you're unsure how to check what version of Python you're on, you can check it using the following:Note:You may need to usepython3before your commands to ensure you use the correct Python path. e.g.python3 --versionpython--version

--or--

python3--versionInstallationWe recommend usingPyPIto install the Wyze Developer Kit for Python.$pipinstallwyze-sdkBasic Usage of the Web ClientWyze does not provide a Web API that gives you the ability to build applications that interact with Wyze devices. This Development Kit is a reverse-engineered, module-based wrapper that makes interaction with that API possible. We have a few basic examples here with some of the more common uses but you are encouraged toexplore the full range of methodsavailable to you.AuthenticatingWhen performing user "authentication" with an email and password in the Wyze app, the credentials are exchanged for an access token and a refrsh token. These are long strings of the formlvtx.XXXX. When using this library, be aware that there are two method for handling authentiation:Obtaining the Token and Storing it for Later Use (Preferred)It is preferred that users first create an emptyClientobject and use thelogin()method to perform the token exchange.importosfromwyze_sdkimportClientresponse=Client().login(email=os.environ['WYZE_EMAIL'],password=os.environ['WYZE_PASSWORD'])print(f"access token:{response['access_token']}")print(f"refresh token:{response['refresh_token']}")The returned values can be stored on disk or as environment variables for use in subsequent calls.importosfromwyze_sdkimportClientclient=Client(token=os.environ['WYZE_ACCESS_TOKEN'])...(Deprecated) Automatically Authenticate Every New ClientThis method has been deprecated due to issues with authentication rate limiting. While it is still a perfectly usable approach for testing or performing infrequent client actions, itis not recommendedif you are scripting with this client library.importosfromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorclient=Client(email=os.environ['WYZE_EMAIL'],password=os.environ['WYZE_PASSWORD'])...Wyze API Key/ID SupportVisit the Wyze developer API portal to generate an API ID/KEY:https://developer-api-console.wyze.com/#/apikey/viewimportosfromwyze_sdkimportClientresponse=Client().login(email=os.environ['WYZE_EMAIL'],password=os.environ['WYZE_PASSWORD'],key_id=os.environ['WYZE_KEY_ID'],api_key=os.environ['WYZE_API_KEY'])...Multi-Factor Authentication (2FA) SupportIf your Wyze account has multi-factor authentication (2FA) enabled, you may be prompted for your 2FA code when authenticating via either supported method described above. If you wish to automate the MFA interaction, both theClientconstructor and thelogin()method accepttotp_keyas input. If the TOTP key is provided, the MFA prompt should not appear. Your TOTP key can be obtained during the Wyze 2FA setup process and is the same code that you would typically input into an authenticator app during 2FA setup.importosfromwyze_sdkimportClientresponse=Client().login(email=os.environ['WYZE_EMAIL'],password=os.environ['WYZE_PASSWORD'],totp_key=os.environ['WYZE_TOTP_KEY'])ORclient=Client(email=os.environ['WYZE_EMAIL'],password=os.environ['WYZE_PASSWORD'],totp_key=os.environ['WYZE_TOTP_KEY'])...Note: This does not work with SMS or email-based MFA.Listing devices in your Wyze accountOne 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.importosfromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorclient=Client(token=os.environ['WYZE_ACCESS_TOKEN'])try:response=client.devices_list()fordeviceinclient.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}")exceptWyzeApiErrorase:# You will get a WyzeApiError if the request failedprint(f"Got an error:{e}")Turning off a switchSome devices - like cameras, bulbs, and plugs - can be switched on and off. This is done with a simple command and even supports delayed actions via timers.importosfromdatetimeimporttimedeltafromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorclient=Client(token=os.environ['WYZE_ACCESS_TOKEN'])try:plug=client.plugs.info(device_mac='ABCDEF1234567890')print(f"power:{plug.is_on}")print(f"online:{plug.is_online}")ifplug.is_on:client.plugs.turn_off(device_mac=plug.mac,device_model=plug.product.model,after=timedelta(hours=3))else:client.plugs.turn_on(device_mac=plug.mac,device_model=plug.product.model)plug=client.plugs.info(device_mac=plug.mac)assertplug.is_onisTrueexceptWyzeApiErrorase:# You will get a WyzeApiError if the request failedprint(f"Got an error:{e}")Setting device propertiesEvery Wyze device has myriad properties and attributes that can be set in a common, intuitive way.importosfromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorclient=Client(token=os.environ['WYZE_ACCESS_TOKEN'])try:bulb=client.bulbs.info(device_mac='ABCDEF1234567890')print(f"power:{bulb.is_on}")print(f"online:{bulb.is_online}")print(f"brightness:{bulb.brightness}")print(f"temp:{bulb.color_temp}")print(f"color:{bulb.color}")client.bulbs.set_brightness(device_mac=bulb.mac,device_model=bulb.product.model,brightness=100)client.bulbs.set_color(device_mac=bulb.mac,device_model=bulb.product.model,color='ff00ff')client.bulbs.set_color_temp(device_mac=bulb.mac,device_model=bulb.product.model,color_temp=3800)bulb=client.bulbs.info(device_mac='ABCDEF1234567890')assertbulb.brightness==100assertbulb.color=='ff00ff'assertbulb.color_temp==3800client.bulbs.set_away_mode(device_mac=bulb.mac,device_model=bulb.product.model,away_mode=True)exceptWyzeApiErrorase:# You will get a WyzeApiError if the request failedprint(f"Got an error:{e}")Taking actions on devicesWant to unlock your lock, or tell your vacuum to clean certain rooms? Yeah, we got that.importosimportwyze_sdkfromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorclient=Client(token=os.environ['WYZE_ACCESS_TOKEN'])try:lock=client.locks.info(device_mac='YD.LO1.abcdefg0123456789abcdefg0123456789')iflockisnotNone:print(f"is open:{lock.is_open}")print(f"is locked:{lock.is_locked}")ifnotlock.is_locked:## let's try to figure out when it was unlockedforrecordinclient.locks.get_records(device_mac='YD.LO1.abcdefg0123456789abcdefg0123456789',since=datetime.now()-timedelta(hours=12)):print(f"lock record time:{record.time}")print(f"lock record type:{record.type}")print(f"lock record source:{record.details.source}")## lock upclient.locks.lock(device_mac='YD.LO1.abcdefg0123456789abcdefg0123456789')exceptWyzeApiErrorase:# You will get a WyzeApiError if the request failedprint(f"Got an error:{e}")try:vacuum=client.vacuums.info(device_mac='JA_RO2_ABCDEF123456')fromwyze_sdk.models.devicesimportVacuumMode# if our vacuum is out sweeping, let's find out where he is and tell him to go homeifvacuum.mode==VacuumMode.SWEEPING:print(f"current position:{vacuum.current_position}")client.vacuums.dock(device_mac='JA_RO2_ABCDEF123456',device_model=vacuum.product.model)# idle hands are the devil's playground - go clean the kitchenelifvacuum.mode==VacuumMode.IDLE:# want to see what's going on behind the scenes?wyze_sdk.set_stream_logger('wyze_sdk',level=logging.DEBUG)client.vacuums.sweep_rooms(device_mac='JA_RO2_ABCDEF123456',room_ids=[room.idforroominvacuum.current_map.roomsifroom.name=='Kitchen'])exceptWyzeApiErrorase:# You will get a WyzeApiError if the request failedprint(f"Got an error:{e}")