Introduction: Integrate Sonoff With Home App (Apple IPhone IPad IOS)

About: The MasterWalker Shop is a virtual store selling products for robotics, automation and electronic components. We are active in the market since 2011, always with the objective of guaranteeing our customers qua…

This tutorial is for people who want to use Sonoff devices with the Home app without having to change firmware and consequently maintain the original features of the module, including use with the eWeLink app, Google Home and Alexa.

Initially, this tutorial was written in Portuguese here in Brazil. I tried my best to write in English. So forgive me for any errors that may be in writing.

This instruction was divided as follows:

Step 1: Homebridge

Step 2: Plugin Homebridge eWeLink Max

Step 3: Install Plugin Homebridge eWeLink Max (Raspberry Pi)

Step 4: Install Plugin Homebridge eWeLink Max (Windows)

Step 5: Check and test Sonoff devices listed in the Home app

In the video below you can see a preview of what you will learn in this instructable:

Step 1: Homebridge

Developed by Nick Farina, Homebridge is a NodeJS server that emulates the Homekit API and makes it possible to use non-Apple certified devices with the Home app and Siri. The server is lightweight, can run on a home network and is modular, meaning it supports multiple plugins created and made available by an extremely active community in strengthening the tool.

The plugins are installed on Homebridge and most of them are intended to make Homekit compatible any non-Apple certified device. Plugins for use with Homebridge are installed directly from the NPM website.

To proceed with this instructable you will need to have the Homebridge server running. If you don't have one yet, you can follow our instructable Install Homebridge on Raspberry Pi and Windows, and once you're done, just continue the steps mentioned in this post. In this same post that teaches how to install Homebridge on Raspberry Pi and Windows, you are also taught how to install and configure the Homebridge Config UI X plugin. I recommend that you install this plugin as it facilitates server management from a browser. web.

You also need to have Sonoff devices paired and configured in the eWeLink app.

Assuming you have followed our instructable and have Homebridge running on Raspberry Pi or Windows, we will start by installing the plugin that will allow you to use Sonoff with the Home app without having to make firmware changes and maintain the original features of the module, including using eWeLink app, Google Home and Alexa.

Step 2: Plugin Homebridge EWeLink Max

The plugin in question is homebridge-ewelink-max. This plugin has the major feature that it is not necessary to change Sonoff factory default firmware, so even if linked to the Home and Siri app, you will be able to launch the module via the official board application which is eWeLink. Any device add and remove actions from your eWeLink account will automatically be reflected in your Home app to which these same devices are linked. Basically the plugin accesses your eWeLink account, checks the added devices and through Homebridge links to the Home app the devices that can be managed by the plugin.

According to the plugin developer, the tests were done only with Sonoff Basic, however, in my tests, besides Sonoff Basic I also used Sonoff Mini DIY and it worked perfectly. I also tested the Sonoff WiFi RF Bridge 433MHz for all RF devices (paired buttons and alarms) managed by it to be listed in the Home app, but I was unsuccessful. Therefore, you can continue to follow the tutorial if you have a different Sonoff than the base model or mini, but I can't tell if it will be available in the Home app when you finish the whole procedure.

The plugin only supports one eWeLink account where you can connect using your app email and password or in place of the email you can use your phone number accompanied by the country code. Each time an eWeLink is logged in an authentication token is generated and you can only have one token per user, so after linking Sonoff devices to the Home app through Homebridge, you must keep your eWeLink account logged off. Otherwise, if you try to use eWeLink at the same time as the Home app with your paired devices, both applications will be contending for a login session and neither will stay online.

Alternatively, you can create a secondary account on eWeLink and your primary account to share devices with this secondary account. Then simply use the secondary account with the plugin at Homebridge and keep your primary account online with eWeLink without the risk of having the session expired because of the plugin.

Note in notepad your eWeLink login and password that will be used in the plugin.

Go to the UUID (GUID) Generator on the WEB website and click “Get” to generate a universally unique identifier (UUID), and then copy and paste the generated UUID into your notepad. This identifier will be required for the plugin to work:

Step 3: Install Plugin Homebridge EWeLink Max (Raspberry Pi)

In Raspbian open the terminal:

Type the command line below, enter, confirm the command if prompted, and wait for the installation:

sudo npm -g install homebridge-ewelink-max

You will now need to edit config.json and enter the plugin information added to Homebridge.

If your Homebridge runs immediately after Raspbian starts, type the command below and hit enter:

sudo nano /var/homebridge/config.json

If you didn't put Homebridge to start with Raspbian, type the command below and hit enter:

sudo nano ~/.homebridge/config.json

The config.json will open:

Download the file below. Open this file, copy the contents:

platform ewelink max

Using the arrow keys, go to “platforms” and enter the code snippet copied from the file you downloaded. In the image below you can see what the “platforms” structure will look like if you already have a plugin configured in Homebridge and in the following image what it will look like if Homebridge eWeLink Max is the first plugin you are inserting into config.json:

In the first image the platform already had a plugin (Homebridge Config UI X) configured, so after the last key "}" of this plugin should be added a comma (,), enter and add the snippet referring to the new plugin, which in the this is Homebridge eWeLink Max. The second image would be the case Homebridge eWeLink Max is being the first plugin you are inserting into config.json. Just add between the brackets ”[]” of the “platforms” the configuration snippet mentioned earlier.

With the excerpt added, in "email" you must enter your eWeLink account login email, "password" your eWeLink login password and "imei" you must add the UUID you generated earlier. If you use your eWeLink login phone number, simply remove “email” and add “phoneNumber” instead. In place of the email enter your phone number starting with the “+” sign, country code, area code and phone number. For Brazil the code is 55, assuming the area code is 31 and the phone number is “1234-5678”, so for the plugin it would be “+553112345678”.

After entering the plugin settings, if you want to validate the structure of your code, just go to the JSONLint site, paste all the code from config.json, click "Validate JSON" and if everything is OK the message "Valid JSON" will be returned. . If your code has any error will be pointed to the line with the error and returned a message describing the error:

https://jsonlint.com/

To save the file press CTRL + O and then CTRL + X to close the file.

Reboot the system by typing the command below, hit enter and wait for the reboot:

sudo reboot

With the plugin installed and the Homebridge server running go to step 5 and continue.

Step 4: Install Plugin Homebridge EWeLink Max (Windows)

Run cmd (Command Prompt) as administrator:

To install the plugin type the command below into the terminal, hit enter and wait for the installation to finish:

npm -g install homebridge-ewelink-max

You will now need to edit config.json and enter the plugin information added to Homebridge. Go to the path "C:\Users\YOUR NAME OR DOCUMENTS\.homebridge" and through Notepad ++ open config.json:

Download the file below. Open this file, copy the contents:

platform ewelink max

Go to "platforms" and write the code snippet copied from the file you downloaded. In the image below you can see what the “platforms” structure will look like if you already have a plugin configured in Homebridge and what it will look like if Homebridge eWeLink Max is the first plugin you are inserting into config.json:

In the first image the platform already had a plugin (Homebridge Config UI X) configured, so after the last key "}" of this plugin should be added a comma (,), enter and add the snippet referring to the new plugin, which in the this is Homebridge eWeLink Max. The second image would be the case Homebridge eWeLink Max is being the first plugin you are inserting into config.json. Just add between the brackets ”[]” of the “platforms” the configuration snippet mentioned earlier.

With the excerpt added, in "email" you must enter your eWeLink account login email, "password" your eWeLink login password and "imei" you must add the UUID you generated earlier. If you use your eWeLink login phone number, simply remove “email” and add “phoneNumber” instead. In place of the email enter your phone number starting with the “+” sign, country code, area code and phone number. For Brazil the code is 55, assuming the area code is 31 and the phone number is “1234-5678”, so for the plugin it would be “+553112345678”.

After entering the plugin settings, if you want to validate the structure of your code, just go to the JSONLint site, paste all the code from config.json, click "Validate JSON" and if everything is OK the message "Valid JSON" will be returned. . If your code has any error will be pointed to the line with the error and returned a message describing the error:

https://jsonlint.com/

Save the file, close Notepad ++, and restart Windows.

Step 5: Check and Test Sonoff Devices Listed in the Home App

Once the Homebridge eWeLink Max plugin is installed and configured, with the Homebridge server running, simply open the Home app on your Apple device and wait for the screen to refresh with the devices the plugin can list so you can launch the same. If you already have the Home app open, close it, open it again, and wait for your devices to load. With the devices listed in the Home app, just trigger them by the app and also by Siri:

Note that in my case two devices were listed, the Sonoff Basic and the Sonoff Mini DIY:

In Sonoff Basic the status is updated in real time, regardless of whether it is triggered via Home app / Siri or by the button on the module. In Sonoff Mini DIY the status is also updated in real time, regardless of whether it is triggered via Home app / Siri or the external switch, whether on / off, pulse or three way.

In the video below you can see how the two devices work next to Home app / Siri app and also through eWeLink:

NOTE: to use eWeLink simultaneously with the Home app and Siri I did the suggested procedure at the beginning of instructable, where I created a secondary account on eWeLink and on the main account I shared the devices with this secondary account. The Homebridge eWeLink Max plugin is using the secondary account login data and eWeLink is logged in with the primary account.

If you installed the Homebridge Config UI X plugin as directed at the beginning of the post, open the web access page, click on the "Accessories" menu and see which devices are linked to Homebridge. Additionally, you can trigger devices from this page:

It's important to note that any device built into the Home app is powered locally. To be able to control Home app devices via an external network (3G / 4G connection, for example), you will need to set up an automation hub from one of the following Apple devices: iPad (running iOS 10 or later) , Apple TV (4th generation), or HomePod. This way, even away from home you will be able to remotely control your automation and IoT devices that are integrated with the Home app through Homebridge or Homekit.

Remember that adding and removing devices to your eWeLink account will be reflected in the Home app. If you are using a secondary account in the Homebridge eWeLink Max plugin, be sure to share with you the new devices added to your primary eWeLink account.

While iTead (manufacturer of Sonoff) cannot certify its product line to work with Homekit, we are using solutions like Homebridge.