Search

Lazy Man Joe's Ramblings

Month

August 2018

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 4/4]

Following on from PART 3

Now that Home Assistant is aware of the Garden Zones, we can “program” some automations in Node-Red.

For now I’ve only implemented a rudimentary little flow:

  • I have 4 different flows to handle each of the zones separately, but I do make sure (manually) that they’re not conflicting with each other (i.e. 1 zone’s start-time is AFTER the end-time of the previous zone, etc.)
  • As it’s winter at the moment here in South Africa, I’ve opted to only water the garden 2 x a week and for only 10 minutes in each zone.

 

My flows looks like this:

GardenPi_NodeRed

And the schedule is as follows (currently Mondays and Thursdays):

GardenPi_Zone1_Schedule

And to make it easier for me, I used a “switch”-node to split the flow based on some logic (if the payload is “on” or “off” then go route 1 or 2)

GardenPi_Zone1_SwitchNode

For the “ON” payload, I use the “call service”-node to call the switch and switch it ON (Home-Assistant handles the mqtt messaging in the background):

GardenPi_Zone1_SwitchOn

At the end of the flow I have a “msg”-node for debugging purposes, which I will probably remove in future.

GardenPi_Zone1_Debug

So a bit of a long-winded 4-part post, but wanted to capture all the aspects of the process.

Future work will include adding some “intelligence” like checking the probability of rain, possible sensors in the ground to check humidity, etc.

Anyways – it’s been LOTS of fun and a great learning experience.

 

Advertisements

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 3/4]

Continued from PART 2

With all the puzzle pieces in place, now we can make Home-Assistant aware of the Garden Zone “switches”, so we can program and use the in automations.

In the switches.yaml file (remember I split the configuration for switches out into their own file), under the platform: mqtt section I added the Garden Zones / Switches:

platform: mqtt
name: "Garden Zone 1"
command_topic: "lazyhome/garden/output/zone1/set"
state_topic: "lazyhome/garden/input/zone1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 2"
command_topic: "lazyhome/garden/output/zone2/set"
state_topic: "lazyhome/garden/input/zone2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 3"
command_topic: "lazyhome/garden/output/zone3/set"
state_topic: "lazyhome/garden/input/zone3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 4"
command_topic: "lazyhome/garden/output/zone4/set"
state_topic: "lazyhome/garden/input/zone4"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

You can name the switch anything you want, as this will be the user-friendly name in the Home-Assistant homepage.
The important bits are the command_topic and state_topic sections – these need to align to the configuration you have on your Raspberry Pi with it’s mqtt listener.

I also created some “Groups” (groups.yaml) for Home Assistant to group my different switches into logical sections:

Geysers:
name: Geysers
entities:
- switch.bedroom_geyser
- switch.upstairs_geyser
Garden:
name: Garden
entities:
- switch.Garden_Zone_1
- switch.Garden_Zone_2
- switch.Garden_Zone_3
- switch.Garden_Zone_4

Please note that the switches have “_” to replace the spaces in the names

After updating the configuration, restart HASS and your switches should show up in it’s own group 🙂

GardenPI_Zones

And that’s it !

Home Assistant is now aware of the switches AND you can switch them using the on-screen toggles (which kicks off some mqtt messages in the background, which the Raspberry Pi picks up, switching the relevant GPIO pin, which in turn switches the relay !)

Phew !

😀

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 2/4]

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.

Blog at WordPress.com.

Up ↑