Skip to content

Instantly share code, notes, and snippets.

@TayIorRobinson
Created January 23, 2022 03:59
Show Gist options
  • Save TayIorRobinson/6a8f5d6cca117e13e6bd0cffa2f2195d to your computer and use it in GitHub Desktop.
Save TayIorRobinson/6a8f5d6cca117e13e6bd0cffa2f2195d to your computer and use it in GitHub Desktop.
Control Tuya light bulb with Python using Tuyaha library
import time
import tuyaha
tuya = tuyaha.TuyaApi()
devices = tuya.init("taylor@example.com", "hunter2", "44", "smart_life", "eu")
lights = list(filter(lambda dev: dev.dev_type == "light", devices))
light = lights[0]
print("Hello, " + light.name() + "!")
print("current brightness: " + str(light.brightness()))
print("light goes off")
light.turn_off()
time.sleep(2)
print("light goes on")
light.turn_on()
time.sleep(2)
print("dimming to 10%")
light.set_brightness(25)
time.sleep(2)
print("Red!")
light.set_brightness(255)
light.set_color((0, 100, 100))
time.sleep(2)
print("Teal!")
light.set_color((150, 100, 100))
time.sleep(2)
print("warm!")
light.set_color_temp(1800)
time.sleep(2)
print("cold!")
light.set_color_temp(7500)
time.sleep(2)
light.set_color_temp(4000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment