Documentation for MQTT-GaragePi
To control the GaragePi with MQTT, we need to install some items on the Pi. Since we installed Rasberry Pi, there is no GUI (Desktop) to use. Everything is done through command line (aka shell). You will need to either connect a keyboard and monitor to the GaragePi or use a Terminal or Putty to SSH into the device. If you are going to connect a Monitor and Keyboard, then start with step 4.
Run the following command in a terminal or putty session, where “ipaddress” is the actual IP address of your GaragePi
ssh pi@ipaddress
Run the following commands
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo reboot
sudo apt-get install supervisor
sudo apt-get install python3-pip
sudo pip install --upgrade virtualenv
cd /home/pi
virtualenv ve
. ve/bin/activate
pip install pi-mqtt-gpio
pip install RPi.GPIO
Configure the pi-mqtt-gpio app by modifying ~/pi-mqtt-gpio.yml
nano ~/pi-mqtt-gpio.yml
mqtt:
host: mqtt_broker_ip
port: mqtt_broker_port
user: "homeassistant"
password: "page2kaedaecaitei0ooqu8zeiph5jahf3Shee9aedieX2Oophae7rahtheighae"
topic_prefix: home/garage
status_topic: status
status_payload_running: online
status_payload_stopped: offline
status_payload_dead: dead
discovery: on
gpio_modules:
- name: raspberrypi
module: raspberrypi
digital_outputs:
- name: switch23
module: raspberrypi
pin: 23 #GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: switch24
module: raspberrypi
pin: 24 #GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: switch25
module: raspberrypi
pin: 25 #GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: switch26
module: raspberrypi
pin: 26 #GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
digital_inputs:
- name: sensor21
module: raspberrypi
pin: 21 # GPIO
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no
- name: sensor17
module: raspberrypi
pin: 17 # GPIO
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no
- name: sensor13
module: raspberrypi
pin: 13 # GPIO
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no
The next step is to setup pi-mqtt-gpio as a daemon so it will run when the pi is restarted. To do this, you need to create a supervisor config: /etc/supervisor/conf.d/pi-mqtt-gpio.conf
sudo nano /etc/supervisor/conf.d/pi-mqtt-gpio.conf
Enter the following
[program:pi_mqtt_gpio]
command = /home/pi/ve/bin/python -m pi_mqtt_gpio.server pi-mqtt-gpio.yml
directory = /home/pi
redirect_stderr = true
stdout_logfile = /var/log/pi-mqtt-gpio.log
Update the Supervisor using the follwoing commands:
sudo supervisorctl update
sudo supervisorctl status
To ensure the GPIO pins start up with the right levels, you need to edit /boot/config.txt by adding the following at the end of the file:
# Custom Setting for GPIO on startup
# Set GPIO23, 24, 25, and 26 to be an output set to 1
gpio=23,24,25,26=op,dh
To edit the /boot/config.txt file:
sudo nano /boot/config.txt
This completes the GaragePi side of the setup.