Home

Awesome

<p align="center"><a href="https://github.com/MTry/homebridge-smart-irrigation"><img src="https://raw.githubusercontent.com/MTry/homebridge-smart-irrigation/master/branding/logo.png" height="160"></a></p> <span align="center">

Homebridge Smart Irrigation

<p align="center"><a href="https://openweathermap.org/"><img src="https://raw.githubusercontent.com/MTry/homebridge-smart-irrigation/master/branding/logo_white_cropped.png" height="52"></a> <a href="https://github.com/MTry/homebridge-smart-irrigation"><img src="https://raw.githubusercontent.com/MTry/homebridge-smart-irrigation/master/branding/email.png" height="52"></a> <a href="https://pushover.net"><img src="https://raw.githubusercontent.com/MTry/homebridge-smart-irrigation/master/branding/icon-256.png" height="55"></a> <a href="https://www.pushcut.io/"><img src="https://raw.githubusercontent.com/MTry/homebridge-smart-irrigation/master/branding/SCOM0927-180.png" height="53"></a></p>

verified-by-homebridge<br>npm github github<br>JavaScript Style Guide github<br>Discord Subreddit subscribers

</span>

Description

Turn any electrical irrigation valve into a smart-valve.. or run your pumps on a smart schedule based on your climate!

This Homebridge plugin exposes a multi-zone irrigation sprinkler <b>dummy control system</b> to Apple's HomeKit.

Although a <i>dummy</i>, it brings smarts of an <b>evapotranspiration</b>[<b>ET<sub>o</sub></b>] based climate/plant adaptive irrigation controller with the use of OpenWeatherMap API. All parameters can be configured from the Homebridge UI and the plugin offers granular control specific to every zone's individual requirements.

The plugin can optionally email you, and/or send you push notifications through Pushover and Pushcut, with the watering schedule it has calculated, or when a watering run is completed, along with the next 7-day weather forecast.

Added option to expose system controls to Homekit allowing a user to enable/disable irrigation, rechecks, push and email notifications from within the Home App. Associated WaterLevel Characteristic shows the % of watering cycle remaining.

Why?

Searching for an irrigation or sprinkler control plugin never showed any suitable option for my needs. The one that came closest, and is the inspiration and basis for this plugin is Tom Rodrigues's homebridge-web-sprinklers. But like many others, I didn't have the http hardware for it to control, or the inclination to rig it! What I did have access to, were some solenoid valves which I could power from a smart socket that was exposed to Homekit. So I stripped the code to just expose the dummy sprinkler accessories, reworked the irrigation logic - and then, one thing led to another.. in my quest to achieve a more granular control and incorporate more irrigation science to create a climate adaptive irrigation controller.

Basic use case..

  1. Configure the plugin to expose the required number sprinkler accessories(zones)
  2. Use the Eve app or another Homekit controller app to configure ANY other smart plug or outlet in your Homekit ecosystem to follow the state of the above exposed sprinklers
  3. The smartplug/outlet/valve in their simplest configuration could be just driving the power of any solenoid valve that controls watering to a zone

Installation

  1. Install Homebridge
  2. Install this plugin:
    • Homebridge Config UI X: Search for homebridge-smart-irrigation plugin and install
    • Manually: Run sudo npm install -g homebridge-smart-irrigation from the terminal
  3. Sign up at the OpenWeatherMap website and retrieve your API key (if you want adaptive control). The free tier allows 1000 API calls a day and this plugin will make no more than a couple on any day!
  4. Gather the mean daily Solar Radiation figures for your location in kWh/day. Please read the settings section for more details
  5. Configure the settings
  6. Use the Eve app or any other Homekit controller app to setup automations for your smartplug or outlet to follow the state of the zones exposed by the plugin

Operating Principle

One of the primary factors affecting the water demand of plants is <b>evapotranspiration</b>, also denoted as <b>ET<sub>o</sub></b> and expressed in <i>mm</i>. While the subject of irrigation is one of extensive global research and there is no end to the extent of complication one can end up with, this plugin chooses to focus on three - <b>ET<sub>o</sub></b>, <b>local rain</b> and the <b>crop characteristics</b> of each of the zones configured.

<b>ET<sub>o</sub></b> is calculated using the <i>Penman-Monteith Evapotranspiration (FAO-56) Method</i>. Those interested in a deeper understanding of the principles may head to this excellent resource of FAO. The factors used include the following <b><i>(daily)</i></b>:

  1. Min/Max Temperatures
  2. Mean RH
  3. Wind speed
  4. Shortwave Solar Radiation <i>[more on this later..]</i>
  5. Atmospheric Pressure (barometric)
  6. Latitude
  7. Elevation
  8. Julian day

<b>Rain</b> is derived from OpenWeatherMap API along with some of the factors above using the latitude and longitude configured.

<b>Crop characteristics</b> use some of the understanding gained from the website of University of California, Division of Agriculture and Natural Resources and particularly from this document for calculating drip irrigation schedules. Specifically, it utilises the following based on the conditions of the particular zone being irrigated:

  1. Crop coefficients [0.1 - 0.9] based on the type of plants Read here!
  2. Planting Density [0.5 - 1.3]
  3. Exposure Factor [0.5 - 1.4] based on the zone's microclimate

Additionally, information about the number of drip emitters, their discharge rate, area irrigated and efficiency is considered with the above factors.

Operating Logic & Scheduling

If masterDisable is not checked, the plugin will calculate the total watering durartion and check if watering can be completed today before sunrise or by the time as specified in sunriseOffset. If not, it will schedule the irrigation for the next day. Regardless of masterDisable it will gather the weather information and also send a notification email if emailEnable is set.

Forecasted low and high temperature higher than their respective thresholds must be met for the day being scheduled.

If adaptive watering is disabled for a zone, but scheduling remains enabled, the zone will be watered for the number of minutes specified by defDuration and not factor any other calculations.

The plugin schedules asynchronous zone watering - cycling sequentially through all the scheduled zones needing water one at a time and repeats the process the number of times specified by cycles.

Start times will vary daily as a result of changing sunrise times as well as the calculated watering time based on the weather factors.

recheckTime instructs the plugin to reassess the watering times based on the most current forecast available 15, 30 or 60 minutes prior to the scheduled run - if this is of no use to you set it to 0. But for many living in tropical regions where climate modeling is far too complex to give accurate forecasting, this can be helpful as the forecasts change frequently or significantly.

  1. Gather weather forecast for the next 7-day period
  2. Using the above and Solar Radiation data, calculate projected <b>ET<sub>o</sub></b> for the next 7 days
  3. If the zone is enabled & adaptive, calculate the total <b>ET<sub>o</sub></b> until the next watering day
  4. If rainFactoring is enabled, calculate the total projected rainfall till the zone's next watering day
  5. Calculate the net irrigation requirement of a zone based on total <b>ET<sub>o</sub></b> and total rain till the zone's next watering schedule
  6. Calculate zone specific time required based on that zone's irrigation infrastructure and crop profile
  7. Schedule the watering run and send notification email if emailEnable
  8. Reassess recheckTime minutes before the scheduled run

Example config block:

{
            "accessory": "SmartSprinklers",
            "name": "Irrigation",
            "exposeControls": true,
            "verbosed": true,
            "masterDisable": false,
            "recheckTime": 15,
            "latitude": 25.009243,
            "longitude": 77.73491,
            "altitude": 390,
            "keyAPI": "yOuR_OWM_key",
            "cycles": 2,
            "sunriseOffset": 0,
            "lowThreshold": 8,
            "highThreshold": 18,
            "emailEnable": true,
            "senderName": "💦 Irrigation Control",
            "senderEmail": "someone@yourmail.com",
            "sendTo": "someone@yourmail.com",
            "smtpHost": "smtp.gmail.com",
            "smtpPort": 587,
            "portSecure": false,
            "userID": "someone@yourmail.com",
            "userPwd": "password",
            "pushEnable": true,
            "userPO": "your---user---key",
            "tokenPO": "your---app---token",
            "devicePO": "iphone",
            "priorityPO": 0,
            "soundPO": "pushover",
            "pcEnable": true,
            "pcKey": "abcdXXXXabcd",
            "pcDevices": "iPad,iPhone",
            "pcWeatherChecked": "Test Checked",
            "pcWeatherCheckedSound": "system",
            "pcWateringStart": "Test Start",
            "pcWateringStartSound": "system",
            "pcWateringEnd": "Test End",
            "pcWateringEndSound": "jobDone",
            "JanRad": 5.4,
            "FebRad": 6.3,
            "MarRad": 7,
            "AprRad": 7.3,
            "MayRad": 7.2,
            "JunRad": 5.7,
            "JulRad": 5,
            "AugRad": 5.1,
            "SepRad": 5.5,
            "OctRad": 5.7,
            "NovRad": 5.2,
            "DecRad": 5,
            "zones": [
                {
                    "zoneName": "Flowerbed",
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true,
                    "defDuration": 30,
                    "maxDuration": 60,
                    "rainThreshold": 2.5,
                    "tweakFactor": 100,
                    "dripLPH": 8,
                    "dripNos": 23,
                    "dripArea": 2.7,
                    "efficiency": 100,
                    "cropCoef": 0.6,
                    "plantDensity": 1.1,
                    "expFactor": 1,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Sunday",
                        "Monday",
                        "Tuesday",
                        "Wednesday",
                        "Thursday",
                        "Friday",
                        "Saturday"
                    ]
                },
                {
                    "zoneName": "Pots",
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true,
                    "defDuration": 10,
                    "maxDuration": 30,
                    "rainThreshold": 2.5,
                    "tweakFactor": 100,
                    "dripLPH": 2,
                    "dripNos": 1,
                    "dripArea": 0.05,
                    "efficiency": 100,
                    "cropCoef": 0.6,
                    "plantDensity": 0.5,
                    "expFactor": 0.9,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Sunday",
                        "Tuesday",
                        "Thursday",
                        "Friday"
                    ]
                }
            ]
        }

Primary Setup

Expose Controls - exposeControls - exposes up to 5 additional related switch services allowing a user basic control of the system from within the Home App:

These switch settings are persistent across plugin/Homebridge restarts, so you shouldn't have to reset your preferences in the Home App!

KeyDescriptionDefault
nameName that appears in the Home appN/A
exposeControlsExpose controls to Homekittrue
verbosedVerbose Calculations and Extended Climate datatrue
masterDisableDisable scheduling all irrigationfalse
recheckTimeReassess - minutes before runtime0
cyclesNumber of cycles per watering run2
sunriseOffsetMinutes before sunrise that watering should get over by0
lowThresholdSkip scheduling when forecasted minimum temperature falls below this5
highThresholdSkip scheduling when forecasted maximum temperature stays below this10
keyAPIYour OpenWeatherMap API KeyN/A
latitudeEnter the latitude in decimals including '-' if in the southern hemisphereN/A
longitudeYour decimal longitudeN/A
altitudeEnter the altitude in meters0

Email Notifications Setup

Currently this supports basic authentication. If using Gmail, you will need to go to the security settings of your account to enable less secure app access. It might be best to create a specific ID for this purpose to avoid security risks to your main account!

KeyDescriptionDefault
emailEnableEnable Notificationsfalse
senderNameSender NameN/A
senderEmailSender Email IDN/A
sendToReceiver Email IDN/A
smtpHostSMTP HostN/A
smtpPortSMTP PortN/A
portSecureSecure Portfalse
userIDSMTP UsernameN/A
userPwdSMTP PasswordN/A

Pushover Notifications Setup

Push notifications using Pushover are supported.

KeyDescriptionDefault
pushEnableEnable Push Notificationsfalse
userPOYour user keyN/A
tokenPOYour application tokenN/A
devicePOReceiving devicesall
priorityPOMessage Priority0
soundPONotification soundpushover

Pushcut Notifications Setup

Push notifications using Pushcut are supported. While HomeKit automations and shortcuts can always be triggered based on service or zone states, this opens up a host of possibilities! Do note that this operates in a slightly different manner compared to Pushover. Notifications are sent for the following events:

This also meaans that on completion of a watering run, 2 notifications Weather Check & Watering End will be sent.

KeyDescriptionDefault
pcEnableEnable Pushcut Notificationsfalse
pcKeyYour API keyN/A
pcDevicesDevice list seperated by comma - WITHOUT SPACE after comma!all
pcWeatherCheckedYour "Weather Checked" notification nameN/A
pcWeatherCheckedSoundNotification soundsystem
pcWateringStartYour "Watering Start" notification nameN/A
pcWateringStartSoundNotification soundsystem
pcWateringEndYour "Watering End" notification nameN/A
pcWateringEndSoundNotification soundjobDone

Monthly data of Mean Daily Solar Radiation [kWh/day]

There are several sources but the one that I used is Weatherspark. Search for your location. Scroll to the bottom of the page to the Solar Energy section and note the figures for each month(the months are clickable!) in kWh/day which is the daily mean figure for the month. Feel free to use an alternate source that you trust but keep in mind the unit of measurment - kWh/day!

Going forward, it will be great to extract live daily shortwave radiation data/forecast through an API instead of relying on historical averages.. hopefully will get there soon!

KeyDescriptionDefault
xxxRadMean Daily Solar Radiation [kWh/day] for the month xxx6

Zones setup

This is where multiple zones can be configured - with a limit of 16 zones at the moment.

Crop Coefficient - Read here for reference!<br> This is based on the crop type or species and their water needs. [0.1 - 0.9]

Planting Density<br> Low—sparse: 0.5 - 0.9<br> Average—moderate coverage: 1<br> High--complete coverage: 1.1 - 1.3<br>

Exposure Factor<br> The microclimate or exposure factor [0.5 - 1.4]<br> Average--open field: 1.0<br> Low--moderate wind, part sun: 0.5 - 0.9<br> High--stronger winds and greater exposure: 1.1 - 1.4<br> A protected, shady location would use a lower factor.

KeyDescriptionDefault
zoneNameFriendly zone nameN/A
enabledZone Enabledtrue
adaptiveClimate Adaptive Zonetrue
rainFactoringFactor rain amount in watering & respect the set threshold to skip irrigation for this zonetrue
defDurationDefault zone duration in minutes when not adaptive [max 180]20
maxDurationMaximum duration settable in minutes [max 180]30
rainThresholdRain Threshold[mm] above which watering skipped for this zone2.5
tweakFactorThe human factor to tweak proposed watering in % [max:200]100
dripLPHDrip emitter discharge rate in LPH (of a single emitter)2
dripNosNumber of drip emitters used in this zone1
dripAreaIrrigation area in m<sup>2</sup>1
efficiencyIrrigation system efficiency - usually 90% for drip90
cropCoefCrop Coefficient [0.1 - 0.9]0.5
plantDensityPlantation Density [0.5 - 1.3]1
expFactorExposure Factor [0.5 - 1.4]1
wateringWeekdaysWeekdays to water - at least 1!ALL
wateringMonthsWatering Months - uncheck to skip watering in that monthALL

Notes & Suggestions

Way forward..

Support/Contribution

A ⭐️ star would be great!

I dont have a great deal of programming experience so the biggest help and contribution you can make is helping with the code or "Way forward.." items!

If financial contribution is on your agenda, may I humbly redirect you to Homebridge which makes this community possible. Also consider supporting several fine developers who offer an incredible amount of their time and effort in supporting the community and creating extraordinary plugins.