If you’ve been following the various episodes on building a Smart Home, you’ll know we’ve managed to make everything pretty smart. But we’ve only really done things inside the home, now (if you’re lucky enough) it’s time to make my garden smart…
I know what you’re thinking! What else could you honestly do in a garden to make it smart? Add some funky lights, a overpriced robot lawnmower? There isn’t a lot you can do… WRONG! 😂
I don’t have the budget for a 4 figure robot lawnmower but I have spent some of this year growing some plants in our raised beds and although you could call this lazy, automating the watering of the plants is a challenge I fancied… so here goes!
Let’s start with the equipment needed…
- An outside tap (kinda mandatory)
- Optional Tap splitter (I used this)
- A hosepipe (also kinda mandatory)
- A zigbee or z-wave enabled valve (I used this)
- Male-Male hozelock adapter (I used this)
- Irrigation components (I used this)
- OpenWeatherMap
Let’s start off with what I was trying to achieve here, and I’ll preface this by saying I am in no way green-fingered, nor am I am expert in how much water each individual plant needed or the next Monty Don (for you gardening fans!).
All I wanted is the planets to be watered at the base (watering leaves isn’t good I’m told), watered only when they needed to be (i.e. when it hadn’t been raining and rain wasn’t due), not watered in direct sunlight and watered automatically without my brain needing to remember!
This idea came about when I noticed on reddit that OpenWeatherMap was able to predict rainfall, so like every good geek, I went about researching how I could achieve this.
Putting the hardware together
First off, I bought a tap splitter to still allow me to use a hose pipe (to wash the car, engage in water fights, etc) at the same time as my irrigation system was operational. This was super cheap here in the UK, less than £15.
Next was £30 on the smart valve, zigbee and battery controlled which simply screwed on to one of the outputs from the tap splitter (with a bit of tpe tape). I then connected the hose to the smart valve, hiding it behind the edge of the garden and under the soil to the raised beds.
From there, a hozelock end and a male-male adapter connected it to the irrigation kit. This gave me the option to disconnect it should I want to, and replace the irrigation kit, or extend the hose easily should I need to.
From there, it’s just a matter of putting together the irrigation kit together cutting the pipe to size to align with the base of your plants. This took me no more than an hour.
Getting Started with OpenWeatherMap
OpenWeatherMap is a service which essentially keeps track of the weather for your specific location – the history, the current and forecasting. When I say ‘weather, I don’t just mean whether its going to be sunny, overcast or raining – it goes into serious detail. Once integrated you get sensors giving the following detail:
- Cloud coverage (%)
- Condition (cloudy, clear sky, etc)
- Dew Point (in Celcius)
- Feels like temperature (Celcius)
- Humidity (%)
- Precipitation kind
- Pressure (hPa)
- Rain (mm per hr)
- Snow (mm per hr)
- Temperature (Celcius)
- UV Index
- Visibillity (Meters)
- Weather (few clouds, etc)
- Weather code
- Wind bearing (degrees)
- Wind speed (in km/h)
As you can see, massives of detail, and lots you can do automation on. For the purposes of this though, I’m only really bothered with the “Rain mm per hour” sensor.
Installation
First things first, head over to openweather.org, you’ll notice if you scroll down, some detail on their ‘One Call API 3.0’ that gives 1000 API calls a day for free. Thats what we’re going for.
Anyway, click ‘Sign In’ in the top left and then Create an Account. Provide the detail required and log yourself in. Once logged in, click on API on the top bar, and then click ‘Subscribe’ for the One Call API 3.0. You will need to provide payment detail here, but this is purely if you intend to make more than 1000 calls per day. Once that is complete, you will recieve an email within a few mins confirming. It can take an hr or so for this to activate with my experience, but people have seen it being active within as little as 5 mins.
Next, we need to go over to our Home Assistant console and get the openweathermap addon. This, like installing all add-ons, is super simple.
If you visit this handy link, you will see a link to install the add-on straight into your Home Assistant instance or you can go to Settings > Devices and Integrations and then click on the ‘Add Integration’ button in the bottom right hand site and search for OpenWeatherMap.
You’ll then be prompted to provide the API key, the latitude and longitude of your location (I found it to be prepopulated) and then select v3.0 for the mode. There are previous versions of this API, but they were deprecated in June 2024 (article here). Once you’ve done that, you’ll be able to click into the integration and see a number of entities
The Automation
So, it’s time for the interesting bit… once you’ve added your smart valve to Home Assistant (in the same way every other device is added) and configured solcast (see this blog on solar automation) then you’re good to go
Here is my configuration:
alias: "Action: Irrigation System"
description: ""
trigger:
- platform: sun
event: sunset
offset: "+1"
condition:
- condition: and
conditions:
- condition: template
value_template: >-
"{{
state_attr('weather.openweathermap','forecast')[0]['precipitation'] < 5 }}"
- condition: template
value_template: >-
"{{
state_attr('weather.openweathermap','forecast')[1]['precipitation'] < 5 }}"
action:
- action: switch.turn_on
target:
entity_id:
- switch.outside_tap_switch
data: {}
- delay:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
- action: switch.turn_off
target:
entity_id: switch.outside_tap_switch
data: {}
mode: single
Let’s walk through this configuration and focus on the logic of what we’re trying to do here.
Firstly we need to essentially control the zigbee smart value on and off once a day and its usually better to water a garden without direct sunlight, so the trigger waits until 1 hour after the sun has set.
Next is looking at the condition. Essentially what this is doing is using an AND to ensure that 2 conditions are true. Both conditions use the openweathermap service, the first of whichis looking at forecast [0], essentially today’s forecast and seeing if there has been less than 5mm of rain for that day. The second condition is the same, but looking into the future (the [1] denotes the next day, and checking whether or not less than 5mm of rain is expected to fall.
If both of these conditions are true, then we open up the outside tap (which is the entity for the smart water valve) and turns it on. There is then a 15 minute delay to allow the irrigation system to do its job, and then an action to turn off the the smart water valve.
I’ve been testing this for a few weeks and its working really well. I suspect, depending on the irrigation system you are using, you may need to play around with how long you’re keeping the valve open (as you don’t want to flood the plants), but this seemed like a good starting point for me,
I’ve also written a second automation, which essentially notifies me in the event that the valve has been open for more than 20 minutes. Although this hasn’t been triggered yet, I’ve heard some stories of particularly smart valves not being reliable and I didn’t want a huge water bill, nor killing every plant in my raised beds! For reference, this automation is below
alias: "Notification: Irrigation System"
description: ""
trigger:
- platform: device
type: turned_on
device_id: 1ecfce417e32be7d3bd5af41514ee6a8
entity_id: 6d7888ac760a0fd9f0570fe7255be02b
domain: switch
for:
hours: 0
minutes: 20
seconds: 0
condition: []
action:
- action: notify.mobile_app_sams_iphone
data:
message: Irrigation system overruning
mode: single
Hopefully you can see from the above how simple it is to create a system to simply water your plants without your involvement, and I’d argue is more efficient than you – as it knows when its going to rain. Which, unless you are some type of Soothsayer, then is probably a bit smarter 😉
Hope you enjoyed this, catch you in the next one!