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