2020. 9. 30. 15:52ㆍRaspberry Pi
< The Raspberry Pi series: Homebridge >
Hello friends, this is babae!
So, I'm back this week to introduce another piece of software for the Raspberry Pi, and this is one of the primary reasons for me to get a Raspberry Pi in the first place.
I have started to finally try out smart home gadgets in 2018 when I got the third generation of Amazon Echo Dot. Initially, I was just looking for a small speaker for my laptop. I wasn't looking for volume, but just a speaker that could be wirelessly connected via Bluetooth and improve the quality over the tinny built-in laptop speakers. I was living in a basement suite with thin walls so I definitely wasn't looking for bass. The audio quality of the Echo Dot third gen, according to online reviews at the time, was a huge improvement compared to the second gen and seemed to be exactly what I was looking for. Aesthetically, it was great too, as it was small and the round design with a fabric cover was contemporary.
On Prime Day, or when it goes on sale, you cannot find a better speaker for the price.
I didn't know Alexa and while I had been using iOS and Android, I never really spoke to the smart assistants, Siri and Google Assistant, respectively. The Echo Dot has four buttons for volume control, muting the mic, and activating Alexa. Naturally, it invites you to interact with it through voice. It is quite sensitive to its wake word and can hear you from across a fairly large space, sometimes even from the other room. As you can imagine, aside from hooking it up with Spotify in the Alexa app, there is nothing really impressive that I can do with it. At times before I started wearing a watch, when I was too lazy to grab my phone to check the time, I would just ask Alexa. Occasionally, I would ask Alexa for the weather. It is some what impractical to control your music through Alexa, though, as you would have to request to play songs, one at a time. I usually play my music through a generated playlist on Spotify, which Alexa does not recognize, and I don't know about you but I rarely know the names of songs.
Anyways, I was still pretty impressed how Alexa understand natural speech and decided to experiment with the smart home stuff that was already getting popular at the time. You would think that it's cool to voice control your lights so you'd intuitively go buy a smart light bulb. I later learn that this is incorrect. If you want to control a light only by your voice, such as a floor lamp that has an in-line switch, and that switch is inconveniently located, it makes a lot of sense to replace the light bulb. However, if you want to occasionally use your voice to control a light, and still use the physical light switch on the wall to control the light, then you should actually replace the switch itself instead. It makes even more sense when your one light switch controls many lights at the same time. For example, I have one switch that turns on my kitchen lights, which are a set of six pot lights. It would be ridiculously more expensive to buy six smart bulbs, then group them in the smart app, than buying just one smart switch. The biggest draw back is that if you have a smart bulb and then turning it off with the manual switch, then it goes offline and you cannot turn it back on via your voice, whereas you can switch off the lights manually on the smart switch, but it remains online so you can turn your lights back on via your voice. For the floor lamp example above, a smart bulb makes a lot of sense. In addition to making it more convenient to turn on than finding the in-line switch, usually on the floor along the path to the wall outlet, a smart bulb allows you to add dimming, and color/temperature control.
By the time I got my Raspberry Pi, I have three smart bulbs, one smart switch, one smart plug, and of course, a smart TV in my home. The smart plug is for my portable air conditioner, which doesn't have smart controls built-in. I may make a more detailed post of my current home setup later on in the future if you guys are interested. I have been interacting with my devices mostly through Alexa, and occasionally, the widget on my iPhone. When I'm in another room and forgot to turn off the lights, I don't really want to yell to Alexa. It is much more convnenient to use my phone since I always have it with me. Switching the lights off through the widget on my iPhone takes more work than just asking Siri; Siri only works with Apple Home-certified accessories - otherwise known as HomeKit.
My smart home products are all from Amazon, and I have never had Philip Hue as smart home technology in 2018 started to move away from hub-based controls. First, Philip Hue is over priced, and second, you have to invest in a hub to connect all the individually accessories. As for anything Apple-related, manufacturers pay a premium to be in the ecosystem and pass that price to you. Siri can only control HomeKit accessories, such as Philip Hue, which is like five to ten times more expensive than generic Chinese ones (I have a few good brands to recommend, again in a later post). These Chinese smart accesories often have the same chipset or protocol, despite coming from different brands. I believe the parent company is Tuya. Alexa has no problem recognizing these devices, once you connect Alexa to the SmartLife or Tuya platform. My Alexa also connects to my Sony Android TV from 2016. You just have to find the skill on the Alexa app.
So the question is, how do I use all my smart home devices, including my TV, with Apple Home so that I can control them just by asking Siri? The answer is a bridge - the Homebridge.
What Homebridge does is similar to how skills enhance Alexa; as the name implies, it creates a bridge between different platforms, such as Tuya, with HomeKit. Once your accessory is recognized in Apple Home, you can set scenes, create automations, and control it with Siri or short cuts on the control panel. If you have a smart TV and find a Homebridge plugin for the TV, you can even use the Apple TV remote in the control panel to navigate on the TV.
I should note, though, that for you to access Home remotely (ie, outside of your local network), or use automation, you need an Apple TV, iPad, or HomePod to act as a hub. Even with VPN, you won't be able to connect as it uses Bonjour services - same reason AirPlay cannot connect through VPN.
To install Homebridge, you need to install the server backend, called Node.js. At the time of writing, Node.js is on version 14 but the Homebridge website still has instructions for version 12. To be safe, and I'm sure theres no practical benefits of using a newer version for our purposes, let's stick with those instructions. SSH into the Pi as we did in previous parts of the series:
curl -sLdeb.nodesource.com/setup_12.x| sudo bash -
sudo apt install -y nodejs gcc g++ make python net-tools
sudo npm install -g npm
Notice, we also install dependencies, such as gcc, g++, make, python, and net-tools. Some of these may already be installed on your Pi, and they will be skipped automatically if so.
Now, we install Homebridge:
sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x
The above will also install the front-end, which we will use to interact with Homebridge on a web browser.
This is where I had a lot of issues when I first followed the instructions on the website, and I wished I had someone to explain the instructions to me like I am doing for you.
Installing Homebridge is separate from installing instances of the Homebridge service. You can think of each instance as separate bridges. On your Apple Home app, you can add one or more bridges. However, a bridge can only be added by one person/account. For example, if you have a light bulb in your home and two people live in the home. You have to create two Homebridge services on the Pi, and each person will add their own one Homebridge service on their Home app on their iPhone.
To do this, for each instance, you will use the following and give a port number to access the web user interface (UI) later:
hb-service install --user homebridge --service-name <you can name it here> --port <an unused port number here>
For example:
hb-service install --user homebridge --service-name homebridge1 --port 8080
In the example, I create a user called homebridge, named the instance homebridge1, and set the port to 8080, which is usually open - except, if you had followed my previous post, Pi-hole would already have been using the port! This is the key to why many people have trouble installing Pi-hole and Homebridge together when they just copy and paste code from tutorials on the web.
As I explained in the previous post, an application can use an unassigned port but once that application claims it, another application cannot use it as it will conflict. Let's try this analogy to help you understand: you have a file with the extension .mp3, which is an audio file. You cannot have a picture with .mp3 as your computer will try to open that file with your audio player, and the audio player won't know what to do with it as it was expecting the data to be in an audio format. Once you assign a port to an application, the application listens to that port, expecting data that it knows what to do with.
To avoid/address the conflict, use another port:
hb-service install --user homebridge --service-name homebridge1 --port 8581
By the way, you can customize the username to be whatever you want, but using "homebridge" is descriptive. I recommend you do not install homebridge on your primary user account though, as that will limit the permissions and access of Homebridge to that specific account. User permissions is one of the built-in security measures of Linux. For the second instance of homebridge, you would probably change the details to:
hb-service install --user homebridge --service-name homebridge2 --port 8582
The numbering do not have to be seqential. You can name it whatever you want and use any unused port number. I keep they sequential so its easier to remember.
With the services installed, you can now go on the web browser, and go to http://<IP address of your Pi>:<port number you assigned>. The default username and password for login are both "admin". For security reasons, I highly recommend you create a new user and set a strong password.
At this point, you go to the Plugins and search for the platform you need. These plugins will instructions on how to customize the .json configuration file, which you would also access from the web UI. Play around with it as there are too many features and options for me to cover.
Now, on your iPhone, you can open the Home app and scan that QR code to add your Homebridge. It would give you a warning that the accessory is not supported, but continue anyways.
Congratulations, you should now see all of your smart devices in your Home app, and you can ask Siri to turn them, on and off, and whatever else you can normally do with them on the native platform app.
Come back next week for an introduction to another app that I use on my Pi.
라즈베리 파이를 이용해서 스마트홈 만들기!
어렵지 않아요 :)
천천히 시작해봐요 ㅎㅎ
'Raspberry Pi' 카테고리의 다른 글
The Raspberry Pi Series: LAMP Server (9) | 2020.10.31 |
---|---|
The Raspberry Pi series: PiVPN (2) | 2020.10.09 |
The Raspberry Pi series: Securing The Pi / 라즈베리파이 셋업 시리즈: 보안강화 편 (7) | 2020.09.21 |
The Raspberry Pi series: The Setup (9) | 2020.09.14 |
The Raspberry Pi series: Pi-hole (11) | 2020.09.07 |