0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pythonからYeelightを操作する。

Posted at

#環境
Python version:3.9.7
OS: windows 10.0
Anaconda:conda 4.11.0

#実装したかった、やりたかったこと
・pythonを使ってyeelight を操作する。

#今後すること
・時間や家の温度によって自動的に動作するようにしたい。
 温度のクライテリアを決めて、onにするとか。

#セットアップ
##1.yeelightパッケージのinstall
pythonにyeelightのパッケージが公開されています。下記でinstallします。

pip install yeelight

intall後、下記を実行すると、yeelightのipアドレスが取得できます。

import yeelight
yeelight.discover_bulbs()

##2.code
別ファイルでclassの設定をしてみたかったので、light_action.pyを読み込んで操作るようにした。

yeelight.py
import time
#user module
import light_action

#Set up 
ye_address = "IPアドレス"
light_action_class = light_action.light_up_rgb_color() #instance
light_action_class.address_set(ye_address) # light address set

#Turn on 
light_action_class.light_turn_on()

light_action_class.rgb_white()
time.sleep(3)
light_action_class.rgb_olive()
time.sleep(3)
light_action_class.rgb_yellow()
time.sleep(3)
light_action_class.rgb_fuchsia()
time.sleep(3)
light_action_class.rgb_silver()
time.sleep(3)
light_action_class.rgb_red()
time.sleep(3)
light_action_class.rgb_gray()
time.sleep(3)
light_action_class.rgb_blue()
time.sleep(3)
light_action_class.rgb_green()
time.sleep(3)
light_action_class.rgb_purple()
time.sleep(3)
light_action_class.rgb_navy()
time.sleep(3)
light_action_class.rgb_teal()
time.sleep(3)
light_action_class.rgb_maroon()
time.sleep(3)

#Turn off 
light_action_class.light_turn_off()

yeelightの操作は、別ファイルでまとめてます。

light_action.py
import yeelight

class light_up_rgb_color :
    # 初期処理
    def __init__(self) : 
        bulb_def = ""
        print("initilize")

    def address_set(self, ac_address) :
        self.bulb_def  = yeelight.Bulb(ac_address)        

    def light_turn_on(self) :
        self.bulb_def.turn_on()

    def light_turn_off(self) :
        self.bulb_def.turn_off()

    def rgb_white(self) :
        self.bulb_def.set_rgb(255,255,255)

    def rgb_olive(self) :
        self.bulb_def.set_rgb(128,128,0)

    def rgb_yellow(self):
        self.bulb_def.set_rgb(255,255,0)

    def rgb_fuchsia(self):
        self.bulb_def.set_rgb(255,0,255)

    def rgb_silver(self):
        self.bulb_def.set_rgb(192,192,192)

    def rgb_red(self):
        self.bulb_def.set_rgb(255,0,0)

    def rgb_gray(self):
        self.bulb_def.set_rgb(128,128,128)

    def rgb_blue(self):
        self.bulb_def.set_rgb(0,0,255)

    def rgb_green(self):
        self.bulb_def.set_rgb(0,128,0)

    def rgb_purple(self):
        self.bulb_def.set_rgb(128,0,128)

    def rgb_navy(self):
        self.bulb_def.set_rgb(0,0,128)

    def rgb_teal(self):
        self.bulb_def.set_rgb(0,128,128)

    def rgb_maroon(self):
        self.bulb_def.set_rgb(128,0,0)
'''
# No to set color
    def rgb_black(self):
        self.bulb_def.set_rgb(0,0,0)
'''
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?