Thanks All,
I got it sort of working using the original circuit with this sketch below, using another variable with last runstate, sorry my coding is shocking.,...
#define MY_DEBUG
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RF69_433MHZ // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
#define MY_IS_RFM69HW // Mandatory if you radio module is the high power version (RFM69HW and RFM69HCW), Comment it if it's not the case
//#define MY_RFM69_NETWORKID 101 // Default is 100 in lib. Uncomment it and set your preferred network id if needed
#include <MySensors.h>
unsigned long SLEEP_TIME = 3600000; // Every hour Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define CHILD_ID 15 // Id of the sensor child
int laststate=0;
// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Motion Sensor", "8.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_MOTION);
}
void loop()
{
// Read digital motion value
bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == LOW;
if ( tripped==1) {
laststate=1;
Serial.print("Generator State = ");
Serial.println(tripped);
}
if (( tripped==1 ) & (laststate==1)) {
//Serial.println("Still Running");
delay(60000);
}
if (tripped==0) {
laststate=0;
Serial.println("Generator OFF");
//send(msg.set(tripped?"1":"0")); // Send tripped value to gw
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), HIGH, SLEEP_TIME);
}
}