Greetings OG!
An old friend (@lefthandseeds) developed the idea of using a raspberry pi, a relay, and some software to power 4 outlets based on timing schedules set within an amazing piece of software called Node-Red (https://nodered.org).
I will detail in this post how we set it up, and how to do it yourself if interested.
This thread comes with a strong disclaimer - this project “suggestion” deals with high voltage applications. If you don’t have an understanding of how to work with 120V power in an application such as this, I highly recommend you bring in a friend that does. Follow strict safety procedures if you decide to follow the “suggestions” here about how we did it. Never work on the box while it’s plugged in to 120V (obviously).
Firstly, why?
We were both using cheap timers in our grows that only allowed for very limited timing intervals (on/off only on hourly basis) and had switched to feeding on an hourly schedule such as 15s on per hour. This device allows for microsecond control of any type of timing. I wanted 4 relays so that I could control both a water pump and lights on a veg and flower tent on completely separate timing schedules.
The Rasperry Pi and Node Red also allow this box to be fully wifi controlled, but we use it as a “set and forget” utility.
On to the fun.
The components, and a cost breakdown:
4 Gang work outlet box - $7 - https://amzn.com/B000BQWVD2
4 power outlets - $4 x 4 = $16 - https://amzn.com/B002DQT5UK
4-gang wallplate - $6 - https://amzn.com/B003AU36OY
Raspberry Pi-Zero W (wifi enabled) - $10 - Raspberry Pi Zero W - DEV-14277 - SparkFun Electronics
Raspberry Pi Power Supply - $8 - Wall Adapter Power Supply - 5.1V DC 2.5A (USB Micro-B) - TOL-13831 - SparkFun Electronics
Raspberry Pi Header (this is a solder-less option) - $7 - GPIO Hammer Headers - Solderless Raspberry Pi Connectors [Male + Female + Installation Jig] : ID 3413 : Adafruit Industries, Unique & fun DIY electronics and kits
Raspberry Pi Jumper Wires (female/female to go to header and relay) - $4 - Jumper Wires Premium 6" F/F Pack of 10 - PRT-08430 - SparkFun Electronics
16G Micro SD for Pi - $8 - https://amzn.com/B073K14CVB
4-Channel Relay Module - $8 - https://amzn.com/B00E0NSORY
Wire push connectors (you can use anything you want to combine wires) - $7 - https://amzn.com/B07CNNQDMZ
18 gauge wire (I usually just buy an 18AWG power cord and strip it for its component wiring) - $7 - https://amzn.co/B006VKCFAQ
Please note: verify your gauge of wiring based on the amps of your lights, pumps, fans or whatever else you’re going to be hooking up! Use the right gauge based on your application. If you don’t know, once again, please stop and ask someone who is knowledgable in electricity applications!! Here’s a guide based on AWG (american wire gauge): American Wire Gauge Chart and AWG Electrical Current Load Limits table with ampacities, wire sizes, skin depth frequencies and wire breaking strength
Total cost: $88.00 USD
First step is to get the Raspberry Pi configured, I’m not going to go into this here, but here are the steps for the Pi, and for Node-Red installation.
Node Red install: Redirecting…
Make sure you set Node Red up to start at boot on the Raspberry Pi so that you can simply turn the Pi on and it will be active at your Pi’s address!
Here’s a build schematic I made to display exactly how it’s wired:
As you can see, the Pi is wired from 5v and ground to the relay, and then 4 GPIO pins of your choice go to the IN1 - IN4 pins on the 4-Channel Relay.
Notice power (black) from the push-in connector goes to the center channel of each relay, which is power in, then the bottom, or right most connector on each relay goes out to the power outlet. This is very important! The relay I linked “floats high” so you actually send a False or Off signal to turn ON the relay. I know, super confusing - but this allows for the best case failure state - if your Pi fails for whatever reason, or you lose power - your pumps, lights, and otherwise will default to an OFF condition!
Imagine you lose power and then your pumps default to on, thus dumping your entire reservoir into your grow!
The rest just shows basic wiring to get the power source’s grounds and neutrals to the outlets.
After wiring, you can stuff the relay and the Pi into the bottom of the gang box, and then screw in the outlets to the gang box itself. It will be a mess, be patient and make sure your wires are tight and in alignment to push everything in. Please note also, you are going to need a power source for the box itself and the raspberry pi power adapter, run the raspberry pi’s power adapter out of the gang box.
Plug in just the Raspberry Pi, do NOT plug in the main box power yet as you might need to make adjustments.
Ok, on to Node Red - I’ll post a couple screenshots of the interface and how to setup a simple timer switch, but leave the rest up to you - Node Red is an incredibly powerful IoT application but we use it at its most basic.
When you visit your Pi’s Node-Red address (e.g. 192.168.0.100:1880) you will be presented with a blank flow, which is where your timing arrangements live.
If you want a timer switch to do interval timing:
- Visit the Menu at top right
- Visit “Settings”
- Click the “Palette” tab
- Under the “Nodes” tab - search for “node-red-contrib-timerswitch”
- Click Install
This will make available the timerswitch input under “input” on the left menu.
Drag a timerswitch input onto the flow area, and then scroll all the way down on the left menu to “Raspberry PI” and drag the “rpi gpio” with the dot on the left side of the object onto your flow.
You then attach timerswitches to Rpi GPIO objects like so!
You must individually configure the Rpi Nodes to your GPIO pins running from your Pi to the Relay board, as so:
Here are examples of my timing schemes I set up in the timer switch nodes, please note the On/Off payload is a “0” for ON and a “1” for OFF, this ties to how the relay works, as I described way up above:
Finally, hit the “Deploy” button after you save these settings, plug in your main power to the box. Try plugging a light or other item that will show power is active on an outlet, and try setting a timer switch to turn on now. Once you verify all the outlets work, you are ready to grow with precision!
That’s pretty much the whole setup. I know this project is not for your average stoner to pursue, so please feel free to post any comments or questions. @Mr.Sparkle will probably come in here with a much simpler solution for most people involving smart plugs!
I will post a finished picture of the power box when I’m available later.
Thanks for everything you do, OG!
cc: @WMoon518 (promised this write up a long time ago in Sparkle’s thread)