Make your own Smarthome Server with NodeJS
Tags: javascript, node, ios, tutorial
Published: 2021-04-06 18:51:03

<div class="modal-body">
<p>The smart home product segment is more competitive than ever with lots of companies competing to be the next cool product that you buy for your home. But as a consumer there are lots of complications with trying to pick a product when trying to decide if a product will be compatible with your setup or with the things you may want to buy. And for a lot of products, like TVs, you can get a cheaper TV if it doesn’t support HomeKit as it typically means it’s a few years older. But wouldn’t it be cool if you could still add HomeKit support so that you can control those devices from your&nbsp;phone?</p>
<p>Enter <a href="https://github.com/homebridge/homebridge">Homebridge</a>, a lightweight NodeJS server that you can run on your home network that emulates the iOS HomeKit API. With a growing open source library of plugins, Homebridge is quickly becoming a solid option for anyone looking to add more functionality to their smart&nbsp;home.</p>
<h3><strong>My Experience</strong></h3>
<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-g-Ty3emO3rEFz5QturOQ.jpeg"><figcaption>Source: <a href="https://techcrunch.com/2019/12/19/anybody-can-now-make-homekit-accessories/">TechCrunch</a></figcaption></figure><p>Homekit has allowed me to expand my smart home capabilities and add automations that otherwise wouldn’t be possible. It started when I got a 2019 <a href="https://www.amazon.com/Samsung-QN75Q70RAFXZA-Flat-QLED-Smart/dp/B07N4MVTXB/ref=asc_df_B07N4MVTXB/?tag=hyprod-20&amp;linkCode=df0&amp;hvadid=241883071164&amp;hvpos=&amp;hvnetw=g&amp;hvrand=8233342149939902883&amp;hvpone=&amp;hvptwo=&amp;hvqmt=&amp;hvdev=c&amp;hvdvcmdl=&amp;hvlocint=&amp;hvlocphy=9030890&amp;hvtargid=pla-654607754631&amp;psc=1">Samsung Q70 smart tv</a> that somehow didn’t support Homekit. I got a killer deal on the TV, but the newer models released later that year all supported Homekit natively, and of course cost way more. I had a <a href="https://www.amazon.com/CanaKit-Raspberry-Power-Supply-Listed/dp/B07BC6WH7V">Raspberry Pi B+</a> sitting around so I decided to tinker with it and see if I could get Homebridge to run on it. After less than 30 minutes I was able to get everything up and running with no problems. I figured because it was so easy that it wouldn’t be very stable, but it is really stable. It honestly acts just like first-party Homekit support. I have since added a <a href="https://www.amazon.com/LEVOIT-LV-PUR131-Purifier-Allergies-Eliminator/dp/B06W54K29J">Levoit Air Purifier</a> to my homebridge server and that has also worked out very&nbsp;well.</p>
<h3><strong>Installation</strong></h3>
<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lFFGMmWLK2xJWxG3"><figcaption>Source: <a href="https://blog.pimoroni.com/a-deep-dive-into-the-raspberry-pi-3-b-hardware/">Sandy MacDonald</a></figcaption></figure><p>There are already lots of breakdowns of already installing Homebridge out there, and the <a href="https://github.com/homebridge/homebridge/wiki">official documentation is really solid</a>. I thought I would document how I went about it as I think my implementation was a little bit&nbsp;cleaner.</p>
<p>The first step is to figure out what system you are going to be running this on and download the correct image. I didn’t install Homebridge UI and I kinda wish I did as it just makes it easier to manage going forward. I would highly recommend using a Raspberry pi as it is so easy to get going. After following the basic steps to get everything downloaded, I did the following to run <a href="https://words.bombast.net/homebridge-service-debian/">Homebridge as a service on&nbsp;Linux</a>:</p>
<ul>
<li>
<em>sudo nano /etc/systemd/system/homebridge.service</em> and <a href="https://words.bombast.net/homebridge-service-debian/">paste this</a> in&nbsp;there.</li>
<li><em>sudo systemctl daemon-reload</em></li>
<li><em>sudo systemctl enable homebridge</em></li>
<li><em>sudo systemctl start homebridge</em></li>
</ul>
<p>These commands create a system service and system manager that has widely become the new standard for Linux distributions. The advantage of this is that the service will run as soon as the pi boots so there is no need to worry if the power goes out or if there are any failures that cause Homebridge to crash. It was simply&nbsp;reboot.</p>
<p>After you have the service running, restart you pi and you are ready to start installing any plugins that you&nbsp;want.</p>
<p>If you run into any problems, there is a great community on <a href="https://github.com/homebridge/homebridge/issues">Github</a>, <a href="https://discord.com/invite/kqNCe2D">Discord</a>, and <a href="https://www.reddit.com/r/homebridge/">Reddit</a> to help you. If you have questions about how I was able to get mine set, <a href="https://twitter.com/maurerpwer">tweet me&nbsp;here</a>.</p>
<p><strong>So get out there and make your home&nbsp;smarter!</strong></p>
<img src="https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=86e7aa0f63f4" width="1" height="1" alt="">
</div>