(The photo is from the product introduction page of SoftBank Selection)
On April 24, 2020, SoftBank C & S released the smart light "Yeelight" for the domestic market in Japan. This smart light has a function called "LAN Control" (described later), and I've been interested in it for a long time, but since it was released in Japan, I bought it immediately and tried to control it from Python. Of course, the skill is perfect.
"Yeelight" (Japanese official page) is a brand name of smart light and is a product of "Xiaomi" (Xiaomi, Xiaomi), which is famous for smartphones and home appliances. There are various products such as light bulb type, tape type, and lantern type, but here we will talk about the light bulb type smart light.
The model "YLDP13YL" purchased this time has Wi-Fi connection, 24-bit color (about 16.77 million colors), smart speaker support (Google Home, Alexa, Apple HomeKit), and features similar to general light bulb type smart lights. However, it has a characteristic function called "LAN Control".
"LAN Control" will be described later, but for other specifications of Yeelight, see Product Introduction Page of SoftBank Selection. Please refer.
In addition to the above SoftBank selection, you can purchase from Amazon.co.jp, Yodobashi.com, etc.
Site th> | model th> | 1 th> | Set of 2 th> | Set of 4 th> |
---|---|---|---|---|
Amazon.co.jp | Multicolor th> | 3,300 yen td> | 5,940 yen td> | 11,880 yen td> |
Light bulb color (dimming only) th> | ¥ 2,200 td> | 3,960 yen td> | 7,920 yen td> | |
Yodobashi.com th> | Multicolor th> | ¥ 3,630 td> | - | - |
As the name suggests, Yeelight's characteristic function "LAN Control" is a function for controlling lights via a LAN (Local Area Network), and its API is open to the public. Since it is completed within the LAN without going through the cloud, control with less delay can be performed. In addition, since the API is open to the public, you can freely control it from your own application.
See Yeelight's Developer Page (https://www.yeelight.com/en_US/developer) for more information. (The page loads very slowly, so please be patient)
yeelight
packageWithout having to read the API specification above, Python has a volunteer yeelight package that you can easily control. At the time of writing this article, it was 0.5.1
.
mac$ pip install yeelight==0.5.1
The API is broadly divided into light discovery and control. Let's take a look at each.
After setting up Yeelight and enabling "LAN Control", you can detect the light with yeelight.discover_bulbs ()
.
Since it uses UDP multicast internally, it must be implemented within the reach of it. (In general, I think it's okay if you are connected to the same Wi-Fi network)
A specific example is shown below.
mac$ python
Python 3.7.0 (default, Jun 28 2018, 07:39:16)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yeelight
>>> yeelight.discover_bulbs()
[{'ip': '192.168.1.81', 'port': 55443, 'capabilities': {'id': '0x0000000012429e65', 'model': 'color4', 'fw_ver': '27', 'support': 'get_prop set_default set_power toggle set_bright set_scene cron_add cron_get cron_del start_cf stop_cf set_ct_abx adjust_ct set_name set_adjust adjust_bright adjust_color set_rgb set_hsv set_music', 'power': 'on', 'bright': '100', 'color_mode': '2', 'ct': '2000', 'rgb': '9109504', 'hue': '0', 'sat': '100', 'name': ''}}]
If you already know the IP address of the write, this step is not necessary. You can also check the IP address of the light from the Yeelight app.
If you know the IP address of the write, you can control the write. There is no authentication. Please be careful about the network configuration.
A specific example is shown below. This is an example of lighting ON, OFF, ON / OFF switching, brightness setting, color setting by RGB value, color setting by HSV value, color setting by color temperature, and property acquisition in order from the top.
mac$ python
Python 3.7.0 (default, Jun 28 2018, 07:39:16)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yeelight
>>> bulb = yeelight.Bulb("192.168.1.81")
>>> bulb.turn_on()
'ok'
>>> bulb.turn_off()
'ok'
>>> bulb.toggle()
'ok'
>>> bulb.set_brightness(50)
'ok'
>>> bulb.set_rgb(255, 0, 0)
'ok'
>>> bulb.set_hsv(320, 100, 50)
'ok'
>>> bulb.set_color_temp(3000)
'ok'
>>> bulb.get_properties()
{'power': 'on', 'bright': '100', 'ct': '3000', 'rgb': '8432127', 'hue': '221', 'sat': '49', 'color_mode': '2', 'flowing': '0', 'delayoff': '0', 'music_on': '0', 'name': None, 'bg_power': None, 'bg_flowing': None, 'bg_ct': None, 'bg_bright': None, 'bg_hue': None, 'bg_sat': None, 'bg_rgb': None, 'nl_br': None, 'active_mode': None, 'current_brightness': '100'}
There are many other functions, so please refer to the API specification for developers and the API reference of the yeelight
package.
Then have a good house hack!
Recommended Posts