Archive for the ‘Debian’ Category

So carrying on with my sprinkler controller project I need an easy way to run things on the 1st Monday of a month and the 3rd Monday and only then.  Hmmm, I can do that with cron by looking up the dates and entering each day but that is a manual process to look that up and then enter 24 entries in the crontab…. Must be a better way so I go surfing the Internet and what do I find but a nice bash script called run-if-today.  You feed it the day of the week and what week of the month you want the entry to run. Perfect  makes the crontab 2 lines vs 24 lines!

# m h dom mon dow command
00 06 02 06 * sudo /home/pi/bin/
00 06 16 06 * sudo /home/pi/bin/
00 06 07 07 * sudo /home/pi/bin/
00 06 21 07 * sudo /home/pi/bin/
# etc, on and on until the end of the year


# First monday of month jobs
00 06 * * 1 run-if-today 1 Mon && sudo /home/pi/bin/
# Third monday jobs
00 06 * * 1 run-if-today 3 Mon && sudo /home/pi/bin/

Much better, it will run forever on the first and third Monday. Yea.

So credit where credit is due: I found this on github cron-last-sunday it’s under an MIT license and Copyright (c) 2014 Manuel Gutierrez.  Nice work.  I had a friend Debianize the script into a nice easily installable Debian package, which I need to figure out where to stash it so others can install it on their RPi, because it really simplifies using cron for certain conditions.


A New Project

Posted: June 2, 2014 in Debian, General, Hacking, Hardware, Raspberry PI, RPi, Software
Tags: ,

A New Project – Water Sprinkler Controller

I find myself starting a new project not necessarily because I want to but because of our local three year drought and the need to water my lawn under Stage 3 watering restrictions. Unfortunately, my sprinkler controller finally gave up the ghost. Sounds simple doesn’t it? Simply order a new controller off of ebay, amazon or head down to the local big box hardware store Lowes or Home Depot and buy a replacement. After all there are at least 5 or 6 different units that one can buy for under $100 USD.

Ah, well that is where the drought comes in, and the Stage 3 Watering Restrictions. You see, because of the drought we are only allowed to water every other week on a specific day; on top of that we are not allowed to have any run off into the street. This presents several problems to an off the shelf sprinkler controller: 1) Everyone I’ve found for under $300 works on a weekly pattern, and does not have a specific calendar day or the ability to water every other Monday at 06:00 and be done by 10:00 and if not done kill the water anyway as it’s a $200 fine the first time you water past 10:00 AM and $1000 the second time, progressively getting more expensive; 2) Our soil is mostly clay and water soaks in slowly. So you really need to water in short cycles, wet the ground and then move on to the next zone and keep doing it until you have gotten enough water into the ground without run off. Now some of the $300 units can do this but still don’t have the monthly scheduling ability.

So I’m stuck, either I fix this with a new unit that does not really do what I need thereby forcing me to go into my garage every time I have to water and set off a manual cycle, which seems a bit ridiculous. If I’m going to spend the cash to get a new system I want it to be automatic, not be stuck in the same manual cycle I’ve been in for more then a year as there is no end in sight in terms of the drought1. My other choice is to do the entire thing manually with jumper wires and stand in my garage for 2 hours manually activating each zone by hand and then switching to the next zone as needed, yea, like I have so much spare time in my life that I’m going to do that every two weeks!!!!

1And as it turns out my grass is nicely green even with the watering every 2 weeks so even of the drought breaks I’m unlikely to go back to the weekly watering schedule, I mean why waste water and money (I have to pay for city water to water the grass).

What Features do I want/need

So seems like the only think I can do at this point is to hack something together and make my own sprinkler controller from scratch. 🙂 So what do I want in a sprinkler controller1:

1Your list might vary from mine but this will be an open source project and as such feel free once the code is “over the wall” to add other features or accelerate some.

  1. Friendly user interface, web based so you don’t need to stand in the garage in 110f weather programming the stupid thing system.
  2. Can set any interval, daily, every 2nd day, every 3rd day, every 4th day, every 5th day, every 6th day, every 7th day, weekly, monthly, semi-monthly, annually, or a list of calendar days.
    1. Can set start time and hard end (stop) time
      1. If hard stop time is set system will not allow water to flow after that time.
      2. If hard stop time is set, when programming a “???? set” if you ask for more water then the start time and end time would allow the system will warn you and suggest a new start time that will allow all water to be sent and stop watering by the hard end time.
  3. Real Time Clock so it knows what today is.
  4. Zones can be scheduled independently from each other. So I could set zone 1 – 9 to water every other week according to the local rules, but zone 10 (which is a soaker hose on my foundation) can be run every other day as needed to keep the clay moist near my foundation. 1
  5. Each zone can be set for total length of watering, independent of other zones.
  6. Duration of water applied to a zone. If the duration is shorter then the length of time set for the zone the zone will be watered for the duration and the system will keep coming back to the zone until all water has been delivered. This will keep run off from happing with our clay soil.
  7. Might be nice if durations can be set by zone but this would be an enhancement.
  8. Use any standard off the shelf parts for a sprinkler system available at your local hardware store. No requirement for expensive special water control valves or other specialty hardware. Everything low voltage (most sprinkler systems today use 24VAC as their control voltage on zone valves), no 120/220 in the sprinkler control box.
  9. The ability to easily skip a zone on a once time basis in case you discover a sprinkler head is broken but you want to water the rest of the zones.
  10. Connected to my house network so I don’t have to go digging into my garage to know what is going on. Additionally would be nice to be able to do testing of the system remotely when I’m watering in the yard looking at a zone to make sure it’s working correctly. While not hard it’s a pain to have to go back into the garage to trigger each zone and then walk back to the zone to see what works and is broken several times as I fix issues.2
    1. Expand this to remote control from anywhere in the world via the Internet. Clearly need SSH/SSL/VPN security setup so that bad things can’t happen easily.
  11. Expandable, I have nine (9) zones and I can see adding a tenth (10th) zone soon (soaker hose).
  12. Rain Sensor, including volume of rain fall, so if it rains hard enough 24-48 hours before watering time, cancel the scheduled watering.
  13. Ground moisture sensors, multiple zones so you can if desired analyze by zone the need for water.. Would allow skipping areas if they already are moist enough and don’t need to be watered.
  14. Integration to Internet weather sources so you can see if it rained yesterday or is about to rain tomorrow.
  15. Display on the front panel of what the system is doing now or about to do. Time and date displayed when doing nothing else.
  16. Permanent memory so watering instructions are not lost on power fail.
    1. Not require battery backup, I really dislike 9VDC battery backup systems, the battery always dies at the wrong time.
  17. System resume after power loss, including resuming watering if system was running when power failed.
  18. Record what was done over time in a log. What zones were watered, how long, or what zones were skipped and why (raining, rain predicted, soil already moist, etc.)
  19. Run the entire system on a single wall plug. Use a 24VAC wall wart transformer and make any other voltages needed internally to the system. You should not need more then a single source of power.
  20. External temperature sensor, so if its near or below freezing we don’t water.
  21. An emergency off button, so if you see an issue, like for example a broken sprinkler head that is pouring water into the street you can stop it NOW.
  22. This would include the ability to restart to continue watering if the problem is resolved or you tell the system to skip a zone one time and do the rest.



1Without watering on a regular basis the foundation can crack and that is a big $$$$$ repair. Because of this local law allows watering your foundation as needed vs every two weeks. Crazy isn’t it? Water your house?????

2Yes in ground sprinklers need regular service, lawn mowers shave off heads, heads stick with dirt, tops just break off from age. Lots goes wrong, and run off = $$$ in fines.

Next Steps

Turns out I had a bigger list then I understood when I started. Too big to get done in a single pass. So I’m going to break it up into chunks. This was how I wanted to proceed but as usual your plans go out the window when they intersect reality.

  1. Get the hardware.
    1. Assemble all hardware including the parts we are not going to use right now like:
    2. Raspberry Pi Computer (RPi)
    3. 2 banks of 5VDC relays
    4. 2×18 LCD display
    5. AtoD converter to input moisture sensors and rain sensor.
    6. 40V DC DctoDC converter
    7. Full Wave Bridge Rectifier
    8. 1000uf 50VDC Electrolytic Cap
  2. Installed on the garage wall where the existing controller is.
  3. Modify the init scripts to read the RTC and set the date even if the unit can’t see the Internet for any reason.
  4. Basic cron job that will water the lawn on the specific days allowed:
    1. cron tab of:

00 06 05 06 * sudo /bin/bash /home/pi/bin/
00 06 05 21 * sudo /bin/bash /home/pi/bin/

You see I ordered a bunch of the hardware and it won’t come in until the day after I need to water the grass for the next cycle 😦 So I’m going to have to take just the Raspberry Pi and Relay board and put them in temporally so the grass can get watered. So the actual order will look more like this:

  1. Get some hardware
    1. Raspberry Pi Computer (RPi)
    2. 1 banks of 5VDC relays
    3. Some jumper wires
    4. 40V DC DctoDC converter
    5. Full Wave Bridge Rectifier
    6. 1000uf 50VDC Electrolytic Cap
  2. Disassemble the old control system and leave parts of it in the box on the wall and keep the 24VAC transformer.
  3. Solder the full wave bridge rectifier and cap directly to the DCtoDC converter
  4. Use a chunk of cardboard to zip tie the RPi, relay board, and the new little 5VDC power supply to it.
  5. Using jumper wires connect up everything. Power the RPi via the GPIO pins and not the micro USB connector

Examine the existing connections and wires

Old Sprinkler Controller Connection Board

The old system was made by Irritrol an RD-900 unit, which consists of a control unit and a separate connection board. I don’t care about the control unit as its dead and I”m building a new one BUT I do care about the old connection board and the wires that control the sprinklers that come out of the ground. So time to document them. It’s pretty clear from a closer inspection of the board that the RD-900 is a pretty simple system there are lots of areas not populated on the board. But it’s pretty clear I can use the ribbon cable that came out of the old control unit and attach to this connection board and save some time and cost.

Connection on Old Wall Board Barrier Terminal
1 24 VAC after going through a 2A SLO-BLO Fuse
3 #9 Zone
4 #12 Zone
5 #5 & #7 Bridged to AC Common
6 #11 Zone
7 #5 & #7 Bridged to AC Common
8 #10 Zone
9 #3 Zone
10 #1 Zone
11 #4 Zone
12 #2 Zone
13 #6 Zone
14 #5 Zone
15 #8 Zone
16 #7 Zone

All connections on the Barrier Strip have an MOV for protection but it was never hooked up by the original contractor. Another example of the shoddy work that gets done on these development homes.

Old Sprinkler Controller Connection Board

Old Sprinkler Controller Connection Board

The Barrier Terminal Strip has all of the zone wires connected to it and the 24VAC power. It also has a slo-blo fuse which is quite handy since I’m bypassing the fuse on the RPi by supplying power on the GPIO pins directly.

Barrier Terminal
Strip Label
Wire Color
1 Black (Solid Wire)
2 Blue (Solid Wire)
3 Red (Solid Wire)
4 Green (Solid Wire)
5 Yellow (Solid Wire)
6 Orange (Solid Wire)
7 Brown (Solid Wire)
8 Grey (Solid Wire)
VC White (Solid Wire)
24 Black (Stranded Wire from 24VAC
VAC Black (Stranded Wire from 24VAC

OK ignoring the shoddy workmanship issues I can make use of this board. I’ll be using the following pins listed in the table below, I’m going to skip the 9th zone as I don’t need to water it right now.

Pins Description Connection Point
1 24 VAC after going through a 2A SLO-BLO Fuse DC2DC Converter Full Wave Bridge input
5 #5 & #7 Bridged to AC Common DC2DC Converter Full Wave Bridge input
7 #5 & #7 Bridged to AC Common Bridge to all relays NO Connection
9 #3 Zone Relay 3 Center contact
10 #1 Zone Relay 1 Center contact
11 #4 Zone Relay 1 Center contact
12 #2 Zone Relay 2 Center contact
13 #6 Zone Relay 6 Center contact
14 #5 Zone Relay 5 Center contact
15 #8 Zone Relay 8 Center contact
16 #7 Zone Relay 7 Center contact

Easy to wire up, and test. All good.

First Install and Test

Interesting morning, put the old sprinkler connection board back in the box, hooked up all the wires in the correct spots. Then mounted the RPi/Relay temporary cardboard mount into the lid of the old system, then used jumper cables to connect the 5VDC power supply and the relay board to the connection board.

RPi, Relay, Full wave bridge rectifier, filter cap and DC to DC power Supply

RPi, Relay, Full wave bridge rectifier, filter cap and DC to DC power Supply

Old Connection board jumped to RPi and Relay's

Old Connection board jumped to RPi and Relay’s

Jumped onto my network and checked yep, the RPi is on right where it should be. Sure enough the system set it’s time from the Internet, and SSH is working. Sweet. Ran a test program of 30 seconds per zone to see what happens, YEA success, or sort of, anyway, zones 1,2,4-8 all work as expected. Zone 3 dead, no joy, ugh, what did I do wrong?

So got out a jumper wire and shorted out zone 1 to AC common, on it comes, did the same with all the zones (this bypasses my RPi/Relay setup completely), again all zones except zone 3 work, zone 3 still dead. Looks like the zone valve in the ground is dead. Not really a surprise, this will be the second valve in the last year that has died1, and at least it failed in a better way then the first valve, which failed on, this one failed off, who knows how long it’s been dead, could be just short of a year when I last fixed zone valves. Of course we would have not noticed it, its not like I stand outside and watch my sprinklers go on and off. The only reason I did today was to test my new contraption. Since I now have full SSH access to the RPi I don’t have to go into the garage to manage the grass watering. SCORE 🙂

So I call this a total success, my controller is working, I have a crontab that will water the lawn in June without any attention, so I can now get the rest of the parts in and work on software. And better yet my wife is happy that I completed stage one of the build. Of course I still have to complete the rest of the stages but at this point the grass is getting watered on schedule so its a win.

Now I have to design the web pages to program the system, right now it’s hard coded and that won’t do, I want my wife to be able to change this from anywhere in the world without having to resort to C or Python programming. More about that another day.

1No real surprise, the zone valves are more then 12 years old and have been covered over in clay and dirt and water over that entire time. More shoddy workmanship, no dirt blocking fabric, no gravel under the zone valves just stick them in the ground, put a too small box over them and let it rip. No one is going to notice until years later.