Magic Mirror

The smart mirror! I know you’ve seen them on the Internets. So sleek. So futuristic. Such wow! I had to have one.

Well, a few months ago I built a MagicMirror² for my apartment. The process is pretty well documented, so I’ll spare you the details of my build, but I wanted to add some functionality so that the mirror would display the ETA and surge charges for Lyft and Uber.

I found this module, although I was never able to get it working on my mirror. I had never worked with JavaScript/Node.js and didn’t know (and still don’t really know) anything about back-end communication but I decided to try and hack something together.

Writing the Modules

MagicMirror² does provide Module Development Documentation, however I didn’t find it to be particularly useful. Going through the source code for default modules and other existing modules was a better use of time. Especially if you can find a module that performs a function similar to the function in your own module.

Both Uber and Lyft implement RESTful APIs and require authentication. Fortunately, there was an npm package to handle that. For Uber I used a Server Token to make requests, and for Lyft I used an OAuth2 “2-legged” flow. This blog post was really helpful with the latter.

Anyway, here’s the source for the Uber module and for the Lyft module. All the back-end work is done in the node_helper.js file, while the front-end is taken care of in the .js and .css files. And here’s how it’ll look on the mirror:

Feel free to fork, report issues and submit pull requests!