BOYS COMBINE FORCES, participate on
http://forum.mysensors.org/topic/1557/combined-mysensor-gateway-with-433mhz-transmitter-homeeasy-klik-aan-klik-uit/11 because it seems to have been settled in part
/**
* Import the libraries needed by the Sketch
*/
#include <MySensor.h>
#include <SPI.h>
#include <RemoteTransmitter.h>
/**
* Declare constants like pin settings etc.
*/
#define TRANSMITTERPIN 6 // documentation doesn't see anything if the needs to be a PWM, but why take the risk?
#define CHILD_ID_ACTION_SWITCH_A 1 // Declare the DEVICE A as a separate switch
#define CHILD_ID_ACTION_SWITCH_B 2 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage
#define CHILD_ID_ACTION_SWITCH_C 3 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage
#define CHILD_ID_ACTION_SWITCH_D 4 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage
#define CHILD_ID_ACTION_SWITCH_E 5 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage
const char SYSTEMCODE = char(31); // cast the integer byte value to a char should do the trick. Adjust this to your own SYSTEMCODE see RemoteTransmitter.h
/*
* Declare variables
*/
ActionTransmitter switchTransmitter = ActionTransmitter( TRANSMITTERPIN );
unsigned long SLEEP_TIME = 5000; // the main loop will probably won't do a thing if we only attach a transmitter.
MySensor gw;
/*
* Declare MySensors Messages
*/
MyMessage msgDeviceA( CHILD_ID_ACTION_SWITCH_A, V_LIGHT );
MyMessage msgDeviceB( CHILD_ID_ACTION_SWITCH_B, V_LIGHT );
MyMessage msgDeviceC( CHILD_ID_ACTION_SWITCH_C, V_LIGHT );
MyMessage msgDeviceD( CHILD_ID_ACTION_SWITCH_D, V_LIGHT );
MyMessage msgDeviceE( CHILD_ID_ACTION_SWITCH_E, V_LIGHT );
/**
* Preparation code during initialization of the Arduino
*/
void setup() {
// put your setup code here, to run once:
// Serial.begin( 115200 );
gw.begin( incomingMessage ); // attach a message handler for handling commands transmitted by the controller.
gw.sendSketchInfo("433Mhz bridge", "1.0"); // Send the sketch version information to the gateway and Controller
gw.present( CHILD_ID_ACTION_SWITCH_A, S_LIGHT ); // Present Device A to the gateway
gw.present( CHILD_ID_ACTION_SWITCH_B, S_LIGHT ); // Present Device B to the gateway
gw.present( CHILD_ID_ACTION_SWITCH_C, S_LIGHT ); // Present Device C to the gateway
gw.present( CHILD_ID_ACTION_SWITCH_D, S_LIGHT ); // Present Device D to the gateway
gw.present( CHILD_ID_ACTION_SWITCH_E, S_LIGHT ); // Present Device E to the gateway
gw.sendBatteryLevel(100); // It just looks better in Domoticz if we let Domoticz no we're running on 100% power.
}
/**
* The Sketch's main loop.
*/
void loop() {
// I have nothing to do if only attach a transmitter.
gw.wait( SLEEP_TIME ); // call the wait routine, which will allow for incomming messages during the waiting
}
void incomingMessage(const MyMessage &message) {
Serial.println("message");
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
char device = 64 + message.sensor; // translate child id to device ID. A = 65 so if we take off one and add the received sensor ID we get the correct device
// Serial.println( "Command received for Device " + (String)device + " on id " + (String)message.sensor + " request to turn " + (message.getBool()?"on":"off") );
if ( device >= 'A' && device <= 'E' ) { // Impuls/Action system only allows device 'A' to 'E'
switchTransmitter.sendSignal(SYSTEMCODE, device, message.getBool() );
}
}
}```