HomeKit

Install HomeKit Server in Raspberry Pi

Install node.js, npm, node-gyp and other things we need:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install nodejs npm git-core libnss-mdns libavahi-compat-libdnssd-dev

sudo npm config set registry http://registry.npmjs.org/

sudo npm install -g node-gyp


pi@raspberrypi:~ $ node -v

v0.10.29

pi@raspberrypi:~ $ sudo su -

root@raspberrypi:~ # apt-get remove nodered -y

root@raspberrypi:~ # apt-get remove nodejs nodejs-legacy -y

root@raspberrypi:~ # apt-get remove npm -y # if you installed npm

root@raspberrypi:~ # curl -sL https://deb.nodesource.com/setup_5.x | sudo bash -

root@raspberrypi:~ # apt-get install nodejs -y


Install HAP-NodeJs. Clone the HAP-NodeJS project:

git clone https://github.com/KhaosT/HAP-NodeJS.git

Go into the directory where you cloned it:

cd HAP-NodeJS


npm install node-persist --unsafe-perm

npm install mdns --unsafe-perm

npm install debug --unsafe-perm

npm install ed25519 --unsafe-perm

npm install mqtt --unsafe-perm

npm install nan --unsafe-perm

npm install socketwatcher --unsafe-perm

npm install bignum --unsafe-perm

npm install srp --unsafe-perm

npm install curve25519-n --unsafe-perm

npm install ip --unsafe-perm

npm install decimal --unsafe-perm


npm rebuild

Run the server:

sudo node Core.js

All accessories must be at folder HAP-NodeJS/accessories. See in the folder the examples.

Install Mosquitto - MQTT Broker

cd /

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

sudo apt-key add mosquitto-repo.gpg.key


cd /etc/apt/sources.list.d/

sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list

or

sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list


sudo apt-get update

sudo apt-get install mosquitto


sudo nano /etc/mosquitto/mosquitto.conf

# add this two lines for websocket support

listener 1884

protocol websockets


systemctl start mosquitto

systemctl enable mosquitto

Install lgtv2mqtt - MQTT for LG

### Install mqtt for tvlg

npm install -g lgtv2mqtt


#### Adjust parameter t : ip lg tv

cd /usr/local/lib/node_modules/lgtv2mqtt


sudo nano config.js


#### Install pm2

sudo npm install -g pm2


pm2 start lgtv2mqtt


#### Pm2 adjust for boot startup

pm2 startup systemd


sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi


pm2 save


pm2 list