├── README.md ├── hosts ├── includes ├── .homebridge │ └── config.json └── etc │ └── init.d │ └── homebridge ├── playbook.yml ├── roles └── pi │ └── tasks │ └── main.yml └── run-ansible.sh /README.md: -------------------------------------------------------------------------------- 1 | #Homebridge Ansible Pi 2 | 3 | ![alt text](http://i.imgur.com/tT8Wa4H.jpg "HomeKit") 4 | ![alt text](http://i.imgur.com/1uO4SZL.png "Raspberry Pi") 5 | ![alt text](http://i.imgur.com/i866cOb.png "Ansible") 6 | 7 | 8 | 9 | ##Introduction 10 | HomeBridge Ansible Pi is an automated script for installing the excellent 11 | [HomeBridge](https://github.com/nfarina/homebridge "HomeBridge Githhub") package onto a Raspberry Pi. 12 | Homebridge enables IOT devices to be added and controlled by Siri that would normally not be supported by Apple's Homekit at all. These devices include: 13 | * Lockitron 14 | * Nest 15 | * Sonos 16 | * SmartThings 17 | * SoundTouch 18 | * Wemo 19 | 20 | [HomeBridge-hdmi](https://github.com/x2c/homebridge-hdmi "HomeBridge HDMI") is now automatically installed and configured as part of the set-up process. This enables you to plug your Raspberry Pi directly into your HDMI TV or AV Amp and issue comannds like "Hey Siri, turn the TV on" 21 | 22 | ##Requirements 23 | 24 | 1. Latest version of Ansible - http://docs.ansible.com/ansible/intro_installation.html 25 | 2. Latest version of Raspbian - https://www.raspberrypi.org/downloads/raspbian/ 26 | 3. Raspberry Pi (Recommended Raspberry Pi 2 Model B) 27 | 28 | 29 | 30 | ##Installation 31 | 32 | ```bash 33 | git clone https://github.com/x2c/homebridge-ansible-pi.git 34 | ``` 35 | ```bash 36 | cd homebridge-ansible-pi 37 | ``` 38 | ```bash 39 | nano hosts (modify ip address to point at your raspberry pi) 40 | ``` 41 | ```bash 42 | ./run-ansible.sh 43 | ``` 44 | ```bash 45 | SSH password: (default password raspberry) 46 | ``` 47 | 48 | ##Configure Homebridge on iOS iPhone/iPad 49 | Currently there are no official apps for adding HomeBridge devices to Apple's HomeKit. 50 | A number of third party apps are available which will enable you to add your new HomeBridge devices to Siri: 51 | 52 | * [Insteon+](https://itunes.apple.com/US/app/id919270334?mt=8 "Insteon+ HomeKit App") Price : Free 53 | * [Lutron](https://itunes.apple.com/us/app/lutron-app-for-caseta-wireless/id886753021?mt=8 "Lutron HomeKit App") Price : Free 54 | * [MyTouchHome](https://itunes.apple.com/us/app/mytouchhome/id965142360?mt=8&at=11lvmd&ct=mhweb "MyTouchHome HomeKit App") Price : $1.99 55 | * [Devices](https://itunes.apple.com/us/app/devices/id966877433?mt=8 "Devices HomeKit App") Price : $2.99 56 | 57 | Adding HomeBridge devices to Homekit the default code is **031-45-154** 58 | -------------------------------------------------------------------------------- /hosts: -------------------------------------------------------------------------------- 1 | [raspberrypi] 2 | 192.168.1.201 3 | -------------------------------------------------------------------------------- /includes/.homebridge/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "bridge": { 3 | "name": "Homebridge", 4 | "username": "CC:22:3D:E3:CE:30", 5 | "port": 51826, 6 | "pin": "031-45-154" 7 | }, 8 | 9 | "description": "Default Homebridge configuration", 10 | 11 | "accessories": [ 12 | { 13 | "accessory": "TV", 14 | "name": "TV" 15 | }, 16 | { 17 | "accessory": "AMP", 18 | "name": "Amplifier" 19 | } 20 | ], 21 | 22 | "platforms": [ 23 | 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /includes/etc/init.d/homebridge: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Start daemon at boot time 9 | # Description: Enable service provided by daemon. 10 | ### END INIT INFO 11 | 12 | dir="/home/pi" 13 | cmd="DEBUG=* /usr/local/bin/homebridge" 14 | user="pi" 15 | 16 | name=`basename $0` 17 | pid_file="/var/run/$name.pid" 18 | stdout_log="/var/log/$name.log" 19 | stderr_log="/var/log/$name.err" 20 | 21 | get_pid() { 22 | cat "$pid_file" 23 | } 24 | 25 | is_running() { 26 | [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1 27 | } 28 | 29 | case "$1" in 30 | start) 31 | if is_running; then 32 | echo "Already started" 33 | else 34 | echo "Starting $name" 35 | cd "$dir" 36 | if [ -z "$user" ]; then 37 | sudo $cmd >> "$stdout_log" 2>> "$stderr_log" & 38 | else 39 | sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" & 40 | fi 41 | echo $! > "$pid_file" 42 | if ! is_running; then 43 | echo "Unable to start, see $stdout_log and $stderr_log" 44 | exit 1 45 | fi 46 | fi 47 | ;; 48 | stop) 49 | if is_running; then 50 | echo -n "Stopping $name.." 51 | kill `get_pid` 52 | for i in {1..10} 53 | do 54 | if ! is_running; then 55 | break 56 | fi 57 | 58 | echo -n "." 59 | sleep 1 60 | done 61 | echo 62 | 63 | if is_running; then 64 | echo "Not stopped; may still be shutting down or shutdown may have failed" 65 | exit 1 66 | else 67 | echo "Stopped" 68 | if [ -f "$pid_file" ]; then 69 | rm "$pid_file" 70 | fi 71 | fi 72 | else 73 | echo "Not running" 74 | fi 75 | ;; 76 | restart) 77 | $0 stop 78 | if is_running; then 79 | echo "Unable to stop, will not attempt to start" 80 | exit 1 81 | fi 82 | $0 start 83 | ;; 84 | status) 85 | if is_running; then 86 | echo "Running" 87 | else 88 | echo "Stopped" 89 | exit 1 90 | fi 91 | ;; 92 | *) 93 | echo "Usage: $0 {start|stop|restart|status}" 94 | exit 1 95 | ;; 96 | esac 97 | 98 | exit 0 -------------------------------------------------------------------------------- /playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Ansible Playbook for configuring HomeBridge 4 | 5 | hosts: raspberrypi 6 | roles: 7 | - pi 8 | remote_user: pi 9 | sudo: yes 10 | -------------------------------------------------------------------------------- /roles/pi/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: 'Update APT package cache' 3 | action: apt update_cache=yes 4 | 5 | - name: 'Upgrade APT to the lastest packages' 6 | action: apt upgrade=safe 7 | 8 | - name: 'Install Apt packages' 9 | apt: name={{item}} state=installed 10 | with_items: 11 | - libavahi-compat-libdnssd-dev 12 | - cmake 13 | - liblockdev1-dev 14 | - libudev-dev 15 | - libxrandr-dev 16 | - python-dev 17 | - swig 18 | - git 19 | 20 | - name: 'Git clone LibCEC Platform' 21 | git: repo=git://github.com/Pulse-Eight/platform.git dest=/tmp/platform accept_hostkey=yes 22 | 23 | - name: 'Git clone LibCEC library' 24 | git: repo=git://github.com/Pulse-Eight/libcec.git dest=/tmp/libcec accept_hostkey=yes 25 | 26 | - name: 'Make build directories for LibCEC' 27 | command: "{{item}}" 28 | with_items: 29 | - mkdir -p /tmp/platform/build 30 | - mkdir -p /tmp/libcec/build 31 | 32 | - name: 'Make Install Platform library' 33 | command: "{{item}} chdir=/tmp/platform/build" 34 | with_items: 35 | - cmake .. 36 | - make 37 | - make install 38 | 39 | - name: 'Make Install LibCEC library' 40 | command: "{{item}} chdir=/tmp/libcec/build" 41 | with_items: 42 | - cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib .. 43 | - make -j4 44 | - make install 45 | - ldconfig 46 | 47 | - name: 'Remove legacy nodejs' 48 | apt: name=nodejs-legacy state=absent 49 | 50 | - name: 'Download latest nodejs' 51 | get_url: url=http://node-arm.herokuapp.com/node_latest_armhf.deb dest=/tmp/node_latest_armhf.deb mode=0600 52 | 53 | - name: 'Install lastest node' 54 | apt: deb=/tmp/node_latest_armhf.deb state=present 55 | 56 | - name: 'Install Homebridge + Plugins' 57 | npm: name={{item}} global=yes 58 | with_items: 59 | - homebridge 60 | - homebridge-hdmi 61 | 62 | - name: 'Copy Homebridge default config ~/.homebridge' 63 | copy: src='includes/.homebridge/config.json' dest='/home/pi/.homebridge/' 64 | 65 | - name: 'Copy Homebridge default config ~/.homebridge' 66 | copy: src='includes/.homebridge/config.json' dest='/home/pi/.homebridge/' 67 | 68 | - name: 'Copy Homebridge init script to /etc/init.d' 69 | copy: src='includes/etc/init.d/homebridge' dest='/etc/init.d/' mode=0755 70 | 71 | - name: 'Set homebridge to init on boot' 72 | command: update-rc.d homebridge defaults 73 | 74 | - name: 'Enable hdmi_force_hotplug' 75 | replace: 76 | dest=/boot/config.txt 77 | regexp='#hdmi_force_hotplug=1' 78 | replace='hdmi_force_hotplug=1' 79 | backup=no 80 | 81 | - name: 'Disable HDMI CEC switch to PI on boot' 82 | lineinfile: 83 | dest=/boot/config.txt 84 | line="hdmi_ignore_cec_init=1" 85 | state=present 86 | -------------------------------------------------------------------------------- /run-ansible.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ansible-playbook playbook.yml -i hosts --ask-pass --sudo --------------------------------------------------------------------------------