 
					
						
					
				
				
					@ BartE , thanks a lot , I changed all the _Off to _OFF and the same with the On , gw. wait as well. also the 500 to 5000
Working perfectly !
Many thanks
I haven't had a definite anwer yet if libabry 2.x works on vera , I have only read about problems . For the moment I stick to 1.5
edit : one small thing I just noticed , when I switch via the vera Gui the relais to off , it nicely goes back to on after 5 seconds , but it doesn't report back to vera that it is again in an on state.
is there still something wrong with the code?
Again many thanks,
Cor
For future reference:
// Example sketch showing how to control physical relays. 
// This example will remember relay state even after power failure.
#include <MySensor.h>
#include <SPI.h>
#define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
MySensor gw;
void setup()  
{   
  // Initialize library and add callback for incoming messages
  gw.begin(incomingMessage, AUTO, true);
  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("Relay", "1.0");
  // Fetch relay status
  for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);   
    // Set relay to last known state (using eeprom storage) 
     if (gw.loadState(sensor) == RELAY_OFF) {
     digitalWrite(pin, RELAY_OFF);
     gw.wait(5000);
     digitalWrite(pin, RELAY_ON);
}
  }
}
void loop() 
{
  // Alway process incoming messages whenever possible
  gw.process();
}
void incomingMessage(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.type==V_LIGHT) {
     // Change relay state
 if (message.getBool() == RELAY_OFF) {
digitalWrite(message.sensor-1+RELAY_1, RELAY_OFF);
gw.wait(5000);
digitalWrite(message.sensor-1+RELAY_1, RELAY_ON);
}
     // Store state in eeprom
     gw.saveState(message.sensor, message.getBool());
     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   } 
}```