Its kinda kludgy (of course- I made it!) but it works. As usual full of bits pinched from elsewhere....
I am using this to control 4 effergy wall outlets. I already have mains switching ability but it's made by me and I am nervous about fire, so I figured this was a good compromise.
I have some cheap 433 transmitters and receivers. Used the RCSwitch library to capture the codes. I have only got one switch functional at the moment but to add the rest is trivial. My coding Im sure is crap but it works.
I have soldered a wee wire to the transmitter 12CM long and have no issues with range. I like the 'repeat command x times' function in the RCSwitch library, kinda makes not having feedback a non issue.
// Enable debug prints to serial monitor
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enable repeater functionality for this node
// #define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#include <RCSwitch.h>
#define NUMBER_OF_PLUGS 4 // Total number of attached plugs
#define CODE_1On 1290271
#define CODE_1Off 1290263
#define CODE_2On 1290267
#define CODE_2Off 1290259
#define CODE_3On 1290269
#define CODE_3Off 1290261
#define CODE_4On 1290270
#define CODE_4Off 1290262
RCSwitch mySwitch = RCSwitch();
void setup() {
mySwitch.enableTransmit(4);
mySwitch.setRepeatTransmit(15);
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("433mhz switch", "1.0");
for (int sensor=1 ; sensor<=NUMBER_OF_PLUGS;sensor++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_LIGHT);
}
}
void loop()
{
}
void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
int incomingLightState = message.getBool();
int incomingOutlet = message.sensor;
Serial.print("Outlet #: ");
Serial.println(message.sensor);
Serial.print("Command: ");
Serial.println(message.getBool());
if (incomingOutlet==1) {
if (incomingLightState==1) {
// Turn on socket 1
Serial.println("Turn on Socket 1");
mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
delay(50);
}
if (incomingLightState==0) {
// Turn off socket 1
Serial.println("Turn off Socket 1");
mySwitch.send(CODE_1Off, 24);
delay(50);
}
}
if (incomingOutlet==2) {
if (incomingLightState==1) {
// Turn on socket 2
Serial.println("Turn on Socket 2");
mySwitch.send(CODE_2On, 24);
delay(50);
}
if (incomingLightState==0) {
// Turn off socket 2
Serial.println("Turn off Socket 2");
mySwitch.send(CODE_2Off, 24);
delay(50);
}
}
if (incomingOutlet==3) {
if (incomingLightState==1) {
// Turn on socket 3
Serial.println("Turn on Socket 3");
mySwitch.send(CODE_3On, 24);
delay(50);
}
if (incomingLightState==0) {
// Turn off socket 3
Serial.println("Turn off Socket 3");
mySwitch.send(CODE_3Off, 24);
delay(50);
}
}
if (incomingOutlet==4) {
if (incomingLightState==1) {
// Turn on socket 4
Serial.println("Turn on Socket 4");
mySwitch.send(CODE_4On, 24);
delay(50);
}
if (incomingLightState==0) {
// Turn off socket 4
Serial.println("Turn off Socket 4");
mySwitch.send(CODE_4Off, 24);
delay(50);
}
}
}
delay(50);
}