This blog is to help more developer to make use of Sintron Smart device and help developer's business to grow up

Wednesday, 5 June 2019

How to use iPhone Siri Home Kit with Sintron Device. ( ST-027 Plug & ST-029 Wall switch ) -- with raspberry Pi

difficulty level: Medium

note: Sintron Device Has the version without Logo on product itself. so it's good for developer to build and sell to customers.

video for demo here:




Most of Plugs can support Amazon Alexa and Google Home. but almost non of them still can't support iPhone Siri Home Kit yet. ( June 2019 )

Sintron Device : for example ( ST-027 Plug & ST-029 Wall switch ) do have the ability to be embedded this function for iPhone Users.

this is also a good information for you to help your customer or family to build safe Smart Home. only need to use HomeKit app built-in the iOS, and combine all things there. no need to use multiple apps.

easy and quick to control.

if needed, you can also contact us to support you and customize what you need. we hope to work with you to build your customer's smart home too.

--

Requirement:

hardware:
1. Sintron Device ( ST-027 Plug & ST-029 Wall switch Series ) of course.
2. Raspberry Pi board.

knowledge:
1. some basic linux command experience.
--


Theory before we start: Sintron Device doesn't not connect to iOS device directly, so that we need to use a hub ( raspberry pi in this case ) and help us to communicate between Sintron Device and iOS. so first we will install "homebridge" software and also plugin to raspberry pi. then also use the app Sintron provided. then they will combine together.

this article would assume you are familiar with linux/raspberry pi and command line.
if you are not familiar with this, you can also purchase SD card with pre-installed system directly. then you can skip All Steps below.

buy here.( will update the link soon )


you can also download our pre-installed system and flash it to SD card directly. then you can skip Step 1 ~ Step 5.

download system file ( will update the link soon )



and of course if you would like to do it from scratch, please check below :



Step 1: turn on the Raspberry Pi with raspbian system. you can check the installation guide from official raspberry pi


*connect the ethernet cable or get wifi connected first.
* use SSH to connect to raspberry pi, so that you can copy command & paste directly. How to SSH to server from howtogeek.com.
*log in and Open terminal  ( if you are using GUI Desktop.)
*then you will see :






Step 2. install necessary software first.

in command line:
do not copy "$", this just shows it's the command.

press y & enter if you see any questions.

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install npm nodejs unzip


these might take some minutes.

Step 3: update npm & nodejs to newer & stable version and then reboot:

$ sudo npm cache clean -f

$ sudo npm install -g n

$ sudo n stable

$ sudo reboot


(ps. you can check "npm -v" and "node -v" to check the version of the npm and nodejs )


Step 4. Install the "Homebridge" and Plugin:

$ sudo apt-get install libavahi-compat-libdnssd-dev

$ sudo npm install -g --unsafe-perm homebridge

$ sudo npm install -g homebridge-http-switch

$ sudo npm install pm2 -g



Step 5. try to run "homebridge" for the first time



$ homebridge

you will see QR code ( don't do anything first ) :



ok, so far so good. let's terminate this app first by :       "control" + "c"


Step 4. Download Sintron nodejs app:


$ wget https://www.dropbox.com/s/dtqum7uyh1l4dl9/sintron_iPhone_SIri_homebridge_server.zip

(a little bit too long for a blog, don't miss the last letter "p" )

$ unzip sintron_iPhone_SIri_homebridge_server.zip




Step 5. All prepared !  Let's get them running !!


run sintron app:


$ pm2 start sintron_homebridge_server/sintron_homebridge_server.js

it would show:






Step 6. Prepare config.json file for homebridge.


before we run homebridge, we need to add a config.json file to system.




choose the example that suits the quantity you have. for example, if you have 2 pcs of Sintron Device, you can download the " 2 device config.json" 

then open it with  "plain text" editor.

REALLY IMPORTANT: You must use a "plain text" editor to create or modify config.json. Do NOT use apps like TextEdit on Mac or Wordpad on Windows. Apps like these will corrupt the formatting of the file in hard-to-debug ways. free Atom text editor is recommended.

--

the example you downloaded would look like this format.

---------


{
  "bridge": {
    "name": "Sintron Device",
    "username": "AE:72:E6:5D:1D:83",
    "port": 51826,
    "pin": "897-23-872"
  },

  "accessories": [
    {
      "accessory": "HTTP-SWITCH",
      "name": "fan",

      "onUrl": {
        "url": "http://localhost:4000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=on"
      },
      "offUrl": "http://localhost:4000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=off",

      "statusUrl": {
        "url": "http://localhost:3000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=off",
        "method": "GET"
      },

      "pullInterval": 50000,

      "debug": true
    }

  ]

}



----------

please replace the "onUrl" , "offUrl" and "statusUrl" for your own Sintron device.
( this is using one device as an example, for multi quantity, please change the "onUrl" , "offUrl", "statusUrl" one by one )


for example, if your Sintron Device turn on command is:

http://sintron.vip/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=on

then you change it to : localhost:4000

http://localhost:4000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=on

and then put it back to "onUrl", 

the same to "offUrl"

if your Sintron device turn off command is:

http://sintron.vip/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=off

-->then you change it to : localhost:4000

http://localhost:4000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=off

put it back to "offUrl" too.

and for statusUrl. you can change onUrl from : localhost:4000 to localhost:3000. 

http://localhost:4000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=on

--> change it to:

http://localhost:3000/?host=google&username=sintron&auth=81aa151057ed4cd1ba76bb6d54483092&led=D13&pin=D14&action=on

put it back to "statusUrl"


now we have the config.json customized with your Sintron device.

-

let's put it into system:




$ nano ~/.homebridge/config.json

then paste the config.json you just customized and "ctrl" + "O"  to save it.







Step 7. Get homebridge running. ( finally ! )


$ nohup homebridge >homebridge-sintron.out &

running it in background



$ cat homebridge-sintron.out

then you would see QR code again, it's running now !






1) make sure your iOS device connect to the same router as the raspberry pi.


Scan this code with your HomeKit app on your iOS device to pair with Homebridge:
Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

then you should be able to see the device show up in your HomeKit app, and you can control it now !




video for how to scan and control here:







-----

FAQ:

1) Home app shows i can't add duplicate device.
it's possible you already scanned before, so there's a record.
try to clear the record and run again:

$ sudo rm -r ~/.homebridge/persist/  


2) after some periods it doesn't work anymore.

try to restart it, and launch the apps again:

$ pm2 start sintron_homebridge_server/sintron_homebridge_server.js

$ nohup homebridge >homebridge-sintron.out &


----


for any questions, you can comment below or send email to : sales@sintron.co.uk



Share:

0 comments:

Post a Comment

Sintron

Search This Blog

Powered by Blogger.

Blog Archive

Sintron Smart Plug / Outlet with OTA ( over the air )

Have you ever wanted to upload your own software to Smart plug or Wall switch etc...?  because you might have better idea for your own Sm...

Labels