ANDREW LI

Effortlessly Control WiZ Smart Lights Using a Stream Deck

Introduction

As an app developer and smart home enthusiast, I’m always on the lookout for new ways to simplify and improve my daily life. For the past few years, I’ve been using WiZ smart lights to automate my bedtime and morning routines using iOS shortcuts.

The official way to control WiZ lights is through the WiZ app. The app supports iOS shortcuts on the iPhone, allowing you to control your lights without opening the app. With shortcuts, you can create a widget on your home screen that lets you turn your lights on and off with just a click of a button.

However, the biggest issue with this setup arises when you don’t have your phone nearby. Without your phone, you won’t be able to turn your lights on or off. That’s where the Stream Deck can step in to bridge the gap. With a Stream Deck, you can create a button to control your lights even when your phone isn’t within reach.

I struggled to find a guide on creating a Stream Deck button to control WiZ smart lights. So after figuring it all out, I’ve put together a step-by-step guide for you. In this guide, I’ll walk you through the process of setting up your Stream Deck to effortlessly control your WiZ smart lights, enhancing your smart home experience and making it even more seamless and enjoyable.

Prerequisites

1. WiZ smart lights set up and connected to your Wi-Fi network
2. Stream Deck device (any model) with the latest software installed
3. A computer with python installed

Step 1: Verify you have python installed

First, verify you have Python installed by opening the Terminal app and typing python --version or python3 --version. If the terminal outputs a version number for example “Python 3.9.6” then you have it installed.

If you don’t have Python installed, you can download it from the official Python website (https://www.python.org/downloads/mac-osx/).

Step 2: Install the pywizlight Package with pip

With python installed, you can now install the pywizlight package which will let us control our WiZ smart lights programatically.

In your terminal, type pip install pywizlight

Step 3: Gather your WiZ light ip addresses

To control your lights, we need to know the IP addresses of the Wi-Fi enabled lights found on the network. You can find the IP addresses of your lights using the WiZ app on iOS or by utilizing the discover subcommand in the pywizlight library.

Option 1: Using the Wiz app:

Open the WiZ App and navigate to the home tab. Click on the bulb you want to control then tap the gear button. Under basic tab tap the info button. Under details you will see the IP address of that bulb.

Option 2: Using the discover subcommand in pywizlight:

Before running the discover subcommand, it is necessary to know the broadcast address.

To identify the broadcast address open a terminal, type ifconfig. Your broadcast address is likely under en0 or en1. Look for line inet 192.168.1.100 netmask 0xffffff00 broadcast 192.168.1.255. For this example, the broadcast address can be found by locating the broadcast keyword, which is followed by the address itself (e.g., 192.168.1.255).

Now that we have obtained the broadcast address (e.g., 192.168.1.255), we can run the ‘discover’ command:

python3 -m pywizlight.cli discover

When prompted, simply paste the broadcast address.

Step 4: Develop a Python Script to Control Your WiZ Smart Lights

Now that you have pywizlight installed and gathered the IP addresses of your lights, you can create various scripts to control your smart lights.

You can create a script for turning lights on or off, adjust brightness, change colors, and even activate scenes. To further discover what is possible, take a look at the documentation page by visiting the official GitHub page at: https://github.com/sbidy/pywizlight.

Here are two simple scripts to get you started:

  1. Turn off lights

Copy the code in your editor and save it as turn-off-room.py.

import asyncio

from pywizlight import wizlight

async def main():
        bulb1 = wizlight("<your_bulb1_ip>")
        bulb2 = wizlight("<your_bulb2_ip>")
        bulb3 = wizlight("<your_bulb3_ip>")

        await asyncio.gather(bulb1.turn_off(), bulb2.turn_off(), bulb3.turn_off())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
  1. Turn on lights

Copy the code in your editor and save it as turn-on-room.py

import asyncio

from pywizlight import wizlight, PilotBuilder

async def main():
        bulb1 = wizlight("<your_bulb1_ip>")
        bulb2 = wizlight("<your_bulb2_ip>")
        bulb3 = wizlight("<your_bulb3_ip>")

        await asyncio.gather(
                bulb1.turn_off(),
                bulb2.turn_on(PilotBuilder(scene = 12, brightness = 128, colortemp = 4200)),
                bulb3.turn_on(PilotBuilder(scene = 12, brightness = 255, colortemp = 4200)),
        )

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

I prefer to keep my first bulb off because it causes glare on my screen, but for your script, you can modify it to have the bulb on.

Step 5: Setting up Stream Deck Buttons to Execute Your Python Scripts

With your python scripts ready, you can now add an open action to your Stream Deck buttons to run it.

Drag the open action onto a button on your Stream Deck, and a configuration window will appear. In this window, click choose and navigate to where you saved your python script in Step 4.

Repeat, previous steps if you have multiple scripts for example one for turning on and one for turning off.

Conclusion

Now, when you press the configured button on your Stream Deck, it will open and execute your Python script using the Python interpreter to control your WiZ lights.

© 2024. All rights reserved.