Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
ChakkieC

Chakkie

@Chakkie
About
Posts
31
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • NRF24l01+ vs. NRF24l01+ pa + lna
    ChakkieC Chakkie

    @meju25

    Unfortunately I have the exact same problem with the amplified version. I have two of them and tried all the mentioned solutions (power, shielding etc) on both modules but none of them work. On the contrary the amplifier version works much worst then the normal version. So I have just given up on this module and put some of the normal NRF as repeater.

    May be as one has mentioned, the Chinese module does not work properly. However the normal NRF module are all from China.

    Troubleshooting

  • Adjust / change total energy (kwh) and water (liter) value of the controller or GW
    ChakkieC Chakkie

    @mfalkvidd Thanks

    The idea of changing the pulseCount is correct. However I had set the value at the wrong place without realizing the pulseCount is reset at the Void setup() section.

     // Water Reset pulsecount
      pulseCountW = oldPulseCountW = 0;
    
      // Zonnepanelen Reset pulsecount
      pulseCountZ = oldPulseCountZ = 0;
    

    The solution is

    Change the 0 to : Value (meter) - Value (Controller)

    Upload the sketch. wait until the first pulse is sent to the gateway.

    If successed the controller (domoticz in my case) will show the total value matching the value on the physical meter.

    Now change the value in the sketch back to 0. (Otherwise each time you reset the sensor or the gateway the value wil be added to the total value.) Upload the sketch to the sensor.

    You are done. There is no need to Modify the Domoticz database with SQL tool.

    You will get the value you've just added to the total value in the day value log. If you find this ignoring you can delete this value the next day. This only applies to Energy meter. Do not apply this to the water meter as the result the total value of the water meter will be gone too.

    General Discussion

  • Adjust / change total energy (kwh) and water (liter) value of the controller or GW
    ChakkieC Chakkie

    I use the following script to log my energy and water meter. I have tried to change the total value to match the actual value on my energy & water meter by changing the pulseCount.

    Does anyone if this is possibleow to do it and h. Thanks

    ![alt text](0_1464972474986_upload-9c76a914-cceb-49b6-bc74-cbe6cf6d008e image url)

    /**
     * based on the pulsecounter sketches form www.mysensors.org
     * changed for S0 ports and working without interrupts which
     * make ghost pulsecounts disappear with the use of S0 ports
     *
     * Combined and changed by Mediacj september/okt/nov 2015
     *
     */
    
    #include <SPI.h>
    #include <MySensor.h>
    
    //water
    #define DIGITAL_INPUT_SENSORW 3  // The digital input for the S0 bus wire
    #define PULSE_FACTORW 1000       // Nummber of rotations per m3 of your meter
    #define CHILD_IDW 10             // Id of the sensor child
    
    //zonnepanelen
    #define DIGITAL_INPUT_SENSORZ 5  // The digital input for the S0 bus wire
    #define PULSE_FACTORZ 1000       // Nummber of blinks per KWH of your meter
    #define MAX_WATT 10000            // Max watt value to report. This filetrs outliers.
    #define CHILD_IDZ 11             // Id of the sensor child
    
    MySensor gw;
    //Water
    double ppwhW = ((double)PULSE_FACTORW) / 1000; // Pulses per watt hour
    boolean pcReceivedW = false;
    volatile unsigned long pulseCountW = 0;
    volatile double volume = 0;
    unsigned long oldPulseCountW = 0;
    double oldVolume;
    unsigned long lastSendW;
    unsigned long nulw;//tijd sinds de laatste 0 waarde
    
    //Zonnepanelen
    double ppwhZ = ((double)PULSE_FACTORZ) / 1000; // Pulses per watt hour
    boolean pcReceivedZ = false;
    volatile unsigned long pulseCountZ = 0;
    unsigned long oldPulseCountZ = 0;
    volatile unsigned long watt = 0;
    unsigned long oldWatt = 0;
    double kwh;
    double oldKwh = 0;
    unsigned long lastSendZ;
    unsigned long nulz;//tijd sinds de laatste 0 waarde
    
    //Water
    MyMessage volumeMsg(CHILD_IDW, V_VOLUME);
    MyMessage pcMsgw(CHILD_IDW, V_VAR1);
    volatile unsigned long pulseLengthW = 0;
    volatile unsigned long lastMillisW = 0;
    boolean timeReceivedW = false;
    boolean sensorIsOnW = false;
    
    //Zonnepanelen
    MyMessage wattMsg(CHILD_IDZ, V_WATT);
    MyMessage kwhMsg(CHILD_IDZ, V_KWH);
    MyMessage pcMsgz(CHILD_IDZ, V_VAR2);
    volatile unsigned long pulseLengthZ = 0;
    volatile unsigned long lastMillisZ = 0;
    boolean timeReceivedZ = false;
    boolean sensorIsOnZ = false;
    int tellerkwh = 0;
    
    void setup()
    {
      gw.begin(incomingMessage);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Water en Energie Meter", "10.0");
      delay(1000);
    
      // Register this device as watersensor
      gw.present(CHILD_IDW, S_WATER);
      // Register this device as power sensor
      delay(1000);
      gw.present(CHILD_IDZ, S_POWER);
    
      // Water Reset pulsecount
      pulseCountW = oldPulseCountW = 0;
    
      // Zonnepanelen Reset pulsecount
      pulseCountZ = oldPulseCountZ = 0;
    
      pinMode(DIGITAL_INPUT_SENSORW, INPUT_PULLUP);       // Enable internal pull-up resistor on pin 3
      pinMode(DIGITAL_INPUT_SENSORZ, INPUT_PULLUP);       // Enable internal pull-up resistor on pin 5
      lastSendW = millis();
      lastSendZ = millis();
    
      // Fetch last known pulses value from gw
      gw.request(CHILD_IDW, V_VAR1);
      gw.request(CHILD_IDZ, V_VAR2);
    
    }
    
    
    void loop()
    {
      gw.process();
      unsigned long now = millis();
    
      //Zonnepanelen#############################
      // read the digital input
      bool solarInput = digitalRead(DIGITAL_INPUT_SENSORZ);
      // rising edge?
      if(solarInput && sensorIsOnZ == false)
      {
        sensorIsOnZ = true;
      }
      // falling edge?
      if(!solarInput && sensorIsOnZ == true)
      {
        pulseLengthZ = micros() - lastMillisZ;
        //store the time for the next pulse
        lastMillisZ = micros();
        // update counters and send to gateway
        pulseCountZ++;
    
        //Last Pulsecount not yet received from controller, request it again
        if (!pcReceivedZ)
        {
          gw.request(CHILD_IDZ, V_VAR2);
          return;
        }
        gw.send(pcMsgz.set(pulseCountZ)); // Send zppulsecount value to gw in VAR2
        watt = (((3600000000.0 / pulseLengthZ) / ppwhZ)); //was 1.0118 personal multiply factor not necessary (1.0115)
        if(watt != oldWatt && watt < ((unsigned long)MAX_WATT))
        {
          Serial.println(watt);
          gw.send(wattMsg.set(watt));
        }; // Send watt value to gw
        oldWatt = watt;
        lastSendZ = now;
        sensorIsOnZ = false;
        tellerkwh++;
        if (tellerkwh == 2)
        {
          double kwh = ((double)pulseCountZ / ((double)PULSE_FACTORZ)); //was 1.0118 personal multiply factor not necessary
          oldKwh = kwh;
          tellerkwh  = 0;
          Serial.println(kwh);
          gw.send(kwhMsg.set(kwh, 4));// Send kwh value to gw. 4 mean 4 digits before the comma
        };
      }
    
    
      // Watermeter###########################
      // read the digital input
      bool waterInput = digitalRead(DIGITAL_INPUT_SENSORW);
      // rising edge?
      if(waterInput && sensorIsOnW == false)
      {
        sensorIsOnW = true;
      }
      // falling edge?
      if(!waterInput && sensorIsOnW == true)
      {
        //controle
        if ((micros() - lastMillisW) < 3000000L)
        {
          return;   //Sometimes we get interrupt on RISING, = 3 sek debounce
        }
        // store the time between the last two pulses
        pulseLengthW = micros() - lastMillisW;
        //store the time for the next pulse
        lastMillisW = micros();
        // update counters
        pulseCountW++;
        //Last Pulsecount not yet received from controller, request it again
        if (!pcReceivedW)
        {
          gw.request(CHILD_IDW, V_VAR1);
          return;
        }
        gw.send(pcMsgw.set(pulseCountW)); // Send waterpulsecount value to gw in VAR2
        sensorIsOnW = false;
        double volume = ((double)pulseCountW / ((double)PULSE_FACTORW));
        oldPulseCountW = pulseCountW;
        Serial.println(volume);
        gw.send(volumeMsg.set(volume, 3));  // Send volume value to gw. 3 mean 3 digits before the comma
        oldVolume = volume;
        lastSendW = now;
      }
    
      //Water na 10 minuten geen pulse laatste waarde herhalen
    //  if ((now - lastSendW) > 600000)
    //  {
    //    gw.send(volumeMsg.set(oldVolume, 3));
    //    
    //    lastSendW = now;
    //    nulw = millis();
    //  }
    //
    //  //Zonnepanelen na 12 minuten geen pulse 0 waarde sturen
    //  if ((now - lastSendZ) > 720000)
    //  {
    //    watt = 0;
    //    gw.send(wattMsg.set(watt));
    //    lastSendZ = now;
    //    nulz = millis();
    //    gw.send(kwhMsg.set(oldKwh, 4));
    //  }
    }
    
    void incomingMessage(const MyMessage &message)
    {
      if (message.type == V_VAR1)
      {
        unsigned long gwPulseCountW = message.getULong();
        pulseCountW += gwPulseCountW;
        volume = oldVolume = 0;
        Serial.print("Received last water pulse count from gw:");
        Serial.println(pulseCountW);
        pcReceivedW = true;
      }
    
      if (message.type == V_VAR2)
      {
        unsigned long gwPulseCountZ = message.getULong();
        pulseCountZ += gwPulseCountZ;
        kwh = oldKwh = 0;
        Serial.print("Received last zon pulse count from gw:");
        Serial.println(pulseCountZ);
        pcReceivedZ = true;
      }
    }
    
    General Discussion

  • Buzzer when door opened longer than X seconds
    ChakkieC Chakkie

    @Boots33 Thanks for the help. The main problem was how to set the time when the doors are opened. I have tried several attempts and everytime the timer is reset. Therefore the buzzer will never be triggered because the timer and the current time is always the same.

    I have solved this problem. The working script is here below:

    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define CHILD_ID_Koel 31
    #define CHILD_ID_Vries 32
    #define BUTTON_PIN_Koel  7  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON_PIN_Vries  8  // Arduino Digital I/O pin for button/reed switch
    #define INTERRUPT BUTTON_PIN_Koel -2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define INTERRUPT BUTTON_PIN_Vries -2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define buzzPin 2 // I/O-pin from buzzer connects here
    
    unsigned long currentMillisKoel;
    unsigned long currentMillisVries;
    
    MySensor gw;
    Bounce debouncerKoel = Bounce();
    Bounce debouncerVries = Bounce();
    int oldValueKoel = -1;
    int oldValueVries = -1;
    int KoelBuzz = 0;
    int VriesBuzz = 0;
    
    unsigned long DoorDelay = 5000UL;
    unsigned long KoelTimer = 0UL;
    unsigned long VriesTimer = 0UL;
    
    MyMessage msgKoel(CHILD_ID_Koel, V_TRIPPED);
    MyMessage msgVries(CHILD_ID_Vries, V_TRIPPED);
    
    void setup()
    {
      gw.begin(NULL, 204, false, 0);
    
      // Setup the button
      pinMode(BUTTON_PIN_Koel, INPUT);
      pinMode(BUTTON_PIN_Vries, INPUT);
    
      //Buzz pin
      pinMode(buzzPin, OUTPUT);
      digitalWrite(buzzPin, HIGH);
    
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN_Koel, HIGH);
      digitalWrite(BUTTON_PIN_Vries, HIGH);
      // After setting up the button, setup debouncer
      debouncerKoel.attach(BUTTON_PIN_Koel);
      debouncerVries.attach(BUTTON_PIN_Vries);
      debouncerKoel.interval(5);
      debouncerVries.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_Koel, S_DOOR);
      gw.present(CHILD_ID_Vries, S_DOOR);
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
    
      // Fridge door script
      debouncerKoel.update();
      // Get the update value
      int valueKoel = debouncerKoel.read();
    
      if (valueKoel != oldValueKoel) {
        // Send in the new value
        gw.send(msgKoel.set(valueKoel == HIGH ? 0 : 1)); // change this value to if NC then 0 : 1; if NO then 1 : 0
        oldValueKoel = valueKoel;
        KoelBuzz = digitalRead(BUTTON_PIN_Koel);
        Serial.println(KoelBuzz);
        if (KoelBuzz == LOW) { //Door is open.
          KoelTimer = millis(); //  Set the time. 
          Serial.println(KoelTimer);
        }
      }
    
      // check how long the doors are opened
      unsigned long currentMillisKoel = millis();
      if ((currentMillisKoel - KoelTimer) >= DoorDelay && KoelBuzz == LOW) {
    //    Serial.println("Counter start");
    //    Serial.println(KoelTimer);
    //    Serial.println(currentMillisKoel);
        digitalWrite(buzzPin, KoelBuzz); // Tone ON
    //    Serial.println("Buzzer triggerd");
    
      }
    
    
    // Freezer door script
      debouncerVries.update();
      // Get the update value
      int valueVries = debouncerVries.read();
    
    
      if (valueVries != oldValueVries) {
        // Send in the new value
        gw.send(msgVries.set(valueVries == HIGH ? 0 : 1)); // change this value to if NC then 0 : 1; if NO then 1 : 0
        oldValueVries = valueVries;
        VriesBuzz = digitalRead(BUTTON_PIN_Vries);
        Serial.println(VriesBuzz);
        if (VriesBuzz == LOW) { //Door is open.
          VriesTimer = millis(); //  Set the time. 
          Serial.println(VriesTimer);
        }
      }
      if (VriesBuzz && KoelBuzz == HIGH) {
        digitalWrite(buzzPin, VriesBuzz); // Tone OFF
      }
      
      // check how long the doors are opened
      unsigned long currentMillisVries = millis();
      if ((currentMillisVries - VriesTimer) >= DoorDelay && VriesBuzz == LOW) {
    //    Serial.println("Counter start");
    //    Serial.println(VriesTimer);
    //    Serial.println(currentMillisVries);
        digitalWrite(buzzPin, VriesBuzz); // Tone ON
    //    Serial.println("Buzzer triggerd");
    
      }
    
    // Sleep until interrupt comes in on motion sensor. Send update every two minute.
    //  gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    //  Serial.println("sleep");
    }
    
    General Discussion

  • Buzzer when door opened longer than X seconds
    ChakkieC Chakkie

    Hi All,

    I have got the buzzer module today and I want to use it on my exist frigde door contact sensor. What I want to do is when one of the fridge door is open more than 30 seconds the buzzer will turn on. And when door is closed the buzz stops.

    The full code is here below:

    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define CHILD_ID_Koel 31
    #define CHILD_ID_Vries 32
    #define BUTTON_PIN_Koel  7  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON_PIN_Vries  8  // Arduino Digital I/O pin for button/reed switch
    #define INTERRUPT BUTTON_PIN_Koel -2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define INTERRUPT BUTTON_PIN_Vries -2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define buzzPin 2 // I/O-pin from buzzer connects here
    
    unsigned long currentMillis = millis();
    
    MySensor gw;
    Bounce debouncerKoel = Bounce();
    Bounce debouncerVries = Bounce();
    int oldValueKoel = -1;
    int oldValueVries = -1;
    int buzz = 0;
    
    unsigned long DoorDelay = 30000;
    unsigned long DoorMillis;
    
    MyMessage msgKoel(CHILD_ID_Koel, V_TRIPPED);
    MyMessage msgVries(CHILD_ID_Vries, V_TRIPPED);
    
    void setup()
    {
      gw.begin(NULL, 204, false, 0);
    
      // Setup the button
      pinMode(BUTTON_PIN_Koel, INPUT);
      pinMode(BUTTON_PIN_Vries, INPUT);
    
      //Buzz pin
      pinMode(buzzPin, OUTPUT);
      digitalWrite(buzzPin, HIGH);
    
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN_Koel, HIGH);
      digitalWrite(BUTTON_PIN_Vries, HIGH);
      // After setting up the button, setup debouncer
      debouncerKoel.attach(BUTTON_PIN_Koel);
      debouncerVries.attach(BUTTON_PIN_Vries);
      debouncerKoel.interval(5);
      debouncerVries.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_Koel, S_DOOR);
      gw.present(CHILD_ID_Vries, S_DOOR);
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
      debouncerKoel.update();
      // Get the update value
      int valueKoel = debouncerKoel.read();
    
      if (valueKoel != oldValueKoel) {
        // Send in the new value
        gw.send(msgKoel.set(valueKoel == HIGH ? 0 : 1)); // change this value to if NC then 0 : 1; if NO then 1 : 0
        oldValueKoel = valueKoel;
    
      }
    
    
    
      debouncerVries.update();
      // Get the update value
      int valueVries = debouncerVries.read();
    
      if (valueVries != oldValueVries) {
        // Send in the new value
        gw.send(msgVries.set(valueVries == HIGH ? 0 : 1)); // change this value to if NC then 0 : 1; if NO then 1 : 0
        oldValueVries = valueVries;
        buzz = digitalRead(BUTTON_PIN_Vries);
        Serial.println(buzz);
    
        if (buzz == HIGH) {
          digitalWrite(buzzPin, buzz); // Tone OFF
          Serial.println("Buzzer off");
        }
        if (buzz == LOW) {
          DoorMillis = millis();
          Serial.println("Counter start");
          Serial.println(DoorMillis);
        }
    
        if ((millis() - DoorMillis) > DoorDelay) {
          digitalWrite(buzzPin, buzz); // Tone ON
          Serial.println("Buzzer triggerd");
    
        }
    
      }
    
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      //  gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      //  Serial.println("sleep");
    }
    

    Below is part of the code where I tired to get the code work. I think I am doing something wrong.

    debouncerVries.update();
      // Get the update value
      int valueVries = debouncerVries.read();
    
      if (valueVries != oldValueVries) {
        // Send in the new value
        gw.send(msgVries.set(valueVries == HIGH ? 0 : 1)); // change this value to if NC then 0 : 1; if NO then 1 : 0
        oldValueVries = valueVries;
        buzz = digitalRead(BUTTON_PIN_Vries);
        Serial.println(buzz);
    
        if (buzz == HIGH) {
          digitalWrite(buzzPin, buzz); // Tone OFF
          Serial.println("Buzzer off");
        }
        if (buzz == LOW) {
          DoorMillis = millis();
          Serial.println("Counter start");
          Serial.println(DoorMillis);
        }
    
        if ((millis() - DoorMillis) > DoorDelay) {
          digitalWrite(buzzPin, buzz); // Tone ON
          Serial.println("Buzzer triggerd");
    
        }
    

    Does anyone know how the code should look like

    Thanks

    General Discussion

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @AWI

    Thanks for the info. I thought you always have to add the sleep time to the gw.sleep. I will disable the a wake timer by removing the 86400000.

    @siod I use one switch for the letterbox and one for the door.

    My Project

  • Motion Sensor triggering on its own
    ChakkieC Chakkie

    I have the same issue first when I tried to power the PIR with the VCC from the arduino mini pro 3.3V. It seems like the PIR does not work with 3.3V. Now I power the PIR directly from the 9V battery. Problem solved.

    Troubleshooting

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @AWI thanks. this looks like more promising.

    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @AWI Thanks this clear thinks up but at the same time also confusing too.

    So "-2" activates both 0 and 1 on pin 2 or pin 3 as you mentioned earlier. I always though it represents a pin number.

    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @mfalkvidd Thanks for the info. Does DigitalPinTolnterrupt works better?

    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @AWI Thanks. By the way would you care to explain the interrupt index number? or may be a link for explanation?

    My Project

  • Magnetic Door Switch with Buzzer
    ChakkieC Chakkie

    @knipex Hi can you please post your working script?? I want the same functionality too. Thanks

    Troubleshooting

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @AWI Thank you so much. Yes I have came to the conclusion that the debouncer does not seems to work fine with sleep function. So I have used a method other than debouncer.

    Here the working script below:

    #include <MySensor.h>
    #include <SPI.h>
    
    
    #define CHILD_ID_Deur 11
    #define CHILD_ID_Post 12
    #define BUTTON_PIN_Deur  2  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON_PIN_Post  3  // Arduino Digital I/O pin for button/reed switch
    
    MySensor gw;
    
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msgDeur(CHILD_ID_Deur,V_TRIPPED);
    MyMessage msgPost(CHILD_ID_Post,V_TRIPPED);
    
    void setup()  
    {  
      gw.begin();
    gw.sendSketchInfo("Voordeur contacts", "1.0");
     // Setup the button
      pinMode(BUTTON_PIN_Deur,INPUT);
      pinMode(BUTTON_PIN_Post,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN_Deur,HIGH);
      digitalWrite(BUTTON_PIN_Post,HIGH);
    
      // 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_Deur, S_DOOR);
      gw.present(CHILD_ID_Post, S_DOOR);   
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      uint8_t value;
      static uint8_t sentValue = 2;
      static uint8_t sentValue2 = 2;
    
      // Short delay to allow buttons to properly settle
      gw.sleep(5);
    
      value = digitalRead(BUTTON_PIN_Deur);
    
      if (value != sentValue) {
        // Value has changed from last transmission, send the updated value
        gw.send(msgDeur.set(value == HIGH ? 1 : 0));
        sentValue = value;
      }
    
      value = digitalRead(BUTTON_PIN_Post);
    
      if (value != sentValue2) {
        // Value has changed from last transmission, send the updated value
        gw.send(msgPost.set(value == HIGH ? 1 : 0));
        sentValue2 = value;
      }
    
    
      // Sleep until something happens with the sensor
      gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000);// changing Secondary button to correct pin (-3) does not work. So keep it on (-2)
      Serial.println("Sleep");
    
    }
    
    

    Notice that the script does not work properly when I set BUTTON_PIN_Post - 3. The button pin post will not trigger. But when I change it to -2, both switches will work

    gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000);
    
    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @sundberg84 I have debugged a several times. I am now sure it is not a hardware failure.

    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @mfalkvidd Hi thanks

    Changing the sleep time to 0 does not help. When I open and close the contact the status will not be sent. That's weird

    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    @sundberg84

    I have added some print to debugged. It seems like the code with sleep does not verify and send the high 1 or low 0 when I open and close the contact. See the serial debug log. The repeated sleep in the log is when i open and close the contact. Normally it will send 1 or 0 " send: 204-204-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,st=ok:0"

    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         Serial.println("Trigger");
         gw.send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }     
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      Serial.println("Sleep");
    
    send: 204-204-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 204-204-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 204-204-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-204 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=204, parent=0, distance=1
    send: 204-204-0-0 s=3,c=0,t=0,pt=0,l=0,sg=0,st=ok:
    Trigger
    send: 204-204-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,st=ok:0
    Sleep
    Sleep
    Sleep
    Sleep
    Sleep
    Sleep
    Sleep
    Sleep
    
    My Project

  • gw.sleep on battery powered magnet door switch
    ChakkieC Chakkie

    Hi all,

    I have made a magnet door contact using a Arduino mini Pro 3v3 powered with 2 coin cells battery. To save battery life, I want to use gw.sleep to let the Arduino mini to sleep and trigger when the door is open.

    Unfortunately, the arduino is not trigger when contact is open or closed due to gw.sleep. I was wonder how to use the sleep comment and still making the debounce action works. I have tried to use INTERRUPT but with no luck.

    Thanks

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    #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 // Usually the interrupt = pin -2 (on uno/nano anyway)
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    
    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);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      
      // 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;
      }
     
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      
      
    } 
    
    
    My Project

  • RFID Garage door opener
    ChakkieC Chakkie

    @BartE

    I've just solved the issue regarding tags lost after power off.

    Simply add the line "StoreEeprom();" after the program mode function

      if (programmode && ((timer % (ONE_SEC / HEARTBEAT)) == 0 ))  {
                ledon = !ledon;
                digitalWrite(LED_PIN, ledon);
                programTimer++;
    
                // Stop program mode after 20 sec inactivity
                if (programTimer > PROG_WAIT)  {
                   programmode = false;
                   digitalWrite(LED_PIN, false);
                   Serial.println(F("Program expired"));  
    
                   storeEeprom();
                   Serial.println(F("Store Card to EEPROM"));  ```
    My Project

  • RFID Garage door opener
    ChakkieC Chakkie

    @BartE

    Hi BartE, I have the same issue regarding tags lost after power off. I run the debug instruction using Serial print as you mentioned. I found out that the storeEeprom line did not run after closing the program mode. I think this is why the tags are lost after power cycle.

    send: 210-210-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 210-210-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 210-210-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-210 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=210, parent=0, distance=1
    send: 210-210-0-0 s=255,c=3,t=11,pt=0,l=9,sg=0,st=ok:RFID Lock
    send: 210-210-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.1
    send: 210-210-0-0 s=2,c=0,t=19,pt=0,l=0,sg=0,st=ok:
    send: 210-210-0-0 s=1,c=0,t=1,pt=0,l=0,sg=0,st=ok:
    RecallEeprom
    MFRC522 Software Version: 0x92 = v2.0
    send: 210-210-0-0 s=1,c=1,t=15,pt=2,l=2,sg=0,st=ok:1
    Init done...
    Switch 1
    Card UID: 26 13 80 41
    Invalid card
    send: 210-210-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
    send: 210-210-0-0 s=1,c=1,t=16,pt=2,l=2,sg=0,st=ok:0
    release
    Card UID: xx xx xx xx
    Program mode
    release
    Card UID: xx xx xx xx
    new card
    release
    Program expired
    

    Thanks

    My Project

  • RGB LED strip amplifier gives inverted RGB value
    ChakkieC Chakkie

    Hi TheoL,

    I have changed the value from 0 to 255 as shown below and now the LED strip turn off when I click the off button in domoticz.

    Now the dimming part has yet to be solved :)

    ![alt text](0_1459697790250_upload-deea4aa9-4d91-4afa-af88-b87a342aed1e image url)

    Was

     if (message.type == V_LIGHT) {
        if (message.getInt() == 0) {
          digitalWrite(RED_PIN, 255);
          digitalWrite(GREEN_PIN, 255);
          digitalWrite(BLUE_PIN, 255);```
    Domoticz
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular