Here is a HUEseless side-project
Tuesday, March 26, 2019
4 min read
(This is a physical one from ThinkGeek (not an affiliate link))
In this post, I will recount how I made a silly side-project playing with the Philips HUE APIs, NodeJS, Google Home, RaspberryPi Zero W, and my kids.
I made a tweet about this some time ago, and today I’d like to elaborate a little on the subject:
""HUEseless"" gift for you 😈... or your kids 🤭https://t.co/gPK0Q3Fwwu#PhilipsHUE #RaspberryPi #NodeJS #GoogleHome #KidsKeepSwitchingLightOnInsteadOfSleeping #BestDadEver #BadParentalAdvice pic.twitter.com/ugu0KsSfGG— David Lacourt 🛣🏡 (@doppelganger9) 3 mars 2019
My genius evil plan
The story is:
In 2016, I installed a Philips HUE lightbulb in my kids’ bedroom. Unfortunately, the room switch turns it off, and when turned back on, the HUE lightbulb goes back to white and 100% intensity. So the kids quickly learned that If I turn off the lights remotely with an app or Google Home, they simply need to play with the room switch off then on and they “win”.
So, as soon as I closed their door when time to sleep has had come, they would get up and turn it back on!
A war of turning on & off lights ensued.
As a geek dad, I wanted to automate this into an evil AI, so that I can laugh madly while petting my cat, mwahahahahah!
As a gift, here is a link to the repository where you’ll find more details: https://gitlab.com/davidlacourt/hueseless
How does it work?
The APIs are really easy to “HUE”-se.
Just read the documentation and follow the tutorial, I did not meet any obstacle on the way. So I could hack an evil “AI” really quickly.
Evil AI (= 2 “IF”s)
Here is the evil AI pseudo-code:
IF you get data from API IF the light is on THEN turn it off
Just for the fun of it, I added voice to my script, so that instead of using
console.log I would hear messages from it. When starting, it would say:
Light status monitoring enabled!
or when turning off the lights:
I turned off the lights.
I used node-googlehome repository/NPM library but had to tweak it a little to make it work, and ended up opening a PR.
RaspberryPi Zero W
The RaspberryPi Zero W is a mini version of the RaspberryPi which is already a really small computer.
Once installed and built, I deployed this project on the RPi0W, which was really slow to
npm install all the libs, but 10 minutes later, I could run the main loop.
I even added an auto-start to the Raspberry, which made it so that when powering up, it would automatically start my NodeJS script. Really nice!
For more details, I just followed this Medium article.
Well, it worked perfectly.
Except kids learn more quickly than my evil “AI”!
They learned that switching on/off a few dozen times made my code break. And even, instead of simply putting the lights on, for them it became a new game!
So I ended the experiment there.
Now they go to sleep without any need to have a light so I can say it’s over.
In this short post, I wanted to show you a silly side-project mixing Google Home, NodeJS, Philips HUE, running on a RaspberryPI and evil AI in order to battle my smart kids. The result is working but they still outsmarted the whole contraption 🤣!
Anyway, I learned some things on the way.
I hope you too learned a few things or at least piqued your curiosity.