ESP 8266 control my 433mhz power plug´s Smarthome

Yesterday i got the 433mhz receiver and transmitter. Then i thought, and know ?
what will i build with this.

Then i have tested with the remote control of my power plugs. To get a Code
or anything else. Success i could read the Codes for ON & OFF for each Chanel.

Then i wrote the sketch for the RF transmitter to control each Chanel from
Cayenne Dashboard.

It works very well…

You need

1 433mhz transmitter & receiver module
1 Nodemcu ESP 8266-12 E or smaler
1 Powerplugs with Remotecontrol

At first you have to get the Codes out of the Remotecontrol !!! Make it with the
RF-Sniffer. Sketch below!
Connect the Receiver with an ESP or else to read the RC. Test, test, test to get the right Codes ! Write them down you will need it in the second Sketch.

FIRST SKETCH

/*
  RF_Sniffer
 
  Hacked from http://code.google.com/p/rc-switch/
 
  by @justy to provide a handy RF code sniffer
*/
 
#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
RCSwitch mySwitch = RCSwitch();
 
void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0); 
}
 
void loop() {
  if (mySwitch.available()) {
 
    int value = mySwitch.getReceivedValue();
 
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
 
     Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
    }
 
    mySwitch.resetAvailable();
 
  }
}

Then you have to build the ESP with the Receiver together.!

My build is a bit different because its my Christmas Lights 2.0 Version.

Second and Run Sketch

you have to Change the Numbers at “mySwitch.send” to your Codes

#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT serial
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

char ssid[] = "*********";
char wifiPassword[] = "*******";

char username[] = "*************";
char password[] = "*****************";
char clientID[] = "*****************";

void setup() {
  // put your setup code here, to run once:
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  mySwitch.enableTransmit(4);
  pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
  
  
}

void loop() {
  // put your main code here, to run repeatedly:
  Cayenne.loop();

}
CAYENNE_IN(6)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    digitalWrite(2, HIGH);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    digitalWrite(2, LOW);
  }
}
CAYENNE_IN(7)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    digitalWrite(5, HIGH);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    digitalWrite(5, LOW);
  }
}
CAYENNE_IN(8)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    mySwitch.send(5571921, 24);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    mySwitch.send(5571924, 24); 
  }
}
CAYENNE_IN(9)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    mySwitch.send(5574993, 24);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    mySwitch.send(5574996, 24); 
  }
}
CAYENNE_IN(10)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    mySwitch.send(5575775, 24);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    mySwitch.send(5575764, 24); 
  }
}
 CAYENNE_IN(11)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    mySwitch.send(5575953, 24);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    mySwitch.send(5575956, 24); 
  }
}

Now you have to create Widgets for each Channel on your Cayenne Dashboard
Try it and much fun with this simple and low-cost Smarthome

5 Likes

Nice project! Thanks for sharing the code you created too. Hopefully saves some headaches for people in the future.

~Benny

1 Like

Thanks bestes,

it was just to try out, and ? its run very well. I have to make a pause or brake in to the sketch. It runs not stable over the time…

Nice project! I have an old remote laying around somewhere, I should map out the values and use it for something cool too…

Hi Sven

I built pretty much the same last year and included some code to prevent the transmitter from continuously sending an ‘on’ or ‘off’ signal every loop cycle

The code just sends one signal if the button state changes.

Don’t know if it helps with the stability issue but you could try.

CAYENNE_IN(1)
{
state = getValue.asInt();
//CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
digitalWrite(ACTUATOR_PIN, state);
Serial.print("State: ");
Serial.println(state);

//Check switch status if it is 1 and then activate the remote switch
//Only one activation event will do, the switchstatus variable will take care of that.
if( state == 1 and switchstatus == 0){
mySwitch.send(329041, 24);
}
// Below it sets the switchstatus to 1 the in the first cylce after the button was pressed. (will be reversed if the button is set to off)
if( state == 1 and switchstatus == 0)
switchstatus =1;
delay (200);

//Check switch status if it is 0 and de-activate the remote switch
//Only one de-activation event will do, the switchstatus variable will take care of that.
if( state == 0 and switchstatus == 1){
mySwitch.send(329044, 24);
}

if( state == 0 and switchstatus == 1)
switchstatus =0;
delay (200);