@AWI You are right about that internal pull-up. It got even worse when I added an external pull-up. I placed a 10k between pin 3 and GND (for the Door, Window example) and disabled the internal pull-up. When the reed contact is open the sensor pulls only 008.5 uA which is great! When the reed is closed it pulls a whopping 00.32 mA.
I don't know what else to try to bring down that 00.32mA whenever the reed is closed (which will be most of the time because the window will be closed).
I will look into hardware debouncing to see if that will be a solution for the reed switch.
// Simple binary switch example
// Connect button or door/window reed switch between
// digitial I/O pin 3 (BUTTON_PIN below) and GND.
#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>
#define CHILD_ID 3
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define INTERRUPT BUTTON_PIN-2
MySensor gw;
Bounce debouncer = Bounce();
int oldValue=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(CHILD_ID,V_TRIPPED);
void setup()
{
gw.begin();
// Setup the button
pinMode(BUTTON_PIN,INPUT);
// deActivate internal pull-up
digitalWrite(BUTTON_PIN,LOW);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
gw.present(CHILD_ID, S_DOOR);
}
// Check if digital input has changed and send in new value
void loop()
{
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue) {
// Send in the new value
gw.send(msg.set(value==HIGH ? 1 : 0));
oldValue = value;
//Sleep until interrupt comes in on motion sensor. Send update every two minute.
//gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
gw.sleep(INTERRUPT,CHANGE, 0);
}
}