All,
I have noticed a few folks asking questions about integrating 433Mhz RF devices with SmartThings. I have a set of 3 ETEKCITY Remote Outlet Switches - ZAP 3F is the model. The SKU is 10-BHC9938U-3 and I purchased them on sale a while back from Newegg. @keithcroshaw had asked me a while back about integrating the Arduino “RCSwitch” library with my ST_Anything library. I am happy to share with everyone the results of this union between an Arduino, a ST Thingshield, and some inexpensive 433MHz RF components.
For the basic understanding of the Arduino ST_Anything library my son and I wrote a few months back, please visit this post. This should get you started:
I have updated my Github repository to include the EX_RCSwitch.cpp and .h files at GitHub - DanielOgorchock/ST_Anything: ST_Anything is an Arduino library, sketch, and Device Type that works with your SmartThings ThingShield to create an all-in-one SmartThings device.. The EX_RCSwitch (Executor, Radio Controlled Switch class) implements the necessary features/libraries needed to comminucate with the 433MHz RC Transmitter (I used one just like this http://amzn.com/B00INTI8R2, however I bought mine via eBay from China.)
I have also added a new RCSwitch Multiplexer which handles three virtual switches to one Arduino. So, there is now a complete matched set of code (i.e. RCSwitch Arduino sketch/library, RCSwitch Device Type for the Arduino ThingShield, RCSwitch Multiplexer Smart App, and Virtual Switch Device Type.)
This should be everything you need to get things up and running.
- Load the ST_Anything_RCSwitch.ino sketch on your Arduino (which I assume you have figured out how to wire to the ThingShield and the 433MHz Transmitter already. See my original thread for ST_Anything I linked above for detailed instructions.)
- Then install the ST_Anything_RCSwitch.device.groovy Device Type in the ST IDE to replace whatever Device Type you have already for the Arduino ThingShield.
- Using the ST IDE, create three Virtual Switches using my VirtualSwitch.device.groovy Device Type
- Finally, tie everything together using my ST_Anything_RCSwitch_Multiplexer.smartapp.groovy SmartApp. The SmartApp will accept the Arduino and the three Virtual Switches as input devices. This allows you to control each “Switch” independently from other traditional SmartApps/Hello Home phrases.
I realize that this example is specific to my ETEKCITY ZAP 3F RF outlets, however it should server as a great starting point for anyone who wants to integrate 433MHz RF devices to SmartThings. Once you determine the correct RF Codes needed by the RCSwitch library, just enter them into the Arduino Sketch in the following section of code:
//Executors
static st::EX_RCSwitch executor1(F("rcswitch1"), PIN_RCSWITCH, 5526835, 24, 5526844, 24, 174, 1, 15, LOW);
static st::EX_RCSwitch executor2(F("rcswitch2"), PIN_RCSWITCH, 5526979, 24, 5526988, 24, 174, 1, 15, LOW);
static st::EX_RCSwitch executor3(F("rcswitch3"), PIN_RCSWITCH, 5527299, 24, 5527308, 24, 174, 1, 15, LOW);
Refer to the comment section at the top of EX_RCSwitch.h for details of what each of the arguments above is used for. You WILL need to change come of these values for your specific 433MHz RF device.
// st::EX_RCSwitch() constructor requires the following arguments
// - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
// - byte transmitterPin - REQUIRED - the Arduino Pin to be used as a digital output for the RCSwitch object's transmitter pin
// - unsigned long onCode - REQUIRED - the "on" code for RCSwitch send() command
// - unsigned int onLength - REQUIRED - the "on" code's length for RCSwitch send() command
// - unsigned long offCode - REQUIRED - the "off" code for RCSwitch send() command
// - unsigned int offLength - REQUIRED - the "off" code's length for RCSwitch send() command
// - unsigned int pulseLength - REQUIRED - the length of the RF pulse for RCSwitch send() command
// - byte protocol - OPTIONAL - defaults to "1" - the protocol for RCSwitch send() command
// - byte repeatTransmits - OPTIONAL - defaults to "15" - the number of repeated transmits for RCSwitch send() command
// - bool startingState - OPTIONAL - the value desired for the initial state of the switch. LOW = "off", HIGH = "on"
Also, an antenna on the transmitter will most likely be required to get some decent range.
To determine your device’s 433MHz codes, please use the example Arduino code contained within the RC-Switch library(GitHub - sui77/rc-switch: Arduino lib to operate 433/315Mhz devices like power outlet sockets. - I have included it in my Github Repo as well.) You’ll need to hook up the 433MHz receiver to an Arduino so it can listen and learn the correct codes to turn on or off your device. Once you know these codes, try using them in one of the sample transmitter sketches to make sure you can make the Arduino control your device BEFORE you try to use my ST_Anything_RCSwitch example code. No need to complicate the troubleshooting until you know that you can get the device to be properly controlled by the Arduino in the first place.
Hope others find this useful!
Dan