Automated Skylight Greenhouse
During the cold mountain winters, I wanted a place where my plants could stay safe from pets but still get the sunlight they need, so I put them in my skylight (hat-tip to my son for the idea). The problem then was watering them without climbing on a ladder, so the bulk of this Instructable is the monitoring and watering system I built to keep our green friends happy.
Supplies
- The basics:
- First and foremost: plants!
- Wire shelving to hold the plants while letting light through
- Low, clear plastic trays: 70qt is $27 Lowes: 52qt is $16 at Walmart
- The automation:
- 1 large water container like a bucket, at least a gallon but preferably more
- 1 water pump. You could buy one, but I used a hospital cast-off from my parts bin
- Vinyl tubing to go from the reservoir to all the plants - I used about 25ft
- Tubing T's to distribute water to each plant: 5 for $8 Amazon
- A tubing valve for each plant so that each gets just enough water, and a few more valves to let you take things apart as necessary: 5 for $8 at Amazon
- Capacitive soil moisture sensors for each plant: $2.50ea at Aliexpress; 5 for $12 at Amazon
- 1 ESP32, or similar, microcontroller: 6 for $40 at Amazon (They're not much cheaper at Ali, and quality tends to be iffy, at best.)
- 1 smart plug to toggle the pump power. I'm using a Z-wave wall outlet, but you can use whatever ties into your home automation, or one you control from your phone. If you're just getting started, these are about $11 each at Amazon and work with Apple Homekit, Alexa, and Hey Google - no additional hardware or software required. My Meross smart plugs work well so I'm comfortable recommending them. Walmart has comparable $11 switches, though from a different brand so I can't attest to their reliability.
- 1 water level sensor: 6 for $4 at Aliexpress; 2 for $9 at Amazon
- Home-assistant to manage everything. Setup is well beyond this Instructable, but if you'd like help, don't hesitate to reach out.
- Wire
- Optional but recommended: heat-shrink tubing of various sizes
- Optional: Liquid Electrical Tape - $10 at either Amazon or Lowes
- Pro upgrade: Zigbee temperature and humidity sensor: $8 at Aliexpress; $18 at Amazon
Diagnose the Problem and Start Tinkering
My mother has had two large vegetable gardens since before I was born, so I grew up seeding, weeding, picking, and eating veggies right from the ground. After college, I looked forward to being able to have at least a small garden of my own, but living in Manhattan made that challenging, to put it mildly. A few years ago, I bought a little weekend getaway house in the Pocono mountains and was excited to finally have some dirt of my own, ripe for planting - or so I thought. The ground there is so rocky that very little grows and what does manage to sprout makes a quick meal for our friendly, neighborhood deer and other woodland creatures. So I got a small greenhouse for my deck, which worked great - until winter set in, as you might have guessed from the picture.
When we brought the plants into the house, our cats decided they had a favorite new past-time: horticultural destruction. We tried setting up the greenhouse inside, but it's much too big and cumbersome for that. While taking it apart to store for the winter, my son suggested putting the plants in a skylight: it's warm, there's plenty of light and it's high enough that the cats, good jumpers though they are, didn't stand a chance. "Brilliant! Why doesn't everyone do that?" I asked, before realizing almost immediately that monitoring and watering would become troublesome, not to mention the risk of leaving a ladder in the middle of the room. (Plus, one of the cats is easily smart enough to figure out how to climb it to further his messy agenda.)
That's when the consummate DIYer in me got to work. I've been running home-assistant for 5+ years and had large swaths of the house automated already, so why not this? And a project was born.
Mount the Shelves
I won't go into too much detail here since I suspect anyone willing to attempt this project knows how to hang shelves. My skylight is tall enough that I was able to put up two tiers: 12" deep on the top and 16" on the bottom. I chose ClosetMaid ShelfTrack adjustable shelves to allow for changing heights based on what I'm growing. On top of the wire are shallow, clear plastic storage trays, like you'd use for under-bed storage. Initially, I was going to keep a few inches of water in the trays to let the plants soak it up through the bottom holes in the pots, but I quickly determined that would be too heavy and consume a lot of water. I should also mention that there's no faucet anywhere near this skylight, adding another degree of difficulty.
Prototype and Calibrate the Monitoring System
To determine when your plants are thirsty, you'll need soil moisture sensors, but be careful about which ones you buy, and make sure you read the reviews carefully. Cheap ones often don't work at all, or if they do their readings are unreliable. Even if they behave fine at first, they may not last long since they're in contact with soil and water at all times. I went with name-brand capacitive sensors that, even after a year and a half, are rock solid with no signs of corrosion. These require 3 wires and I had a spool of 4-conductor, solid project wire, which worked out perfectly because the copper conductor is just a bit too small to fit tightly into the plugs which came with the sensors. That let me work a couple of tricks you'll see shortly.
You'll also need a microcontroller. ESPHome integrates seamlessly with home-assistant, so an ESP32 was a natural fit, specifically the ADC (Analog To Digital) sensor package. You could also use an Arduino or ESP8266, the ESP32's older sibling. For full details down to the pin-out, sensor tuning, and signal filtering, see the attached code. Instructables won't accept a yaml file, so I changed the extension to "txt". The only things you'll have to update, other than the file extension, of course, are the passwords and wifi details, all of which I include from a secrets file to keep sensitive information private. You can also find the file in my github repo.
After installing ESPHome and connecting one sensor to the ESP32, set up three small cups or pots of soil: one dry, one perfectly moistened (a standalone moisture meter like in the photo is very handy if you have one), and one soaking wet. Each sensor will be a bit different, so calibrate them individually with your sample cups. Don't forget to label the sensors so you don't mix them up later. (No bonus points will be awarded for figuring out the source of that recommendation.).
Downloads
Wire Up the Sensors
This is where you'll probably need to deviate from my Instructable based on how many sensors you have, how big and far apart the plants are, etc. But I'll detail my setup in case it's helpful.
The sensors run on 3.3-5V DC, as does the ESP32. A USB port will give you 5V, with plenty of amps to handle all of these devices, so it's the perfect power source. The ESP32 can also supply current to the sensors, simplifying the wiring. You could run a dedicated set of 3 wires to each sensor, but that's a lot of excess wire, so I chose to wire them in parallel for power, with only a single signal wire coming back to the ESP from each sensor. After laying out everything just how I wanted it, I cut a length of 4-conductor cable with a few extra feet to allow for the bends I knew I'd need to make, and some additional because better to have too much than too little.
It may not look like it from the full-system picture, but the red (+5V) and black (ground) wires in the red/green/black/white cable are uncut from sensor 1 on the far left, all the way to the ESP32 on the far right (where all of the wires meet). The green wire carries sensor 1's signal. White carries sensor 2's, and I ran another piece of white from sensor 3, but I colored it light green with a sharpie to differentiate it from sensor 2.
It's a bit hard to explain, but here's how I did it:
All: To make sure the project wire was solid in the plug, after stripping the insulation, I bent the copper back on itself, crimping it to make a tight angle, and pushed it into the plug. It was a perfect fit.
Sensor1: Connect the red, black, and wire to the plug, cover with heat-shrink tubing and seal it. easy!
Sensor2: This was the first one where it got a bit tricky - or clever depending on your outlook. The second photo shows the wire getting prepped for sensor2. The red and black are stripped, but green is intact. Next, I bent red and black back on themselves, as seen in pic3, and inserted them, along with white, into sensor2's connector. I know, white isn't visible in the picture - I'd peeled it off of the cable earlier for some testing so if you look carefully in later pictures, you'll the whole thing held together with twist-ties. After testing, lock it down with heat shrink. The last picture shows the white wire connected to the sensor's signal pin and if you look carefully you can see that green is looped over because the whole cable makes a u-turn there. (red and black are doubled as well.)
Sensor3: Just like sensor 2, except this time you have two wires left intact (green and white) so you'll need to run its sensor wire separately and make use of those twist-ties I mentioned in the last paragraph.
Sensor4: I chose to put the ESP32 between sensors 3 and 4, so that was another simple, straight run of wire with no fanciness necessary.
ESP32: I could have soldered the wires directly to the ESP32, but I've had a couple go bad after just a few weeks, so I didn't want anything that permanent. Instead, I cut and soldered some Dupont female connectors to the ESP32 end of the sensor cable so I could swap out the microcontroller if necessary. It also provides extra flexibility in case I want to change something down the road. As it turns out, the first ESP I used here stopped working after about 2 months, so I was very glad to have chosen this route.
Power Up!
There's no power outlet near my skylight, so originally I'd planned to run the system off of a home-built battery using 18650 cells recovered from tool and laptop batteries. See my previous Instructable for more detail. Based on the estimated power draw, a pair of cells should have lasted a good month, and since I can reach up onto the first shelf to change them, that was satisfactory. What scuttled this plan was the always-lit LED on the ESP board, which drained power much faster than I'd hoped. The thing was drawing about 1/10W, which is almost 10x what I'd expected. Rather than lasting a month, a good pair of cells gave me about 3 days. Even changing out the 2-pack for a 4-pack (2 pairs of serial-connected cells, with the pairs connected to each other in parallel) lasted less than a week and since I'm often away from this house for longer than a week, that simply wouldn't do. Put a pin in that and we'll come back to it after I explain the watering system.
ESPHome has a built-in web server so even before connecting to home-assistant, you can keep an eye on your plants, as you can see from the screenshot.
Water Supply
Since there's no faucet nearby I had to build a reservoir. In the interest of reduce, reuse, recycle, I grabbed a large plastic barrel (formerly the home of cheese balls) and cut a small hole right near the bottom, then used gorilla glue to seal a short length of 3/8" OD vinyl tubing.
To keep the pump from running dry, I 3D printed a mount for a water level sensor and glued it to the inside of the barrel, well above where the pump would start drawing in air. If you don't have a 3D printer, you could use a piece of wood for the same purpose as long as it wasn't pressure-treated since the chemicals would likely leach into the water and those are not good for growing plants, especially those you intend to eat!
Another sensor option is a non-contact sensor that will read through the wall of the barrel, like this one for $15. I had the float sensors from another project, but if I were starting from scratch I'd probably get the non-contact instead.
Pump It Up
Next, you'll need a way to move the water up from the reservoir to the plants. They're not expensive online, and I considered buying one until I remembered that a friend had given me a couple of cordless pumps used for incision irrigation in an operating room. Once these things are unpacked they can't be put back into the supply room, so rather than throw them away, the doctors take them home, mostly to harvest the 8 brand new AAs inside. "Irrigation? Perfect." Just as long as it can pump water about 10 feet straight up to the top shelf in the skylight. Not only could it pump the water that high, it was blasting dirt out of the pots.
I cracked open the pump (saving the AAs of course) and connected a wall wart with variable voltage so I could water the plants rather than sandblast (waterblast?) them. 9V did the trick and now that wall wart is plugged into a Z-wave outlet managed by home-assistant. The only modification I had to make to the pump was to disable the check-valve which prevented it from working in any position other than straight up.
Run the Tubing
Unfortunately, I don't have a good picture of the tubing, but it's probably the simplest part of the build, so they're not really necessary. The short output tube from the barrel goes to a ball valve so I can close it and remove the barrel without having to drain it first. From the valve, another short tube goes to the pump, followed by one more short tube, then yet another valve before connecting to the long tube running to the skylight. I used a bunch of T's and more short tubes to ensure each plant gets a line. Each of those lines has another valve to make sure that the last plant gets as much water as the first. Tweaking those will take some trial and error, but once you get it set, it should last indefinitely.
I've thought about replacing the manual valves with those I can have home-assistant operate so that I only water plants that need it, but they all seem to get thirsty together so I haven't needed to do that. But it's on the drawing board for v2.
Prevent Burnout
Running a water pump without water is a good way to burn it out, which is why I glued the water level sensor into the barrel. That sensor is connected to the same ESP32 that monitors the plant moisture levels, though this is a binary sensor (on/off) rather than an ADC. When home-assistant sees this sensor turn on, it shuts off power to the pump immediately and I get a pop-up on my phone in the home-assistant app so I know to refill it. For a while, I just ran a pair of wires alongside the tubing from the sensor to the ESP, but that changed when I redesigned how I power the thing.
Automate It
ESPHome's web server is nice, but it's far from automated. One of the many great things about ESPHome is that as soon as I brought it up on my network, home-assistant found it and added the integration automatically. From there, automation was easy.
- Create a dashboard for the plants
- Set thresholds for monitoring. Mine alert me at 40% moisture level, which corresponds to the dry side of "ok" on the standalone moisture meter.
- Have home-assistant turn on the pump for 60 seconds when the moisture level gets below your threshold, then ensure it doesn't run again for at least an hour while the water spreads in the pots.
If anyone is interested in seeing the home-assistant automation code, leave a comment and I'll be happy to post it.
No More Batteries
I got tired of changing the 18650s every few days, so I figured I'd move the ESP32 to the table next to the pump and barrel since there's an outlet right there. I'd need a total of six conductors: 5V, ground, and 4 sensors, so rather than running a bunch of individual strands or even pairs, I grabbed a length of Cat5 since it has 8 conductors and, as a networking geek, I have plenty of it around. Yes, I used proper RJ45 jacks on both ends. (I can't believe you asked - it's like you don't even know me.) Unfortunately, the analog signals degraded and interfered with each other over such a long stretch of wire so that didn't work. Never mind having the power lead right alongside.
What did work, however, was moving the ESP32 back to the skylight and using that same cat5 wire to route the float sensor signal and power from the wall outlet. And that's how it's lived for over six months. The plants like the system so much that they're producing fruit (habaneros are almost ready to pick) and I like it so much that I haven't moved them back to the greenhouse.
Final Thoughts
This project turned out to be even more fun than I expected and I still get a huge grin on my face when I'm sitting in the office and I hear the pump turn on by itself. I have added one more thing recently: a small, $8 Zigbee temperature and humidity sensor. It's amazing how much warmer it gets in the skylight than just a few feet below it in the office.
Items for an overhaul, or if I were starting from scratch:
- Add remotely-managed valves for each plant so that I can water only the ones that need it.
- Use two non-contact water level sensors for the reservors so I'll know to fill it before it runs almost dry. (As it happens, when I work remotely, I'm in the same room, so I see it every time I come in.)
- Find an ESP32 without an always-on LED to see just how long it'll run on batteries. Sure, wall power is easier, but where's the challenge in that?
- I didn't think to write this until I was most of the way through so next time, take more pictures as I'm testing, assembling, and changing things.