Yeelight and Hyperion tinkering

2017, Feb 10

Over the last week I've been looking into creating a basic web-service to easily interact with my lights around my flat. Currently, I have two Yeelights and a LightPack, which is located on the back of my TV.

Stuff tied into this

Cool things it can do RIGHT NOW

  • Turn lights on when my phone connects to WiFi
  • Notifications lights from my phone, passed on by Tasker
  • IFTTT events
  • Voice activated lighting cues, eg OK GOOGLE DIM LIGHTS, turn off, shut up etc using AutoVoice with Tasker
  • Basic web dashboard to fire off effects to devices
  • Using intents from (Sleep As A Droid)[https://play.google.com/store/apps/details?id=com.urbandroid.sleep&hl=en], turn off my lights when it's time to go to bed
  • Let people on the internet mess around with my light globes; this is a good idea

Cool things I'm thinking about doing with it

The CODE

I'm running a SimpleHTTP server in Python to handle all GET requests. The requests check to see, firstly, if the device exists and if so, what effect to run on it. As an example: http://localhost:5000/device/effect. I thought this would make it easy to simply craft a HTTP GET rather than posting JSON to it. Also means I can use Tasker without having to use the Send/Except plugin, which is fine and also great, but takes a bit to setup. Not that I'm lazy or anything. It also means I can use IFTTT's Maker to easily hit the AIR QUOTES API AIR QUOTES

You can view my source on github. It was written over a few days and strongly requires a re-factor.

Setting up Tasker

This can be a repetative process, but you can also copy the tasks you edit. AutoVoice is completely optional of course, and only if you're a giant nerd and want to tell OK Google to do stuff. Also excuse the ridiculously sized images.

Creating a task is fairly simple. You just need to use HTTP Get to push commands off to the Python webapi

So, my profile for my Snapchat notification is this: SnapeChatte in Tasker . To do this..

  • While on the profile tab...
  • Press the plus button, then Add Event => UI Event => Notification
    • Add Event
    • UI Event
    • Notification
    • Owner Application => Select Snapechat, go back
    • Enter Task
    • Hyperion Yellow
    • Hold down finger on the Hyperion Yellow task
    • Add Task
    • Yeelight K Yellow Blink
    • Hold finger down on Notification
    • Add State
    • Net => Wifi Connected
    • SSID => Enter your SSID for your WiFi
    • Done!

Breaking it down...

  • Once we get a notification from the App Snapchat AND if we're connected to my local WiFi:
    • Run task Hyperion Yellow, which will light my TV's backlights yellow
    • Run task Yeelight K Yellow Blink, which will blink the kitchen Yeelight

Adding a HTTP Get request | Editing the Task

My "OK Google Dim Lights" profile is as follows:

AutoVoice in Tasker

  • Once we get the voice command 'Dim Lights' AND if we're connected to my local WiFi
    • Run task Yeelight Dim

The configuration for the above event looks like this: AutoVoice in Tasker Event

Yeelights

Yes, you can ping your light globes now; what a future we live in.

It took me a while to workout how to enable the TCP JSON service on these lights. Turns out you need to download the Developer Mode application, then enable developer mode on each light globe. Xiaomi have also included a very comprehensive API documentation. But I'm being super lazy and using the python-yeelight package because it does pretty much everything I want it to do.

Overall

It was a pretty fun project. I think I'll need to upgrade my Raspberry Pi if I'm going to be adding text-to-speech. It's already processing video through to Hyperion! Also, please don't DDoS my lightbulbs. Thank you kindly.