Skip to content

Instantly share code, notes, and snippets.

@ryanvillarreal
Last active January 16, 2023 02:11
Show Gist options
  • Save ryanvillarreal/190a2cfa6007d06da20ae580ca4eb001 to your computer and use it in GitHub Desktop.
Save ryanvillarreal/190a2cfa6007d06da20ae580ca4eb001 to your computer and use it in GitHub Desktop.
from pyHS100 import Discover,SmartPlug
#https://github.com/GadgetReactor/pyHS100
def lamp():
alias = "Office"
# discover which device is aliased to office
for dev in Discover.discover().values():
if (dev.alias == "Office"):
host = dev.host
# check to see if the light is off or on - toggle according
plug = SmartPlug(host)
if (plug.state == "ON"):
print("turning off")
plug.turn_off()
elif(plug.state == "OFF"):
print("turning on")
plug.turn_on()
else:
pass
if __name__ == "__main__":
lamp()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment