So in GardenPi – PART 1 I covered the hardware & software configs to get going, but that’s not all yet 🙂

We now have a Raspberry Pi running MQTT and we can switch the GPIO pins by sending messages on the queue.

Next steps:

Connect the pins from GPIO to the relay board

This was fairly easy as the 8 port relay board I used had small pins I could connect directly via small cables from the GPIO pins
As the board also make use of 5V, I used the PWR connector (PIN 2 [5V] and PIN 6 [GND] on the Raspberry Pi) to power the relay board.
I would only be using 1 of the relays at a time, so the power usage will be minimal to draw power directly from the Raspberry Pi.

gardenpi-test-before-boxing.jpg

Make sure MQTT starts at power-on of the Raspberry Pi

To make sure we have a consistent experience, we need to make sure MQTT is started on power-on / reboot of the Raspberry Pi.
I used Supervisor for this as it makes it much easier to set up items which need to start when the Raspberry Pi is restarted.
They cover the configuration of Supervisor in the Pi-MQTT-GPIO setup instructions and I followed it – except I DID NOT set up a virtual environment, as my Raspberry Pi will be dedicated to it’s job.
Basically you install Supervisor;
Then create a /etc/supervisor/conf.d/pi-mqtt-gpio.conf file with your config information for pi-mqtt-gpio [/home/pi/config.yml].
My pi-mqtt-gpio.conf looks like this:

[program:pi_mqtt_gpio]
command = /usr/bin/python -m pi_mqtt_gpio.server /home/pi/config.yml
directory = /home/pi
redirect_stderr = true
stdout_logfile = /var/log/pi-mqtt-gpio.log

and my config.yml file looks like this:

mqtt:
host: 192.168.xxx.xxx
port: 1883
user: “xxx”
password: “xxx”
topic_prefix: lazyhome/garden

gpio_modules:
- name: raspberrypi
module: raspberrypi

digital_outputs:
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
initial: low

digital_inputs:
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

4 Zones, each with settings for digital_output and digital_input.

OK – so now hardware connected and Raspberry Pi will start the PI-MQTT-GPIO listener on power-up / reboot.

Connecting the sprinklers

As I was basically replacing the controller for the sprinklers I already had in the garden, all I did was connect each of the Zones’ solenoids/valves to the relay board.
It’s fairly straightforward as you just have to remember the relay is a switch and you need to see whether you’re going to use the “Normally Open” [NO] or “Normally Closed” [NC] side of the relay. (Normally Open would mean that the switch is NOT switched on by default and when you trigger the relay, it will close the circuit; i.e. switch things ON – for Normally Closed it’s the other way round 🙂 )
I used “Normally Open” side of the relay as I wanted the Raspberry Pi to actually switch the solenoid on, which will open the valve and let the water through.
The solenoids make use of 24V AC and I already had a transformer to power them – so re-used that.

rainbird_hv

End result was enclosing the Raspberry Pi and relay board in a small housing, connected to the sprinklers in the garden.

GardenPi-Endresult

Next part we go to Home-Assistant to set up & config.

Advertisements