As I’m testing my new build homekit accesoires I need to manually start my Apple Homebridge based on MQTT every time I boot. So the question is: How can I automatically start Apple Homebridge based on MQTT after rebooting the Raspberry Pi Zero W.

There are many directions out there that don’t work on Raspbian. Specifically the “upstart” scripts, as Raspbian doesn’t come with upstart, and will mess things up greatly if you install it. Raspbian uses init.d. It’s fairly simple to get things going.

Create script in /etc/init.d

sudo nano /etc/init.d/homebridge

The following is an example based on starting up the homekit2mqtt service, but change the name of the script and the command to start and stop it and it would work for any command.

#! /bin/sh
# /etc/init.d/homebridge

### BEGIN INIT INFO
# Provides: homekit2mqtt
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Required-Start: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start Homekit@mqtt at boot
# Description: A simple script from https://www.studiopieters.nl Which will start / stop Homekit2mqtt at boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting Homebridge"
# run application you want to start
homekit2mqtt
;;
stop)
echo "Stopping Homebridge"
# kill application you want to stop
killall homekit2mqtt
;;
*)
echo "Usage: /etc/init.d/homebridge {start|stop}"
exit 1
;;
esac

exit 0



Make script executable

sudo chmod 755 /etc/init.d/homebridge

Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d hombridge defaults

Note: The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name. If you want to know more about creating LSB scripts for managing services, see http://wiki.debian.org/LSBInitScripts

If you ever want to remove the script from start-up, run the following command:

sudo update-rc.d -f homebridge remove

The Raspberry Pi Zero W will automatically start Apple Homebridge based on MQTT after a restart. It is hereby no longer necessary to have connected a mouse, keyboard or monitor. The Apple Homebridge based on MQTT server can be placed anywhere this way.

 

Pin on Pinterest1Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Buffer this pageDigg thisEmail this to someone
Flattr the authorShare on Reddit0Share on StumbleUpon0Share on Tumblr0Share on VKShare on Yummly0