Home Creating a Comfortable WFH Smart Home Environment, Control Appliances at Your Fingertips
Post
Cancel

Creating a Comfortable WFH Smart Home Environment, Control Appliances at Your Fingertips

Creating a Comfortable WFH Smart Home Environment, Control Appliances at Your Fingertips

Demonstrating the use of Raspberry Pi as a HomeBridge host to connect all Mi Home appliances to HomeKit

photo by [picjumbo.com](https://www.pexels.com/zh-tw/@picjumbo-com-55570?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels){:target="_blank"}

photo by picjumbo.com

About

Due to the pandemic, the time spent at home has increased; especially when working from home, it’s best if all home appliances can be smartly controlled via an app. This way, you don’t have to keep getting up to turn on the lights or the rice cooker, which wastes a lot of time.

Previously, I wrote an article titled “First Experience with Smart Home — Apple HomeKit & Xiaomi Mi Home”, where I initially tried using HomeBridge to connect Xiaomi appliances to HomeKit. Theoretically, it was feasible, but there wasn’t much practical application mentioned. Today’s article is a comprehensive advanced version of the previous one, including how to set up a Raspberry Pi as the host, with a step-by-step tutorial.

The motivation came from recently switching to an iPhone 11 Pro, which supports iOS ≥ 13 shortcuts with NFC automation. This means the phone can execute corresponding shortcuts when it detects an NFC tag. Although you can directly use an old EasyCard as an NFC tag, it takes up too much space and there aren’t that many cards. I asked around Guanghua Digital Plaza but couldn’t find any NFC tag stickers, so I finally found them on Shopee for $50 each and bought 5 to play with. The seller was kind enough to help me differentiate them by color.

*NFC automation is model-specific, only iPhone XS/XS max/XR/11/11pro/11pro max support this feature. Previously, with an iPhone 8, there was no NFC option.

After playing around a bit, I found a problem: when executing shortcuts for the Mi Home app, you must enable the “Show When Run” option (otherwise it won’t actually execute). When detecting the tag, you need to unlock the iPhone and the shortcut will open, making it impossible to execute directly in the background. Additionally, if the shortcut is for native Apple services (e.g., HomeKit appliances), it can execute directly in the background without unlocking. Moreover, HomeKit’s response speed and stability are much better than Mi Home’s.

This makes a big difference in user experience, so I delved deeper into connecting all Mi Home smart home products to HomeKit. For those that support HomeKit, just bind them directly; for those that don’t, follow this tutorial to bind them as well!

My Mi Home Smart Home Items

  1. Mi Home Smart Camera Pan-Tilt Version 1080P
  2. Mi Home DC Inverter Fan
  3. Mi Home LED Smart Desk Lamp
  4. Xiaomi Air Purifier 3
  5. Mi Home Desk Lamp Pro (supports HomeKit natively)
  6. Mi Home LED Smart Bulb Color Version * 2 (supports HomeKit natively)

Operating Principle

I made a simple reference diagram. If the smart appliance supports HomeKit, connect it directly. For those that don’t support HomeKit, set up a “HomeBridge” service host (which needs to be always on) to bridge and connect them. In the same network environment (e.g., the same WiFi), the iPhone can freely control all HomeKit appliances. However, if you’re on an external network, such as 4G mobile network, you need an Apple TV/HomePod or iPad as the home hub, always on standby at home to control HomeKit from outside. Without a home hub, the Home app will show “ No Response “ when opened from outside.

*If it’s a Xiaomi device, it will be controlled via the Xiaomi server, which means there could be security issues as the data has to go through mainland China.

Requirements

So, there are two devices that need to be on standby all the time: one is an Apple TV/HomePod or iPad as the home hub; this part currently has no workaround, you have to obtain these devices somehow, if not, you can only use HomeKit at home .

The other device can be any computer that can be on standby 24 hours (like your iMac/MacBook), an idle host (old iMac, Mac Mini), or a Raspberry Pi.

*Windows series has not been tried, but it should work too!

Alternatively, if you just want to play around, you can use your current computer (can be used together with the previous article).

This article will demonstrate using a Raspberry Pi (Raspberry Pi 3B) and a MacBook Pro (MacOS 10.15.4), starting from setting up the Raspberry Pi environment from scratch; if you are not using a Raspberry Pi, you can skip directly to the HomeBridge integration with HomeKit part (this part is the same).

Raspberry Pi 3B (special thanks to [Lu Xun Huang](https://medium.com/u/b32ce1b681f8){:target="_blank"} )

Raspberry Pi 3B (special thanks to Lu Xun Huang )

If you are using a Raspberry Pi, you will also need a micro SD card (not too big, I use 8G), a card reader, a network cable (for setup, can connect to WiFi later); and the software needed for the Raspberry Pi:

  1. Raspberry Pi Desktop OS (for beginners, using the GUI version)
  2. Etcher burning software

Raspberry Pi Environment Setup

Burning the Operating System

After downloading the two required software, first insert the memory card into the card reader and plug it into the computer; open the Etcher program (balenaEtcher).

First, select the Raspberry Pi OS you just downloaded "xxxx.img", second, select your memory card device, then click "Flash!" to start burning!

First, select the Raspberry Pi OS you just downloaded “xxxx.img”, second, select your memory card device, then click “Flash!” to start burning!

At this point, it will prompt you to enter the **MacOS password**, enter it and click "Ok" to continue.

At this point, it will prompt you to enter the MacOS password, enter it and click “Ok” to continue.

Burning... please wait...

Burning… please wait…

Verifying... please wait...

Verifying… please wait…

Burn successful!

Burn successful!

*If a red Error appears, try formatting the memory card and burning it again.

Reconnect the card reader to the computer, and create an empty “ssh” file in the memory card directory ( or click here to download ) with no content and no extension, just a “ssh” file; this allows us to connect to the Raspberry Pi using Terminal.

ssh

ssh

Setting up the Raspberry Pi

Eject the memory card, insert it into the Raspberry Pi, connect the network cable, and power it on; make sure the MacBook and Raspberry Pi are on the same network.

Check the IP address assigned to the Raspberry Pi

The IP address assigned to the Raspberry Pi is: 192.168.0.110 (Please replace all IP addresses in this document with the one you found)

It is recommended to set the Raspberry Pi to a static/reserved IP, otherwise the IP address may change after rebooting and reconnecting, requiring you to check it again.

Use SSH to connect to the Raspberry Pi for operations

Open Terminal and enter:

1
ssh pi@your_raspberry_pi_IP_address

When prompted, enter yes, and for the password, enter the default password: raspberry

**Connection successful!**

Connection successful!

*If you encounter an error message like WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED, open /Users/xxxx/.ssh/known_hosts with a text editor and clear its contents.

Basic tools installation and setup on Raspberry Pi

  1. Enter the following command to install the Vim editor:
1
sudo apt-get install vim

2. Resolve the following locale warnings:

1
2
3
4
5
6
7
8
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_LANG = "zh_TW.UTF-8",
    LANG = "zh_TW.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Enter

1
vi .bashrc

Press “Enter” to proceed

Press “i” to enter edit mode

Move to the bottom of the document and add a line “export LC_ALL=C

Press “Esc” and enter “:wq!” to save and exit.

Then enter “source .bashrc” to update.

3. Install nvm to manage nodejs/npm:

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

4. Use nvm to install the latest version of nodejs:

nvm install 12.16.2

*Here, we choose to install version “12.16.2”

5. Confirm the environment installation is complete:

Enter the following commands

npm -v

and

node -v

to confirm

No error messages!

No error messages!

6. Create a nodejs link

Enter the following command

1
which node

Get the path information where nodejs is located

Then enter

1
sudo ln -fs paste_the_path_you_found_with_which_node_here /usr/local/bin/node

Create the link

Setup complete!

Enable Raspberry Pi VNC remote desktop feature

Although we have installed the GUI version, you can directly connect the Raspberry Pi to a keyboard and HDMI to use it as a regular computer. However, for convenience, we will use the remote desktop method to control the Raspberry Pi.

Enter:

1
sudo raspi-config

Enter the settings:

Select the fifth option " **Interfacing Options** "

Select the fifth option “ Interfacing Options

Select the third option " **P3 VNC** "

Select the third option “ P3 VNC

Use " **←** " to select " **Yes** " to enable

Use “ “ to select “ Yes “ to enable

**VNC remote desktop feature enabled successfully!**

VNC remote desktop feature enabled successfully!

Use " **→** " to directly switch to " **Finish** " to exit the setup interface.

Use “ “ to directly switch to “ Finish “ to exit the setup interface.

Add VNC remote desktop service to startup

We want the VNC remote desktop service to be automatically enabled when the Raspberry Pi boots up.

Enter

1
sudo vim /etc/init.d/vncserver

Press “Enter” to proceed

Press “ i “ to enter edit mode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop vncserver
### END INIT INFO

# More details see:
# http://www.penguintutor.com/linux/vnc

### Customize this entry
# Set the USER variable to the name of the user to start vncserver under
export USER='pi'
### End customization required

eval cd ~$USER

case "$1" in
  start)
    su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1024x768 :1'
    echo "Starting VNC server for $USER "
    ;;
  stop)
    su $USER -c '/usr/bin/vncserver -kill :1'
    echo "vncserver stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/vncserver {start|stop}"
    exit 1
    ;;
esac
exit 0

“Command” + “C”, “Command” + “V” to copy and paste the above content, press “Esc” and enter “:wq!” to save and exit.

Then enter:

1
sudo chmod 755 /etc/init.d/vncserver

Change the file permissions.

Then enter:

1
sudo update-rc.d vncserver defaults

Add to startup items.

Finally enter:

1
sudo reboot

Restart the Raspberry Pi.

*After the restart is complete, reconnect using ssh as before.

Connect using VNC Client:

Here we use the Chrome app “ VNC® Viewer for Google Chrome™ “. After installation and launch, enter Raspberry Pi IP address:1. Please note to add Port:1 at the end!

*I was unable to connect using Mac’s built-in VNC://, the reason is unknown.

Click " **Connect** ".

Click “ Connect “.

Click " **OK** ".

Click “ OK “.

**Enter login username and password** , same as SSH connection, username `pi` default password `raspberry`.

Enter login username and password , same as SSH connection, username pi default password raspberry.

**Successfully connected!**

Successfully connected!

Complete Raspberry Pi initialization settings:

The rest is graphical interface! Very easy!

Set language, region, time zone.

Set language, region, time zone.

Change the default Raspberry Pi password, enter the password you want to set.

Change the default Raspberry Pi password, enter the password you want to set.

Directly click " **Next** ".

Directly click “ Next “.

Set up WiFi connection, so you don't need to plug in the cable anymore.

Set up WiFi connection, so you don’t need to plug in the cable anymore.

*But please note that the Raspberry Pi IP address may change, you need to check it again in the router

Whether to update the current operating system, if not in a hurry, select " **Next** " to update!

Whether to update the current operating system, if not in a hurry, select “ Next “ to update!

*The update takes about 20~30 minutes (depending on your internet speed)

After the update is complete, click " **Restart** " to restart.

After the update is complete, click “ Restart “ to restart.

Raspberry Pi environment setup complete!

HomeBridge Installation

Now for the main event, installing and using HomeBridge.

Use Terminal to ssh into the Raspberry Pi or directly use the Terminal in the VNC remote desktop.

Enter:

1
npm -g install homebridge --unsafe-perm

^( Do not add sudo )

Install HomeBridge

Installation complete!

Create/Modify configuration file (config.json):

For easier editing, use VNC remote desktop to connect to the Raspberry Pi (you can also use commands directly) :

Click the top left to open “ File Manager “ -> go to “ /home/pi/.homebridge

If you don’t see the “config.json” file, right-click on the blank area “ New File “ -> enter the file name “ config.json

Right-click on “ config.json “ and open with “ Text Editor

Paste the following basic configuration content:

1
2
3
4
5
6
7
{
   "bridge": {
  "name": "Homebridge",
  "username": "CC:22:3D:E3:CE:30",
  "port": 51826,
  "pin": "123-45-568"
}

No need to make special changes to the content, just copy it directly!

Remember to save!

Done!

Bind HomeBridge to Homekit

Enter:

1
homebridge start

^( Do not add sudo )

Enable

If you encounter an Error: Service name is already in use on the network / port is occupied error, try deleting the service, using homebridge restart to restart, or rebooting.

If you encounter an error like was not registered by any plugin, it means you haven’t installed the corresponding homebridge plugin.

If you change the configuration file (config.json) while starting, you need to modify it:

sudo homebridge restart

Restart HomeBridge

Press “Control” + “C” to close and exit the HomeBridge service in Terminal.

Take out your iPhone and open the “Home” app. In the upper right corner of “Home,” click “+”, select “Add Accessory,” and scan the QRCode that appears.

At this point, you should see “ Accessory Not Found “. Don’t worry! Because we haven’t added any accessories to the HomeBridge bridge yet, it’s okay, let’s continue.

You must have at least one accessory to scan and add!!! (Here, we use a camera as an example) : You must have at least one accessory to scan and add!!! (Here, we use a camera as an example) : You must have at least one accessory to scan and add!!! (Here, we use a camera as an example) :

The first time you scan and add, a warning window will appear. Just click “Force Add”!

After adding once, you don’t need to scan again for any new accessories; they will update automatically!

Add HomeBridge service to Raspberry Pi startup items

Like the VNC remote desktop service, we also want the HomeBridge service to be automatically enabled when the Raspberry Pi starts, otherwise, we have to manually log in and enable it every time it reboots.

Enter:

1
which homebridge

Get homebridge path information

Note down this path.

Then enter:

1
sudo vim /etc/init.d/homebridge

Press “Enter” to enter

Press “i” to enter edit mode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

dir="/home/pi"
cmd="DEBUG=* paste the path you got from which homebridge here"
user="pi"

name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"

get_pid() {
cat "$pid_file"
}

is_running() {
[ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
}

case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in 1 2 3 4 5 6 7 8 9 10
# for i in `seq 10`
do
if ! is_running; then
break
fi

echo -n "."
sleep 1
done
echo

if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

Replace:

cmd=”DEBUG=* Paste which homebridge path”

with the path information you found (without double quotes)

Press “Command” + “C”, “Command” + “V” to copy and paste the above content, press “Esc” and enter “:wq!” to save and exit.

Then enter:

1
sudo chmod 755 /etc/init.d/homebridge

Modify file permissions.

Finally enter:

1
sudo update-rc.d homebridge defaults

Add to startup items.

Done!

You can directly use sudo /etc/init.d/homebridge start to start the homebridge service.

You can also use: tail -f /var/log/homebridge.err to view startup error messages, tail -f /var/log/homebridge.log to view logs.

Preparation before connecting Mi Home smart appliances

Once Homebridge is up and running, we can start adding all Mi Home appliances to Homebridge and connect them to HomeKit!

First, we need to add all Mi Home smart appliances to the Mi Home APP to obtain the information needed to connect to HomeBridge.

After adding the smart appliances to the Mi Home APP:

Connect your iPhone to your Mac, open Finder/iTunes, and select the connected phone.

Select “Back up to this computer”, “Do not check! Encrypt local backup”, and click “Back Up Now”.

After the backup is complete, download and install the backup viewer software: iBackupViewer

Open “iBackupViewer”.

The first time you start it, you will need to go to Mac “System Preferences” - “Security & Privacy” - “Privacy” - “+” - add “iBackupViewer”.

*If you have privacy concerns, you can disable the network while using this software and remove it after use.

Open “iBackupViewer” again, and after successfully reading the backup file, click on the “just backed up phone”.

Select the "App Store" Icon

Select the “App Store” Icon.

On the left, find "Mi Home APP (MiHome.app)" -> On the right, find "numbers_mihome.sqlite" file and "select" -> Top right "Export" -> "Selected Files"

On the left, find “Mi Home APP (MiHome.app)” -> On the right, find “numbers_mihome.sqlite” file and “select” -> Top right “Export” -> “Selected Files”.

*If there are two “numbers_mihome.sqlite” files, choose the one with the latest Created time.

Drag the exported numbers_mihome.sqlite file into this website to view the content:

You can change the query syntax to:

1
SELECT `ZDID`,`ZNAME`,`ZTOKEN` FROM 'ZDEVICE' LIMIT 0,30

Only display the field information we need (if there are specific appliance kits that require other field information, you can also add them for filtering).

  1. ZDID: Device ID
  2. ZNAME: Device Name
  3. ZTOKEN: Device ZToken

ZTOKEN cannot be used directly, it needs to be converted to “Token” to be usable.

Here, we take the conversion of the camera’s ZToken to Token as an example:

First, we obtain the ZToken field content of the camera from the above list:

1
7f1a3541f0433b3ccda94beb856c2f5ba2b15f293ce0cc398ea08b549f9c74050143db63ee66b0cdff9f69917680151e

But the TOKEN obtained here cannot be used yet, we still need to convert it.

Open http://aes.online-domain-tools.com/ this website:

  1. Paste the ZTOKEN you just copied into “Input Text” and select “Hex”.
  2. Enter “00000000000000000000000000000000” (32 zeros) in the Key field, and also select “Hex”.
  3. Then click “Decrypt!” to convert.
  4. Select and copy the output content of the bottom two lines on the right and remove the spaces to get the result Token.

「 **6d304e6867384b704b4f714d45314a34** 」is the Token result we need!

6d304e6867384b704b4f714d45314a34 」is the Token result we need!

*The method of obtaining the Token has been tried using “miio” to sniff directly, but it seems that the Mijia firmware has been updated, and this method can no longer be used to quickly and conveniently obtain the Token!

Finally, we also need to know the IP address of the device (here we take the camera as an example):

Open the Mi Home APP → Camera → Top right corner “…” → Settings → Network Information, to get the IP address!

Record the ZDID/Token/IP information for later use.

Integrate Mijia Smart Appliances into HomeBridge One by One

Install and configure each device individually according to the required plugins and connection information, and add them to HomeBridge.

Next, open Terminal, ssh into the Raspberry Pi, or use VNC remote desktop’s Terminal to continue the subsequent operations…

1. Mijia Camera Pan-Tilt Version:

In Terminal, run the command to install the MijiaCamera homebridge plugin (without sudo):

1
npm install -g homebridge-mijia-camera

Refer to the previous tutorial on modifying the configuration file (config.json), and add the accessories section in the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
   "bridge":{
      "name":"Homebridge",
      "username":"CC:22:3D:E3:CE:30",
      "port":51826,
      "pin":"123-45-568"
   },
   "accessories":[
      {
         "accessory":"MijiaCamera",
         "name":"Mi Camera",
         "ip":"",
         "token":""
      }
   ]
}

accessories: Add the configuration information of the Mijia camera, with the ip field filled with the camera’s IP and the token field filled with the token taught in the previous tutorial.

Remember to save the file!

Then, follow the Homebridge section tutorial to start/restart/scan and add to Homebridge; you will be able to see the camera control items in the “Home” APP.

Controllable items: Camera on/off

2. Mi Home DC Variable Frequency Fan

In Terminal, install the homebridge-mi-fan homebridge plugin (without sudo):

1
npm install -g homebridge-mi-fan

Refer to the previous tutorial on modifying the configuration file (config.json), and add the platforms block in the file (if it already exists, add a sub-block within the block using a comma) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
   "bridge":{
      "name":"Homebridge",
      "username":"CC:22:3D:E3:CE:30",
      "port":51826,
      "pin":"123-45-568"
   },
   "platforms":[
      {
         "platform":"MiFanPlatform",
         "deviceCfgs":[
            {
               "type":"MiDCVariableFrequencyFan",
               "ip":"",
               "token":"",
               "fanName":"room fan",
               "fanDisable":false,
               "temperatureName":"room temperature",
               "temperatureDisable":true,
               "humidityName":"room humidity",
               "humidityDisable":true,
               "buzzerSwitchName":"fan buzzer switch",
               "buzzerSwitchDisable":true,
               "ledBulbName":"fan led switch",
               "ledBulbDisable":true
            }
         ]
      }
   ]
}

platforms: Add Mi Home fan configuration information, input the camera’s IP in the ip field, input the token from the previous tutorial in the token field, and control whether to display temperature and humidity information with humidity/temperature. The type must be the corresponding model text, supporting four different fan models:

  1. ZhiMi DC Variable Frequency Floor Fan: ZhiMiDCVariableFrequencyFan
  2. ZhiMi Natural Wind Fan: ZhiMiNaturalWindFan
  3. Mi Home DC Variable Frequency: MiDCVariableFrequencyFan (sold in Taiwan)
  4. Mi Home Fan: DmakerFan

Please input your own fan model.

Remember to save the file!

Then, as taught in the Homebridge section, start/restart/scan to add to Homebridge; you will be able to see the camera control items in the “Home” APP.

Controllable items: Fan on/off, wind speed adjustment

3. Xiaomi Air Purifier 3

In Terminal, install the homebridge-xiaomi-air-purifier3 homebridge plugin (without sudo):

1
npm install -g homebridge-xiaomi-air-purifier3

Refer to the previous tutorial on modifying the configuration file (config.json), and add the accessories block in the file (if it already exists, add a sub-block within the block using a comma) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
   "bridge":{
      "name":"Homebridge",
      "username":"CC:22:3D:E3:CE:30",
      "port":51826,
      "pin":"123-45-568"
   },
   "accessories":[
      {
         "accessory":"XiaomiAirPurifier3",
         "name":"Xiaomi Air Purifier",
         "did":"",
         "ip":"",
         "token":"",
         "pm25_breakpoints":[
            5,
            12,
            35,
            55
         ]
      }
   ]
}

accessories: Add Mi Home fan configuration information, ip should be the camera ip, token should be the token taught in the previous tutorial, did should be zdid

Remember to save!

Then follow the Homebridge section instructions to start/restart/scan and add to Homebridge; you will be able to see the camera control items in the “Home” APP.

Controllable items: Air purifier switch, wind speed adjustment Viewable items: Current temperature and humidity

4. Mi Home LED Smart Desk Lamp

In Terminal, install the homebridge-yeelight-wifi homebridge plugin (without sudo):

1
npm install -g homebridge-yeelight-wifi

Refer to the previous tutorial on modifying the configuration file (config.json), and add the platforms block in the file (if it already exists, add a sub-block with a comma inside the block) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
   "bridge":{
      "name":"Homebridge",
      "username":"CC:22:3D:E3:CE:30",
      "port":51826,
      "pin":"123-45-568"
   },
   "platforms":[
      {
         "platform":"yeelight",
         "name":"Yeelight"
      }
   ]
}

No need to pass any special parameters! For more detailed settings, refer to the official documentation (such as brightness/color temperature…)

Remember to save!

The smart desk lamp also needs to be re-bound to the Yeelight APP, and then turn on “Local Network Control” to allow Homebridge to control it.

  1. Download and install the Yeelight APP on your iPhone

Search "Yeelight" in the App Store and install

Search “Yeelight” in the App Store and install

After installation, open the Yeelight APP -> "Add Device" -> Find "Mi Home Desk Lamp" -> Re-pair and bind

After installation, open the Yeelight APP -> “Add Device” -> Find “Mi Home Desk Lamp” -> Re-pair and bind

Remember to turn on " **Local Network Control** " in the last step

Remember to turn on “ Local Network Control

*If you accidentally didn’t turn it on, you can go to the “Device” page -> Select the desk lamp device -> Click the bottom right “△” Tab -> Click “Local Network Control” to enter settings -> Turn on Local Network Control

A little complaint, this is really bad, the Mi Home APP itself does not have this switch function, you must bind it to the Yeelight APP, and you cannot unbind or rebind it back to Mi Home… otherwise it will fail.

Then follow the Homebridge section instructions to start/restart/scan and add to Homebridge; you will be able to see the camera control items in the “Home” APP.

Controllable items: Light switch, color temperature adjustment, brightness adjustment

Other Mijia smart home appliances homebridge plugins:

My final config.json looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
   "bridge":{
      "name":"Homebridge",
      "username":"CC:22:3D:E3:CE:30",
      "port":51826,
      "pin":"123-45-568"
   },
   "accessories":[
      {
         "accessory":"MijiaCamera",
         "name":"Mi Camera",
         "ip":"192.168.0.105",
         "token":"6d304e6867384b704b4f714d45314a34"
      },
      {
         "accessory":"XiaomiAirPurifier3",
         "name":"Xiaomi Air Purifier",
         "did":"270033668",
         "ip":"192.168.0.108",
         "token":"5c3eeb03065fd8fc6ad10cae1f7cce7c",
         "pm25_breakpoints":[
            5,
            12,
            35,
            55
         ]
      }
   ],
   "platforms":[
      {
         "platform":"MiFanPlatform",
         "deviceCfgs":[
            {
               "type":"MiDCVariableFrequencyFan",
               "ip":"192.168.0.106",
               "token":"dd1b6f582ba6ce34f959bbbc1c1ca59f",
               "fanName":"room fan",
               "fanDisable":false,
               "temperatureName":"room temperature",
               "temperatureDisable":true,
               "humidityName":"room humidity",
               "humidityDisable":true,
               "buzzerSwitchName":"fan buzzer switch",
               "buzzerSwitchDisable":true,
               "ledBulbName":"fan led switch",
               "ledBulbDisable":true
            }
         ]
      },
      {
         "platform":"yeelight",
         "name":"Yeelight"
      }
   ]
}

For your reference!

The Mijia appliances I used are as taught above. I didn’t try the ones I don’t have. You can search on npm (homebridge-plugin XXX English name) and follow the similar logic to install and configure them!

Here are some homebridge plugins I found but haven’t tried (no guarantee they work):

  1. Xiaomi Air Purifier 1st Gen: homebridge-mi-air-purifier
  2. Mijia Smart Plug Series: homebridge-mi-outlet
  3. Xiaomi Robot Vacuum: homebridge-mi-robot_vacuum
  4. Mijia Smart Gateway: homebridge-mi-aqara

Tips

  1. It is recommended to set all Mi Home appliances to a specified/reserved IP on the router, otherwise the IP address may change, and you will need to reconfigure the config.json settings.
  2. If you find that all steps are correct but errors still occur or it keeps showing “No Response” on HomeKit, you can try again; if the issue persists, it may indicate that the plugin is no longer valid, and you need to find another plugin to connect. (You can check the GitHub issue)
  3. Function failure, slow response; this is also unsolvable, you can post an issue to inform the author and wait for an update. Since it is an open-source project, you cannot demand too much!
  4. After binding each appliance, you can start Homebridge once and then check on your iPhone to see if it works. If it does, you can terminate it with “Control” + “C”; after binding all appliances, you can restart the Raspberry Pi to let it automatically start the Homebridge service in the background after rebooting; this is what we want.

Conclusion

Additionally, you can go to "Settings" -> "Control Center" -> "Customize" to add the "Home" app, allowing you to quickly operate HomeKit from the drop-down control center!

Additionally, you can go to “Settings” -> “Control Center” -> “Customize” to add the “Home” app, allowing you to quickly operate HomeKit from the drop-down control center!

After connecting everything to HomeKit, the only word is “Awesome”! The response to switching is faster, the only downside is that I don’t have a home hub, so I can’t control it remotely. This concludes the advanced Homebridge tutorial, thank you for reading.

Back to the beginning of the article, after adding everything to HomeKit, we can seamlessly use the iOS ≥ 13 Shortcuts automation feature.

Do you want to study how the Homebridge plugin is made? It seems very interesting! So if there is a HomeBridge plugin that doesn’t meet your operational needs or a plugin is broken and you can’t find a replacement, just wait for me to study it!

Home assistant

There is another smart home platform Homeassistant that can be flashed into the Raspberry Pi for use (Note: A 2A power supply is required to start); I also installed Homeassistant to play with. It has a full GUI interface, and you can connect appliances with just a few clicks; I will study it in-depth later. It feels like another Mi Home platform, but if you have many different manufacturers’ IoT components, it is more suitable to use this.

References

  1. https://www.domoticz.cn/forum/viewtopic.php?t=52
  2. https://or2.in/2017/07/02/Homekit-and-MiJia-with-pi/#3-%E5%8F%B7%E5%A4%96-%E5%BC%80%E5%90%AF%E5%8F%AF%E8%A7%86%E5%8C%96VNC

Further Reading

  1. New Additions to Xiaomi Smart Home (AI Speaker, Temperature and Humidity Sensor, Scale 2, DC Inverter Fan)
  2. Using “Shortcuts” Automation Feature with Mi Home Smart Home on iOS ≥ 13.1 (Directly using the built-in Shortcuts app on iOS ≥ 13.1 for automation)
  3. Mi Home App / Xiao Ai Speaker Region Issues
  4. First Experience with Smart Home — Apple HomeKit & Xiaomi Mi Home (Mi Home Smart Camera and Mi Home Smart Desk Lamp, HomeKit Setup Tutorial)

If you have any questions or comments, feel free to contact me.

===

本文中文版本

===

This article was first published in Traditional Chinese on Medium ➡️ View Here



This post is licensed under CC BY 4.0 by the author.

Exploring Methods for Implementing iOS HLS Cache

Easily Create a 'Fake' Transparent Perspective Wallpaper Using iPhone