Voice assistant skill - Wyze Smartbulb integration

I recently made a very rudimentary voice assistant for fun. For the first useful skill, I decided to add a Wyze smartbulb integration.

I currently work on Arizona time while living in Hawaii; this means I work from 6am-2pm year round (since neither state does daylight savings time). It's dark when I get up, and I've found over the years of remote work on different timezones that it is very helpful to have a smartbulb that turns on and gets brighter over a few minutes before my alarm goes off.

The downside is that now I have to control the bulb from the app, instead of being able to just reach over and flip the switch when I'm done reading for the night, or need to turn the lamp on in the middle of the night for some reason. First world problems, anyone?

I like Wyze because they have a developer console where you can generate an api key and secret to use. There is also a Python sdk that appears to be unofficial but tolerated by Wyze.

There's not that much exciting to say about the skill; the SDK is decently well-documented and I pretty much:

  1. Followed the example snippet from their docs to make sure I could list and access my devices

  2. Wrote a function to toggle a particular device on and off

  3. Wrote a function to take in a device nickname and find the corresponding device (I only have the one smartbulb, but why not make things extensible from the get go?) so that I can invoke the device that way with my voice

  4. Implemented some basic token management that checks for the existence of a token and uses it if present, or fetches and adds a new one if not, and instantiates the client from the token

  5. Refactored the power toggle function to take in a device and a command as well as the client, and match the command to a method (i.e. 'on' vs 'off') versus just reversing the state

  6. Added a function to list off all of the devices by nickname, with groundwork to filter by device type (not needed right now, as I only have the one device)

  7. Made it into a module, imported, and hooked it up to voice commands

In the near future I'll extend this skill to include more customization options like setting the brightness/temperature/color, etc, but for now I'm just enjoying turning my lamp on and off with my voice instead of the app.

Hours of coding to save seconds of app navigation. It's the programmer's way!