Here is a HUEseless side-project
Tags: node, philipshue, googlehome, sideprojects
Published: 2019-07-04 22:05:11

---
title: Here is a HUEseless side-project
published: true
description: Here is my silly side-project as a geek dad with kids playing with their lights instead of sleeping.
tags: NodeJS, PhilipsHUE, Google Home, Side-project
lang: en
---

# HUEseless

![Like this one from ThinkGeek](https://www.thinkgeek.com/images/products/zoom/ivlq_useless_light_switch.gif)
(This is a physical one from [ThinkGeek](https://www.thinkgeek.com/product/ivlq/) *(not an affiliate link)*)

In this post, I will recount how I made a silly side-project playing with the [Philips HUE APIs](https://developers.meethue.com/develop/), 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](https://media.giphy.com/media/3ohzdFHDBEG32PmWJO/giphy.gif)

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](https://media.giphy.com/media/MgwVy8YxMqJ56/giphy.gif)

## 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](https://media.giphy.com/media/qs6ev2pm8g9dS/giphy.gif)

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
```

![dr evil laughing](https://media.giphy.com/media/xl5QdxfNonh3q/giphy.gif)

#### 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](https://www.npmjs.com/package/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](https://media.giphy.com/media/8Q62oGruZu0BG/giphy.gif)

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](https://medium.com/@andrew.nease.code/set-up-a-self-booting-node-js-eb56ebd05549).

## Results

![perfect plan](https://media.giphy.com/media/l3vR6aasfs0Ae3qdG/giphy.gif)

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](https://media.giphy.com/media/2iBsieTJ3eO1q/giphy.gif)

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](https://github.com/doppelganger9/blog/issues) to start a conversation, or use [Twitter: my DMs are open](https://twitter.com/doppelganger9).

👋

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