We currently have an off-the-shelf garden watering solution [Hunter], but I’d like to have more control of when, etc. the irrigation is switched on.
I used the following items in my solution:
- Raspberry Pi 2 B+ [using a 16GB SD card]
- Raspberry Pi Wifi Dongle
- 8 Port Relay board
I first started prepping my Raspberry Pi and because I’ll be running it as a headless solution, I used the latest Rasbian Lite OS [download here] (Raspbian Stretch) which doesn’t have the UI and you configure all via the command-line
- Using Etcher, I wrote the image onto the 16GB SD card
- Take your SD card and boot up the Raspberry Pi
- Although I am going headless, I used a keyboard and screen to configure the base OS – I need a way to configure the Wifi and the easiest is when you use raspi-config.
- I configured the following once the 1st boot-up was done:
- Configure your locale, timezone and keyboard layout [I use the en_ZA.UTF-8 locale settings and US keyboard layout]
- Also configure your Wifi settings (SSID & Password, Wifi Country)
- Change the network name of your Raspberry Pi (mine’s called GardenPi)
- I also updated the password for the default pi user (default password is “raspberry” & it’s a good idea to change it 🙂 )
- I then forced an update in the locale file (I’ve had some issues in the past and found if you force it, things work better)
sudo nano /etc/default/locale
- Add the following:
- I also enabled SSH as I will be using SSH to manage the RaspberryPi in future.
- Reboot your Raspberry Pi, log in using the pi user and the new password you configured.
- Check your ip address
- My result showed my wlan0 adapter on IP 192.168.2.150
- You can now make this IP address (192.168.2.150) static on your router to ensure you can easily “find” your raspberry pi when you want to manage it using ssh
- I tested my ssh configuration from my Macbook
- As a last step, I always check whether the latest updates are installed on my raspberrypi
sudo apt-get update
sudo apt-get upgrade
Now you can move on to the software installation !
OK, we 1st need python installed
sudo apt install python-pip
Once python is installed, you can install PI-MQTT-GPIO (it will install MQTT as part of the setup] (more details here)
pip install pi-mqtt-gpio
As I already have MQTT running as part of the rest of my Home-Assistant.io setup, I will now only have to configure pi-mqtt-gpio to publish/subscribe to the MQTT messages.
Update your config.yml file with the necessary info, my info below (with some passwords hidden 🙂 )
NOTE – I’m only showing Zone 1 & Zone 2 settings (output & input)
- name: raspberrypi
digital_outputs: #used to send commands to the GPIO pins
- name: zone1
pin: 5 #GPIO pin number - not the board pin, but the GPIO pin
initial: low # This optional value controls the initial state of the pin
retain: yes # This option value controls if the message is retained.
- name: zone2
digital_inputs: #used to read status from GPIO pins
- name: zone1
- name: zone2
The GPIO pins are referenced as per the following layout:
So to test PI-MQTT-GPIO, you can run it in console mode (running it from the /home/pi folder):
python -m pi_mqtt_gpio.server config.yml
It should show you connecting to the MQTT server, and then subscribing to the messages, etc.
- Raspberry Pi running Rasbian Stretch Lite, with wifi dongle
- PI-MQTT-GPIO installed (using python & pip)
In PART 2 we’ll bring is all together in Home Assistant.