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
  1. Home
  2. Troubleshooting
  3. only wake on interupt..

only wake on interupt..

Scheduled Pinned Locked Moved Troubleshooting
17 Posts 4 Posters 640 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • markjgabbM Offline
    markjgabbM Offline
    markjgabb
    wrote on last edited by
    #5

    ok so yeah it does work....but i think its too sensitive

    i used d2 in the end for the board im using

    but the node seems to trigger every time i even wave my hand near it....

    Literally, node is currently setup with two wires you have to touch together to make the switch. when i wave my hand over it it activates
    im guesing i need to put a resister in place to decrease the sensitivity? currently its just a wire between 3.3 on a pro mini and the d2 wire

    log parse is below

    133795 MCO:SLP:WUP=0
    133797 TSF:TRI:TSB
    133804 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    133810 TSF:MSG:ACK
    133816 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.1
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
    28 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=4
    38 TSM:FPAR
    75 TSF:MSG:SEND,4-4-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    1064 TSF:MSG:READ,0-0-4,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    1071 TSF:MSG:FPAR OK,ID=0,D=1
    1120 TSF:MSG:READ,1-1-4,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    2084 TSM:FPAR:OK
    2084 TSM:ID
    2086 TSM:ID:OK
    2088 TSM:UPL
    2093 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2103 TSF:MSG:READ,0-0-4,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2109 TSF:MSG:PONG RECV,HP=1
    2113 TSM:UPL:OK
    2115 TSM:READY:ID=4,PAR=0,DIS=1
    2129 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2138 TSF:MSG:READ,0-0-4,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2164 TSF:MSG:SEND,4-4-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
    2174 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2189 TSF:MSG:READ,0-0-4,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2238 !TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=11,pt=0,l=19,sg=0,ft=0,st=NACK:Lounge multi button
    2285 !TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:1.1
    2439 !TSF:MSG:SEND,4-4-0-0,s=1,c=0,t=3,pt=0,l=19,sg=0,ft=2,st=NACK:Lounge Light Switch
    2447 MCO:REG:REQ
    2469 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=OK:2
    2478 TSF:MSG:READ,0-0-4,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2484 MCO:PIM:NODE REG=1
    2486 MCO:BGN:STP
    2488 MCO:BGN:INIT OK,TSP=1
    2496 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    Battery percent: 100 %
    3504 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
    3510 TSF:TDI:TSL
    3512 MCO:SLP:WUP=0
    3514 TSF:TRI:TSB
    3520 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    3526 TSF:MSG:ACK
    3563 !TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=NACK:0
    Battery percent: 121 %
    4573 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
    4579 TSF:TDI:TSL
    4581 MCO:SLP:WUP=0
    4583 TSF:TRI:TSB
    4612 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=OK:1
    Battery percent: 121 %
    5621 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
    5627 TSF:TDI:TSL
    5629 MCO:SLP:WUP=0
    5632 TSF:TRI:TSB
    5638 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    5644 TSF:MSG:ACK
    5662 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    Battery percent: 121 %
    Battery Average (Send): 100 %
    6678 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
    6684 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
    6690 TSF:TDI:TSL
    
    
    
    mfalkviddM 1 Reply Last reply
    0
    • markjgabbM markjgabb

      ok so yeah it does work....but i think its too sensitive

      i used d2 in the end for the board im using

      but the node seems to trigger every time i even wave my hand near it....

      Literally, node is currently setup with two wires you have to touch together to make the switch. when i wave my hand over it it activates
      im guesing i need to put a resister in place to decrease the sensitivity? currently its just a wire between 3.3 on a pro mini and the d2 wire

      log parse is below

      133795 MCO:SLP:WUP=0
      133797 TSF:TRI:TSB
      133804 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
      133810 TSF:MSG:ACK
      133816 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
       
       __  __       ____
      |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
      | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
      | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
      |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
              |___/                      2.3.1
      
      16 MCO:BGN:INIT NODE,CP=RNNNA---,REL=255,VER=2.3.1
      28 TSM:INIT
      28 TSF:WUR:MS=0
      34 TSM:INIT:TSP OK
      36 TSF:SID:OK,ID=4
      38 TSM:FPAR
      75 TSF:MSG:SEND,4-4-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      1064 TSF:MSG:READ,0-0-4,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      1071 TSF:MSG:FPAR OK,ID=0,D=1
      1120 TSF:MSG:READ,1-1-4,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      2084 TSM:FPAR:OK
      2084 TSM:ID
      2086 TSM:ID:OK
      2088 TSM:UPL
      2093 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      2103 TSF:MSG:READ,0-0-4,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      2109 TSF:MSG:PONG RECV,HP=1
      2113 TSM:UPL:OK
      2115 TSM:READY:ID=4,PAR=0,DIS=1
      2129 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      2138 TSF:MSG:READ,0-0-4,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      2164 TSF:MSG:SEND,4-4-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.1
      2174 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      2189 TSF:MSG:READ,0-0-4,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      2238 !TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=11,pt=0,l=19,sg=0,ft=0,st=NACK:Lounge multi button
      2285 !TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:1.1
      2439 !TSF:MSG:SEND,4-4-0-0,s=1,c=0,t=3,pt=0,l=19,sg=0,ft=2,st=NACK:Lounge Light Switch
      2447 MCO:REG:REQ
      2469 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=OK:2
      2478 TSF:MSG:READ,0-0-4,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      2484 MCO:PIM:NODE REG=1
      2486 MCO:BGN:STP
      2488 MCO:BGN:INIT OK,TSP=1
      2496 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
      Battery percent: 100 %
      3504 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
      3510 TSF:TDI:TSL
      3512 MCO:SLP:WUP=0
      3514 TSF:TRI:TSB
      3520 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
      3526 TSF:MSG:ACK
      3563 !TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=NACK:0
      Battery percent: 121 %
      4573 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
      4579 TSF:TDI:TSL
      4581 MCO:SLP:WUP=0
      4583 TSF:TRI:TSB
      4612 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=OK:1
      Battery percent: 121 %
      5621 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
      5627 TSF:TDI:TSL
      5629 MCO:SLP:WUP=0
      5632 TSF:TRI:TSB
      5638 TSF:MSG:READ,0-0-4,s=1,c=1,t=2,pt=1,l=1,sg=0:1
      5644 TSF:MSG:ACK
      5662 TSF:MSG:SEND,4-4-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
      Battery percent: 121 %
      Battery Average (Send): 100 %
      6678 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
      6684 MCO:SLP:MS=298000,SMS=0,I1=0,M1=1,I2=255,M2=255
      6690 TSF:TDI:TSL
      
      
      
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #6

      @markjgabb yes, without a pull-down or pull-up resistor, the pin will be floating and not have a defined state.

      1 Reply Last reply
      0
      • skywatchS Offline
        skywatchS Offline
        skywatch
        wrote on last edited by
        #7

        as @mfalkvidd said, you need a resistor between D2 and ground if the switch is connected between D2 and VCC(5V/3.3V). Higher value resistors will reduce current flowing but that's not a big consideration for momentary button presses.

        1 Reply Last reply
        0
        • markjgabbM Offline
          markjgabbM Offline
          markjgabb
          wrote on last edited by
          #8

          Perfect. Tha is for that works great... Interesting thought though with how sensitive it is...

          I was actually just waving my hand near it. Possibly 2-3 inches away from the wires....

          Could be used as something like a plate you slap with your hand

          mfalkviddM 1 Reply Last reply
          0
          • markjgabbM markjgabb

            Perfect. Tha is for that works great... Interesting thought though with how sensitive it is...

            I was actually just waving my hand near it. Possibly 2-3 inches away from the wires....

            Could be used as something like a plate you slap with your hand

            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by
            #9

            @markjgabb yes, that's exactly how touch-based buttons work (and your phone's touchscreen)

            1 Reply Last reply
            0
            • markjgabbM Offline
              markjgabbM Offline
              markjgabb
              wrote on last edited by markjgabb
              #10

              ok stuck now...

              it works once...
              it wakes up each time and send the command
              but in domoticz im using a push on button with a off delay.....
              domoticz is ignoring the sensor after the first on, because the sensor isnt available anymore to receive the command....

              do i possibly need the sensor to send an on command, wait a moment then send its own off command again?

              zboblamontZ 1 Reply Last reply
              0
              • markjgabbM markjgabb

                ok stuck now...

                it works once...
                it wakes up each time and send the command
                but in domoticz im using a push on button with a off delay.....
                domoticz is ignoring the sensor after the first on, because the sensor isnt available anymore to receive the command....

                do i possibly need the sensor to send an on command, wait a moment then send its own off command again?

                zboblamontZ Offline
                zboblamontZ Offline
                zboblamont
                wrote on last edited by
                #11

                @markjgabb Domoticz should display a binary On/Off according to what it is sent, so suggest looking at the Domoticz log for incoming messages, I suspect the OFF is not being sent. Why you are using a Domoticz switch with an off delay I don't understand, a simple on/off is what I use.
                In your modified @skywatch sketch the loop contains battery measurement batM() which itself incorporates a half second delay and Serial.print, suggest rem that out in the loop for now leaving the main loop to work with perhaps a 5 or 10ms delay if the switch is not debounced electrically.

                A momentary rather than latching switch allows a very fast change of state in the region of milliseconds, quite different to a real world device running seconds/minutes/hours in one state or the other.
                In your case you are looking at the interrupt as CHANGE, then reporting the digital state of the pin, any old toggle or light switch would do.

                1 Reply Last reply
                0
                • markjgabbM Offline
                  markjgabbM Offline
                  markjgabb
                  wrote on last edited by markjgabb
                  #12

                  yeah i possibly havent been ecactly clear on that

                  Scenario is that when i walk into a room i dont always want to ask google to turn on or off all the lights in the room.
                  so i plan on having wall mounted momentary switches, which their sole purpose is to if the lights are on, turn them off and if they are off turn them on....

                  so i had planned to use a momentary switch so that no one in the house became focused on if they were off or on, but just push them to get the opposite of current state

                  In domoticz i was going to use a push on button with a dzvents script so that any time the push on on button became on it would toggle the opposite of whatever the state of lights in the room in...

                  obviously a bit more logic is needed in case some lights are on and others off....

                  As per advice i have shortened off the times for delays and have taken out the serial prints on the battery monitor

                  
                  // Enable debug prints
                  #define MY_DEBUG
                  
                  // Enable and select radio type attached
                  #define MY_RADIO_RF24
                  
                  
                  #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                  #define CHILD_ID 1   // Id of the sensor child
                  
                  #include <MySensors.h>
                  
                  unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                  //=========================
                  // BATTERY VOLTAGE DIVIDER SETUP
                  // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                  // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                  // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                  // 3.44/1023 = Volts per bit = 0.003363075
                  #define VBAT_PER_BITS 0.003363075  
                  #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
                  #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
                  int batteryPcnt = 0;                              // Calc value for battery %
                  int batLoop = 0;                                  // Loop to help calc average
                  int batArray[3];                                  // Array to store value for average calc.
                  int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
                  //=========================
                  
                  // Initialize motion message
                  MyMessage msg(CHILD_ID, V_LIGHT);
                  
                  void setup()
                  {
                      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                    analogReference(INTERNAL);
                  }
                  
                  void presentation()
                  {
                    sendSketchInfo("Lounge multi button", "1.1");
                    wait(100);
                    present(CHILD_ID, S_LIGHT, "Lounge Light Switch", true);
                  }
                  
                  void loop()
                  {
                    // Read digital motion value
                     bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                     //Software debounce.....
                     //wait(25);
                     //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                     //if (tripped == tripped1){}
                     //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                     
                     if (tripped == HIGH){
                     send(msg.set(tripped = 1),true);
                     wait(100);
                     send(msg.set(tripped = 0),true);
                     }
                    batM();
                    // Sleep until interrupt on motion sensor. Send update every ten minutes.
                    sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                  }
                  
                  void batM() //The battery calculations
                  {
                     delay(5);
                     // Battery monitoring reading
                     int sensorValue = analogRead(BATTERY_SENSE_PIN);    
                     delay(5);
                     
                     // Calculate the battery in %
                     float Vbat  = sensorValue * VBAT_PER_BITS;
                     int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
                     //Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
                     
                     // Add it to array so we get an average of 3 (3x20min)
                     batArray[batLoop] = batteryPcnt;
                    
                     if (batLoop > 2) {  
                       batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
                       batteryPcnt = batteryPcnt / 3;
                   
                     if (batteryPcnt > 100) {
                       batteryPcnt=100;
                   }
                   
                       Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
                         sendBatteryLevel(batteryPcnt);
                         batLoop = 0;
                        }
                       else 
                       {
                       batLoop++;
                       }
                  }
                  
                  mfalkviddM zboblamontZ 2 Replies Last reply
                  0
                  • markjgabbM markjgabb

                    yeah i possibly havent been ecactly clear on that

                    Scenario is that when i walk into a room i dont always want to ask google to turn on or off all the lights in the room.
                    so i plan on having wall mounted momentary switches, which their sole purpose is to if the lights are on, turn them off and if they are off turn them on....

                    so i had planned to use a momentary switch so that no one in the house became focused on if they were off or on, but just push them to get the opposite of current state

                    In domoticz i was going to use a push on button with a dzvents script so that any time the push on on button became on it would toggle the opposite of whatever the state of lights in the room in...

                    obviously a bit more logic is needed in case some lights are on and others off....

                    As per advice i have shortened off the times for delays and have taken out the serial prints on the battery monitor

                    
                    // Enable debug prints
                    #define MY_DEBUG
                    
                    // Enable and select radio type attached
                    #define MY_RADIO_RF24
                    
                    
                    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                    #define CHILD_ID 1   // Id of the sensor child
                    
                    #include <MySensors.h>
                    
                    unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                    //=========================
                    // BATTERY VOLTAGE DIVIDER SETUP
                    // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                    // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                    // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                    // 3.44/1023 = Volts per bit = 0.003363075
                    #define VBAT_PER_BITS 0.003363075  
                    #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
                    #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
                    int batteryPcnt = 0;                              // Calc value for battery %
                    int batLoop = 0;                                  // Loop to help calc average
                    int batArray[3];                                  // Array to store value for average calc.
                    int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
                    //=========================
                    
                    // Initialize motion message
                    MyMessage msg(CHILD_ID, V_LIGHT);
                    
                    void setup()
                    {
                        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                      analogReference(INTERNAL);
                    }
                    
                    void presentation()
                    {
                      sendSketchInfo("Lounge multi button", "1.1");
                      wait(100);
                      present(CHILD_ID, S_LIGHT, "Lounge Light Switch", true);
                    }
                    
                    void loop()
                    {
                      // Read digital motion value
                       bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                       //Software debounce.....
                       //wait(25);
                       //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                       //if (tripped == tripped1){}
                       //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                       
                       if (tripped == HIGH){
                       send(msg.set(tripped = 1),true);
                       wait(100);
                       send(msg.set(tripped = 0),true);
                       }
                      batM();
                      // Sleep until interrupt on motion sensor. Send update every ten minutes.
                      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                    }
                    
                    void batM() //The battery calculations
                    {
                       delay(5);
                       // Battery monitoring reading
                       int sensorValue = analogRead(BATTERY_SENSE_PIN);    
                       delay(5);
                       
                       // Calculate the battery in %
                       float Vbat  = sensorValue * VBAT_PER_BITS;
                       int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
                       //Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
                       
                       // Add it to array so we get an average of 3 (3x20min)
                       batArray[batLoop] = batteryPcnt;
                      
                       if (batLoop > 2) {  
                         batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
                         batteryPcnt = batteryPcnt / 3;
                     
                       if (batteryPcnt > 100) {
                         batteryPcnt=100;
                     }
                     
                         Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
                           sendBatteryLevel(batteryPcnt);
                           batLoop = 0;
                          }
                         else 
                         {
                         batLoop++;
                         }
                    }
                    
                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by
                    #13

                    @markjgabb when the node is sleeping, it cannot receive messages from Domoticz.

                    1 Reply Last reply
                    0
                    • markjgabbM markjgabb

                      yeah i possibly havent been ecactly clear on that

                      Scenario is that when i walk into a room i dont always want to ask google to turn on or off all the lights in the room.
                      so i plan on having wall mounted momentary switches, which their sole purpose is to if the lights are on, turn them off and if they are off turn them on....

                      so i had planned to use a momentary switch so that no one in the house became focused on if they were off or on, but just push them to get the opposite of current state

                      In domoticz i was going to use a push on button with a dzvents script so that any time the push on on button became on it would toggle the opposite of whatever the state of lights in the room in...

                      obviously a bit more logic is needed in case some lights are on and others off....

                      As per advice i have shortened off the times for delays and have taken out the serial prints on the battery monitor

                      
                      // Enable debug prints
                      #define MY_DEBUG
                      
                      // Enable and select radio type attached
                      #define MY_RADIO_RF24
                      
                      
                      #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                      #define CHILD_ID 1   // Id of the sensor child
                      
                      #include <MySensors.h>
                      
                      unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                      //=========================
                      // BATTERY VOLTAGE DIVIDER SETUP
                      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                      // 3.44/1023 = Volts per bit = 0.003363075
                      #define VBAT_PER_BITS 0.003363075  
                      #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
                      #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
                      int batteryPcnt = 0;                              // Calc value for battery %
                      int batLoop = 0;                                  // Loop to help calc average
                      int batArray[3];                                  // Array to store value for average calc.
                      int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
                      //=========================
                      
                      // Initialize motion message
                      MyMessage msg(CHILD_ID, V_LIGHT);
                      
                      void setup()
                      {
                          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                        analogReference(INTERNAL);
                      }
                      
                      void presentation()
                      {
                        sendSketchInfo("Lounge multi button", "1.1");
                        wait(100);
                        present(CHILD_ID, S_LIGHT, "Lounge Light Switch", true);
                      }
                      
                      void loop()
                      {
                        // Read digital motion value
                         bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                         //Software debounce.....
                         //wait(25);
                         //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                         //if (tripped == tripped1){}
                         //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                         
                         if (tripped == HIGH){
                         send(msg.set(tripped = 1),true);
                         wait(100);
                         send(msg.set(tripped = 0),true);
                         }
                        batM();
                        // Sleep until interrupt on motion sensor. Send update every ten minutes.
                        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                      }
                      
                      void batM() //The battery calculations
                      {
                         delay(5);
                         // Battery monitoring reading
                         int sensorValue = analogRead(BATTERY_SENSE_PIN);    
                         delay(5);
                         
                         // Calculate the battery in %
                         float Vbat  = sensorValue * VBAT_PER_BITS;
                         int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
                         //Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
                         
                         // Add it to array so we get an average of 3 (3x20min)
                         batArray[batLoop] = batteryPcnt;
                        
                         if (batLoop > 2) {  
                           batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
                           batteryPcnt = batteryPcnt / 3;
                       
                         if (batteryPcnt > 100) {
                           batteryPcnt=100;
                       }
                       
                           Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
                             sendBatteryLevel(batteryPcnt);
                             batLoop = 0;
                            }
                           else 
                           {
                           batLoop++;
                           }
                      }
                      
                      zboblamontZ Offline
                      zboblamontZ Offline
                      zboblamont
                      wrote on last edited by
                      #14

                      @markjgabb Wasn't thinking about shortening the battery read but // it out in the loop meantime as it is only a local serial output. Whatever..

                      Ok on the intent, then what you are doing is "illogical", you are reporting the state of the switch not the condition of the light.
                      What you need to do is toggle a separate logic parameter on the Node for a LOW interrupt at the Node, switching ON/OFF the light, report that separate logic state to Domoticz then go to sleep... The interrupt only initiates the action, the Node reports and stores the current state until the next interrupt, Domoticz tells you the last reported state.
                      Whether you control the light at at the button switch Node with a latching relay or command a separate Node is up to you, but Domoticz only reports the last known state...

                      1 Reply Last reply
                      1
                      • markjgabbM Offline
                        markjgabbM Offline
                        markjgabb
                        wrote on last edited by
                        #15

                        @zboblamont
                        haha ok so i went right back to the begining of what you said and got it working now (code below)

                        cut back all unneccicary steps and really locked down what was going on... i can always add back battery part later

                        however now when it comes back online after 5 minutes for heart beat it keep sending a switch command to domoticz...

                        im guessing this is due to the issue where the state is being reported differently after it going to sleep as soon as action is performed....

                        // Enable debug prints
                        #define MY_DEBUG
                        
                        // Enable and select radio type attached
                        #define MY_RADIO_RF24
                        
                        #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                        #define CHILD_ID 1   // Id of the sensor child
                        
                        
                        #include <MySensors.h>
                        
                        unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                        
                        
                        // 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()
                        {
                          sendSketchInfo("Lounge Multi", "3.0");
                          wait(100);
                          present(CHILD_ID, S_DOOR);
                        }
                        
                        void loop()
                        {
                          // Read digital motion value
                           bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                           //Software debounce.....
                           //wait(25);
                           //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                           //if (tripped == tripped1){}
                           //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                           
                           if (tripped == HIGH){
                           send(msg.set(tripped = 1),true);
                           }
                           else if (tripped == LOW){
                           send(msg.set(tripped = 0),true);
                           }
                          
                          // Sleep until interrupt on motion sensor. Send update every ten minutes.
                          sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                        }
                        
                        
                        skywatchS zboblamontZ 2 Replies Last reply
                        0
                        • markjgabbM markjgabb

                          @zboblamont
                          haha ok so i went right back to the begining of what you said and got it working now (code below)

                          cut back all unneccicary steps and really locked down what was going on... i can always add back battery part later

                          however now when it comes back online after 5 minutes for heart beat it keep sending a switch command to domoticz...

                          im guessing this is due to the issue where the state is being reported differently after it going to sleep as soon as action is performed....

                          // Enable debug prints
                          #define MY_DEBUG
                          
                          // Enable and select radio type attached
                          #define MY_RADIO_RF24
                          
                          #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                          #define CHILD_ID 1   // Id of the sensor child
                          
                          
                          #include <MySensors.h>
                          
                          unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                          
                          
                          // 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()
                          {
                            sendSketchInfo("Lounge Multi", "3.0");
                            wait(100);
                            present(CHILD_ID, S_DOOR);
                          }
                          
                          void loop()
                          {
                            // Read digital motion value
                             bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                             //Software debounce.....
                             //wait(25);
                             //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                             //if (tripped == tripped1){}
                             //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                             
                             if (tripped == HIGH){
                             send(msg.set(tripped = 1),true);
                             }
                             else if (tripped == LOW){
                             send(msg.set(tripped = 0),true);
                             }
                            
                            // Sleep until interrupt on motion sensor. Send update every ten minutes.
                            sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                          }
                          
                          
                          skywatchS Offline
                          skywatchS Offline
                          skywatch
                          wrote on last edited by skywatch
                          #16

                          @markjgabb I used the trigger data for a 'heartbeat' so that it looked 'normal' on a graph and the graph updated regularly (otherwise it only updated on a change and that can be a long time indeed for some windows)!

                          The solution might be to immplement the MySensors Heartbeat instead.

                          Just put " sendHeartbeat(); " without the quotes in the sketch main loop. You may still get messages about status, I am not sure as I use MyController for my set-up and never used domoticz
                          .
                          If so you can try and set a memory for the status and only send the tripped message if the status of the last_tripped_status (or whatever you want to call it) has changed.

                          I believe that the relay sketches in 'build' page use a similar approach from memory.

                          Here is a strong hint of how to do it..... :)

                           if (tripped == HIGH && last_tripped == LOW){
                             send(msg.set(tripped = 1),true);
                          last_tripped = HIGH;
                             }
                             else if (tripped == LOW) && last_tripped==HIGH{
                             send(msg.set(tripped = 0),true);
                          last_tripped = LOW;
                             }
                          

                          You need to assign a type bool to last_tripped somewhere and initialise it.

                          1 Reply Last reply
                          0
                          • markjgabbM markjgabb

                            @zboblamont
                            haha ok so i went right back to the begining of what you said and got it working now (code below)

                            cut back all unneccicary steps and really locked down what was going on... i can always add back battery part later

                            however now when it comes back online after 5 minutes for heart beat it keep sending a switch command to domoticz...

                            im guessing this is due to the issue where the state is being reported differently after it going to sleep as soon as action is performed....

                            // Enable debug prints
                            #define MY_DEBUG
                            
                            // Enable and select radio type attached
                            #define MY_RADIO_RF24
                            
                            #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                            #define CHILD_ID 1   // Id of the sensor child
                            
                            
                            #include <MySensors.h>
                            
                            unsigned long SLEEP_TIME = 298000; // Sleep time between reports (in milliseconds)
                            
                            
                            // 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()
                            {
                              sendSketchInfo("Lounge Multi", "3.0");
                              wait(100);
                              present(CHILD_ID, S_DOOR);
                            }
                            
                            void loop()
                            {
                              // Read digital motion value
                               bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
                               //Software debounce.....
                               //wait(25);
                               //bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR);
                               //if (tripped == tripped1){}
                               //send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
                               
                               if (tripped == HIGH){
                               send(msg.set(tripped = 1),true);
                               }
                               else if (tripped == LOW){
                               send(msg.set(tripped = 0),true);
                               }
                              
                              // Sleep until interrupt on motion sensor. Send update every ten minutes.
                              sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                            }
                            
                            
                            zboblamontZ Offline
                            zboblamontZ Offline
                            zboblamont
                            wrote on last edited by zboblamont
                            #17

                            @markjgabb "..cut back all unneccicary steps and really locked down what was going on.." was indeed the idea.

                            What I went on to explain is than you are reporting the state of D3 which goes HIGH/LOW/HIGH via the button, not the light. The critical difference between @skywatch and your install is movement detection maintains a value, your button does not.

                            If you create a variable before the loop, say boolean lightswitch=false; (presuming that the light is ON when you program it) this variable will be changed and reported to Domoticz in the loop.
                            Top of the loop you toggle the "lightswitch" value, first time it will switch false to true, report in the "lightswitch" value then go to sleep.
                            Bottom of the loop your " sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); should trigger on a LOW, as this is the momentary state of D3 ONLY when the button is pressed.
                            Your next button press activates the loop, toggles "lightswitch", reports and goes back to sleep, at least two years on a pair of AA cells.

                            Were it I doing this there would be a mains powered indicator on the switch plate which cuts out when the light is on, A- To find the switch in the dark, B-To provide an indicator which can be used to verify the actual state of the light to ensure it stays in sync (Murphy's Law).
                            I don't see the point of using heartbeat as it is not a security device, and only fire the battery reading mosfet every X loops.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            19

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.1k

                            Posts


                            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                            • Login

                            • Don't have an account? Register

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