My wife and I live full time in our RV. We recently upgraded it to a new Cyclone 4005 Toy Hauler.
We absolutely love it. One of the things that we love is the number of LED lights throughout the entire RV. One of the things we hate about it is how many light switches there are. Really, I think there are over 30, not counting the switches on the lights themselves. It's difficult to remember which switch controls what light.
So Home Automation to the rescue. Using Alexa, I wanted to be able to give some general commands like "Alexa, turn on outside lights" and have the system turn on all 3 awning LED strips, the porch flood light, and the left and right side flood lights. Those 6 switches are located on two separate control panels.
So thinking about how to accomplish this, I decided to try to implement this automation without modifying the existing RV wiring. It basically came down to adding a relay in parallel to each switch. This allows operating the light via the relay, while still allowing the existing switch to work as a backup. I'm not going to go into the details of the wiring in this article. You can read about those details on my blog.
In this article I'm going to talk about how using NCD ControlEverything.com relay boards really simplified this somewhat daunting task. Thirty relays is a lot! And that's just the factory installed light switches and doesn't count fans, motorized awnings, and lamps that I added after buying the RV.
There isn't really any getting around the wiring part of that job, but I was not looking forward to creating 30 duplicate electronic relay controller circuits. So I searched for options to simplify the electronics task. I must say that I was extremely delighted when I came across the ControlEverything.com Photon IoT relay boards. These boards contain a socket for a Particle Photon, and various numbers and types of relays. Each board can contain one, two, four, eight, or sixteen relays. The price is really good on these also. An 8 relay board is about $60, to which you'll just need to provide the $19 Photon. So that works out to about $10 per relay. They also operate directly from 12 volts, so I didn't need to provide separate power supplies since the RV lights operate mostly on 12 volts. And best of all, these boards can be daisy chained using built-in I2C connectors to add additional capabilities such as light dimming, input sensing, and so forth. Wow!
So, with the hardware and wiring stuff decided, what about the software? This was actually the easy part, and is the focus of this article. The Patriot open source IoT project makes this pretty simple. I just needed to create a plugin to support the relay boards. Now that I've done this, you won't need to worry about that part.
So putting together the Patriot sketch really just amounted to deciding what I want to call each relay, and to what commands I want it to respond. Here's an example sketch used to control 16 relays in the front control panel:
/*
* FrontPanel Controller
* This sketch controls all the switches in the Cyclone 4005
* front control panel.
* Author: Ron Lisle
* Date: 9/16/17
*
* Hardware
* 1. Photon
* 2. ControlEverything.com NCD8Relay Photon Controller
* 3. ControlEverything.com NCD8Relay I2C Controller
* 4. I2C cable between boards
* Photon board relay n/o connections 0x20
- Sink (1)
- Front Awning LEDs (2)
- Right Trim (3)
- Left Trim (4)
- Ceiling (5)
- Door Side Floods (6)
- Other Side Floods (7)
- Porch (8)
* I2C board relay n/o connections 0x21
- High Kitchen (1)
- Kitchen Ceiling (2)
- Vent Fan (3)
- Vent Open (4)
- Vent Close (5)
- Front Awning Extend (6)
- Front Awning Retract (7)
- unused (8)
*
* History
* 10/28/17 Update to v2
* 10/17/17 Correct RV Lights to TV Lights.
* 10/03/17 Convert to ConnectEverything relay boards
* 9/16/17 Initial creation using Patriot plugin
*/
#include <IoT.h>
#include <PatriotNCD8Relay.h>
IoT *iot;
void setup() {
iot = IoT::getInstance();
iot->begin();
byte address1 = 0x20;
byte numRelays1 = 8;
NCD8Relay *sink = new NCD8Relay(address1, numRelays1, 0, "Sink");
NCD8Relay *frontAwning = new NCD8Relay(address1, numRelays1, 1, "Front Awning");
NCD8Relay *rightTrim = new NCD8Relay(address1, numRelays1, 2, "Right Trim");
NCD8Relay *leftTrim = new NCD8Relay(address1, numRelays1, 3, "Left Trim");
NCD8Relay *ceiling = new NCD8Relay(address1, numRelays1, 4, "Ceiling");
NCD8Relay *dsFloods = new NCD8Relay(address1, numRelays1, 5, "Door Side");
NCD8Relay *osFloods = new NCD8Relay(address1, numRelays1, 6, "Other Side");
NCD8Relay *porch = new NCD8Relay(address1, numRelays1, 7, "Porch");
iot->addDevice(sink);
iot->addDevice(frontAwning);
iot->addDevice(rightTrim);
iot->addDevice(leftTrim);
iot->addDevice(ceiling);
iot->addDevice(dsFloods);
iot->addDevice(osFloods);
iot->addDevice(porch);
// BEHAVIORS
// Note that both ON and OFF states must be handled
// Awning
iot->addBehavior(new Behavior(frontAwning, "awning", '>', 0, 100)); // On
iot->addBehavior(new Behavior(frontAwning, "awning", '=', 0, 0)); // Off
// Everything
iot->addBehavior(new Behavior(frontAwning, "everything", '>', 0, 100)); iot->addBehavior(new Behavior(frontAwning, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(osFloods, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(osFloods, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(dsFloods, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(dsFloods, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(porch, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(porch, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(ceiling, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(ceiling, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(rightTrim, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(rightTrim, "everything", '=', 0, 0));
iot->addBehavior(new Behavior(leftTrim, "everything", '>', 0, 100));
iot->addBehavior(new Behavior(leftTrim, "everything", '=', 0, 0));
// Inside
iot->addBehavior(new Behavior(sink, "inside", '>', 0, 100));
iot->addBehavior(new Behavior(sink, "inside", '=', 0, 0));
iot->addBehavior(new Behavior(ceiling, "inside", '>', 0, 100));
iot->addBehavior(new Behavior(ceiling, "inside", '=', 0, 0));
// Kitchen
iot->addBehavior(new Behavior(sink, "kitchen", '>', 0, 100));
iot->addBehavior(new Behavior(sink, "kitchen", '=', 0, 0));
// Living Room
iot->addBehavior(new Behavior(ceiling, "living room", '>', 0, 100));
iot->addBehavior(new Behavior(ceiling, "living room", '=', 0, 0));
iot->addBehavior(new Behavior(rightTrim, "living room", '>', 0, 100));
iot->addBehavior(new Behavior(rightTrim, "living room", '=', 0, 0));
iot->addBehavior(new Behavior(leftTrim, "living room", '>', 0, 100));
iot->addBehavior(new Behavior(leftTrim, "living room", '=', 0, 0));
// Outside
iot->addBehavior(new Behavior(frontAwning, "outside", '>', 0, 100));
iot->addBehavior(new Behavior(frontAwning, "outside", '=', 0, 0));
iot->addBehavior(new Behavior(osFloods, "outside", '>', 0, 100));
iot->addBehavior(new Behavior(osFloods, "outside", '=', 0, 0));
iot->addBehavior(new Behavior(dsFloods, "outside", '>', 0, 100));
iot->addBehavior(new Behavior(dsFloods, "outside", '=', 0, 0));
iot->addBehavior(new Behavior(porch, "outside", '>', 0, 100));
iot->addBehavior(new Behavior(porch, "outside", '=', 0, 0));
// TV
iot->addBehavior(new Behavior(rightTrim, "TV", '>', 0, 100));
iot->addBehavior(new Behavior(rightTrim, "TV", '=', 0, 0));
iot->addBehavior(new Behavior(leftTrim, "TV", '>', 0, 100));
iot->addBehavior(new Behavior(leftTrim, "TV", '=', 0, 0));
}
void loop() {
iot->loop();
}
Step 3Although the sketch appears to be long, that's only because it's controlling a lot of relays. This is actually only half of the sketch I'm using. I've edited it to just the first 8 relays. Here's what a single relay, single behavior sketch would look like:
#include <IoT.h>
#include <PatriotNCD8Relay.h>
IoT *iot;
void setup() {
iot = IoT::getInstance();
iot->begin();
byte address1 = 0x20;
byte numRelays1 = 8;
NCD8Relay *sink = new NCD8Relay(address1, numRelays1, 0, "Sink");
iot->addDevice(sink);
iot->addBehavior(new Behavior(sink, "kitchen", '>', 0, 100));
iot->addBehavior(new Behavior(sink, "kitchen", '=', 0, 0));
}
void loop() {
iot->loop();
}
Step 4So that's it.
- Select and purchase a ControlEverything.com relay board with the number and type of relays you need.
- Purchase and plug in a Particle.io Photon.
- Attached the screw terminals on the relay board to whatever it is you want to control.
- Hook the board up to 12 volts.
- Download the Patriot software.
- Create your sketch, and use the Particle.io tools to flash it over-the-air to the Photon. You can use the example included in the NCD8Relay plugin examples directory as a starting point.
For more information about Patriot, refer to my other hackster.io projects or my blog at https://lisles.net. There are also a lot of projects on hackster.io that talk about how to use relays in your projects. Happy automating!
Comments