DEV Community

David Lacourt
David Lacourt

Posted on

Here is a HUEseless side-project

HUEseless

Like this one from ThinkGeek
(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.

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.

on/off

As a geek dad, I wanted to automate this into an evil AI, so that I can laugh madly while petting my cat, mwahahahahah!

evil laugh

Gitlab Repository

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?

NodeJS

For this quick script thing of a project, I prefer JavaScript and NodeJS.
For once, I did not write tests, because my kids tested it for me directly on production.

PhillipsHUE

The APIs are really easy to "HUE"-se.

quotes

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
Enter fullscreen mode Exit fullscreen mode

dr evil laughing

Google Home

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.

mini me

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.

Results

perfect plan

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!

the irony

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.

🤷‍♂️

Conclusion

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.

Thanks for reading this blog, If you have any questions, please use the Github Repository's Issues to start a conversation, or use Twitter: my DMs are open.

đź‘‹

(First posted on my personal blog https://lacourt.dev/2019/03/26/)

Top comments (0)