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. Sending motion V_TRIPPED and light V_STATUS

Sending motion V_TRIPPED and light V_STATUS

Scheduled Pinned Locked Moved Troubleshooting
14 Posts 3 Posters 2.9k Views 5 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.
  • D dmonty

    I have an outside motion-light sensor/relay. The motion-light logic is hosted on the arduino so the motion-light works when the controller is offline.

    • The motion sensor successfully reports to Domoticz. :grinning:
    • I can turn the lights on/off from Domoticz. :grinning:
    • However, when motion turns on the light, the light status is not being reported to Domoticz. :confused:
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    #define MY_RADIO_NRF24
    
    // Enabled repeater feature for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Bounce2.h>
    
    
    
    #define PIN_S_MOTION_BACK_GARAGE_1 3     // garage motion bench [Brown Stripe]
    #define PIN_S_MOTION_BACK_GARAGE_2 4     // garage motion car door [Green Stripe]
    #define PIN_S_MOTION_BACK_GARAGE_OUT 5   // garage motion outside [Green]
    #define PIN_S_LIGHT_IN 14                // LED lighting relay Use analog as digital A0=14 A5=19
    #define MAX_ATTACHED 16                  // Max attached ds18b20 sensors
    #define CONV_TIME 750                    // conversion time for ds18b20
    #define LONG_WAIT 750                    // long wait between signals
    #define SHORT_WAIT 50                    // short wait between signals
    // non-blocking loop timers
    unsigned long trip_time  =   1000;       // Sleep time between reads (in milliseconds) 1s * 1000ms
    unsigned long light_time = 300000;       // Sleep time before lights turn off ( in ms ) 5min * 60s * 1000ms
    unsigned long lastTripTime = 0;
    
    
    bool lastState[MAX_ATTACHED];
    bool tripped = 0;
    bool isArmed = 0;
    bool isLightOn = 0;
    unsigned long lastLightTime = 0;
    #define ID_S_MOTION_BACK_GARAGE_1 8
    #define ID_S_MOTION_BACK_GARAGE_2 9
    #define ID_S_LIGHT_IN 14
    
    MyMessage msg_S_TEMP       (0,V_TEMP);     
    MyMessage msg_S_TIMER      (7, V_DIMMER);  // Dimmer used to set light countdown timer 1-100%
    MyMessage msg_S_MOTION_T   (8,V_TRIPPED);  // pir motion sensors
    MyMessage msg_S_REED_T     (11,V_TRIPPED); // door/window sensors
    MyMessage msg_S_LIGHTS     (14,V_STATUS);  // light relay switch
    
    
    
    void setup()  
    { 
      pinMode(PIN_S_MOTION_BACK_GARAGE_1,   INPUT);      // sets the motion sensor digital pin as input
      pinMode(PIN_S_MOTION_BACK_GARAGE_2,   INPUT);
      pinMode(PIN_S_LIGHT_IN, OUTPUT);
    }
    
    
    void presentation() {
    
      //Serial.println(""); Serial.println("three");
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Back Garage", "1.1");
      wait(LONG_WAIT);
    
    
    
      present(ID_S_MOTION_BACK_GARAGE_1,   S_MOTION,"BkGrgMotion1");
      wait(LONG_WAIT);
      present(ID_S_MOTION_BACK_GARAGE_2,   S_MOTION,"BkGrgMotion2");
      wait(LONG_WAIT);
      present(ID_S_LIGHT_IN,               S_BINARY,"BkGrgLightIn");
      wait(LONG_WAIT);
    }
    
    void loop()     
    {     
      // check trip sensors every second.
      if ( (millis() - lastTripTime) > trip_time ){
        check_motion(PIN_S_MOTION_BACK_GARAGE_1, ID_S_MOTION_BACK_GARAGE_1);
        check_motion(PIN_S_MOTION_BACK_GARAGE_2, ID_S_MOTION_BACK_GARAGE_2);
        lastTripTime = millis();
      }
      if ( isLightOn == 1 && (millis() - lastLightTime) > light_time ) {
        lights_off();
      }
    }
    
    void check_motion( uint8_t t_pin, uint8_t t_id ){
      int tripped = digitalRead(t_pin) == HIGH;
      if (lastState[t_id] != tripped){
        send(msg_S_MOTION_T.setSensor(t_id).set(tripped));
        lastState[t_id] = tripped;
        wait(LONG_WAIT);
      }
      if (tripped){
        lights_on();
      }
    }
    
    
    void lights_on(){
      if ( isLightOn == 0 ){
        digitalWrite(PIN_S_LIGHT_IN, 1);
        send(msg_S_LIGHTS.setSensor(ID_S_LIGHT_IN).set(1));
        isLightOn = 1;
        wait(LONG_WAIT);
      }
      lastLightTime = millis();
    }
    
    void lights_off(){
      if ( isLightOn == 1 ){
        isLightOn = 0;
        digitalWrite(PIN_S_LIGHT_IN, 0);
        send(msg_S_LIGHTS.setSensor(ID_S_LIGHT_IN).set(0));
      }
    }
    
    void receive(const MyMessage &message){
      switch (message.type) { 
        case V_STATUS:
          if(message.sensor==ID_S_LIGHT_IN) {
            if ( message.getBool() ){
              lights_on();
            } else {
              lights_off();
            }
          }
          break;
      }
    }
    
    dbemowskD Offline
    dbemowskD Offline
    dbemowsk
    wrote on last edited by
    #2

    @dmonty First question, and I realize it is outside of the scope of your question, why don't you have your message definitions using your IDs (ID_S_MOTION_BACK_GARAGE_1, ID_S_LIGHT_IN, etc...)

    MyMessage msg_S_TEMP       (0,V_TEMP);     
    MyMessage msg_S_TIMER      (7, V_DIMMER);  // Dimmer used to set light countdown timer 1-100%
    MyMessage msg_S_MOTION_T   (8,V_TRIPPED);  // pir motion sensors
    MyMessage msg_S_REED_T     (11,V_TRIPPED); // door/window sensors
    MyMessage msg_S_LIGHTS     (14,V_STATUS);  // light relay switch
    

    You have 2 motion sensors defined, but only one to report back.

    Anyways, looking at your code, I cannot see a reason why the light state would not report back. The only thing that I can see that wouldn't report back would be motion sensor 2.

    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmonty
      wrote on last edited by
      #3

      When I was working with the temperature sensors I noticed that MyMessage class could be re-used if the type of sensor is the same. Just set the child-sensor-id before sending the message. This cut down the amount of code and made it easier when looping through similar sensors.

      https://www.mysensors.org/build/temp

      dbemowskD 1 Reply Last reply
      0
      • D dmonty

        When I was working with the temperature sensors I noticed that MyMessage class could be re-used if the type of sensor is the same. Just set the child-sensor-id before sending the message. This cut down the amount of code and made it easier when looping through similar sensors.

        https://www.mysensors.org/build/temp

        dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by
        #4

        @dmonty You may be correct, I always worked on the philosophy that each sensor that needed to report should have it's own MyMessage definition. So do they both report back for you?

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmonty
          wrote on last edited by
          #5

          Yes. Both motion sensors report back fine. I also have a node with door, motion and temperature and they all report back their respective values according to child-sensor-id.

          I'm going to try update and re-compiling the code for the master node. Then watch debugging on the master node. Finally if that doesn't work I'll read through the source code for domoticz and mysensors to see why the light is not reporting back.

          dbemowskD 1 Reply Last reply
          0
          • D dmonty

            Yes. Both motion sensors report back fine. I also have a node with door, motion and temperature and they all report back their respective values according to child-sensor-id.

            I'm going to try update and re-compiling the code for the master node. Then watch debugging on the master node. Finally if that doesn't work I'll read through the source code for domoticz and mysensors to see why the light is not reporting back.

            dbemowskD Offline
            dbemowskD Offline
            dbemowsk
            wrote on last edited by
            #6

            @dmonty Skimming your code, I do not see any issues then that stand out to me. Maybe add some debug prints to see if things are getting where they should in the code.

            Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
            Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dmonty
              wrote on last edited by
              #7

              OK while doing some serial debugging I noticed that the gateway node did not get the right message type: V_TEMP (t=0) should be V_STATUS (t=2).

              TSF:MSG:READ,1-1-0,s=14,c=1,t=0,pt=1,l=1,sg=0:1 Received Message
              Sender: 1
              Last Node: 1
              Destination: 0
              Sensor Id: 14
              Command: SET
              Message Type: V_TEMP
              Payload Type: P_BYTE
              Payload Length: 1
              Signing: 0
              Payload: 1

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dmonty
                wrote on last edited by
                #8

                It may be because the enum is clobbering V_STATUS with old V_LIGHT. Arduino/libraries/MySensors/core/MyMessage.h

                typedef enum {
                        V_TEMP                                  = 0,    //!< S_TEMP. Temperature S_TEMP, S_HEATER, S_HVAC
                        V_HUM                                   = 1,    //!< S_HUM. Humidity
                        V_STATUS                                = 2,    //!< S_BINARY, S_DIMMER, S_SPRINKLER, S_HVAC, S_HEATER. Used for setting/reporting binary (on/off) status. 1=on, 0=off
                        V_LIGHT                                 = 2,    //!< \deprecated Same as V_STATUS, **** DEPRECATED, DO NOT USE ****
                        V_PERCENTAGE                    = 3,    //!< S_DIMMER. Used for sending a percentage value 0-100 (%).
                
                
                1 Reply Last reply
                0
                • gohanG Offline
                  gohanG Offline
                  gohan
                  Mod
                  wrote on last edited by
                  #9

                  What version of mysensors are you using?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dmonty
                    wrote on last edited by
                    #10

                    Version 2.1.1

                    This morning I found I did some serial debugging on the sender and master node.
                    I had to re-initiate the Sensor ID and the Sensor Type before sending.

                        isLightOn = 1;
                        msg_S_LIGHTS.setSensor(ID_S_LIGHT);
                        msg_S_LIGHTS.setType(V_STATUS);
                        send(msg_S_LIGHTS.set(isLightOn),true);
                    

                    Without doing this the wrong type is sent from the node itself.

                    9234 TSF:MSG:SEND,1-1-0-0,s=15,c=0,t=3,pt=0,l=10,sg=0,ft=0,st=OK:SdGrgLight
                    9243 TSF:MSG:READ,0-0-1,s=15,c=0,t=3,pt=0,l=10,sg=0:SdGrgLight
                    9249 TSF:MSG:ACK
                    9991 MCO:REG:REQ
                    9996 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
                    10002 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                    10007 MCO:PIM:NODE REG=1
                    10009 MCO:BGN:STP
                    10150 MCO:BGN:INIT OK,TSP=1
                    27173 TSF:MSG:SEND,1-1-0-0,s=9,c=1,t=16,pt=1,l=1,sg=0,ft=0,st=OK:1
                    27938 TSF:MSG:SEND,1-1-0-0,s=15,c=1,t=0,pt=1,l=1,sg=0,ft=0,st=OK:1
                    

                    Sent Message
                    Sender: 1
                    Last Node: 1
                    Next Node: 0
                    Destination: 0
                    Sensor Id: 15
                    Command: SET
                    Message Type:V_TEMP
                    Payload Type: P_BYTE
                    Payload Length: 1
                    Signing: 0
                    Failed uplink counter: 0
                    Status: OK (OK=success, NACK=no radio ACK received)
                    Payload: 1

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dmonty
                      wrote on last edited by
                      #11

                      I tried uploading a simple Light on/off delay loop sending only light status from the node. I can confirm that the master node receives the message on the serial interface. However Domoticz does not log any incoming actions. So my thoughts are now that Domoticz does not handle light-status send-updates from the nodes.

                          msg_S_LIGHTS.setSensor(ID_S_LIGHT);
                          msg_S_LIGHTS.setType(V_STATUS);
                          send(msg_S_LIGHTS.set(isLightOn==1 ? "1" : "0"),true);
                      

                      Message Type: V_STATUS
                      Payload Type: P_STRING

                          msg_S_LIGHTS.setSensor(ID_S_LIGHT);
                          msg_S_LIGHTS.setType(V_STATUS);
                          send(msg_S_LIGHTS.set(isLightOn),true);
                      

                      Message Type: V_STATUS
                      Payload Type: P_BYTE

                          msg_S_LIGHTS.setSensor(ID_S_LIGHT);
                          msg_S_LIGHTS.setType(V_TRIPPED);
                          send(msg_S_LIGHTS.set(isLightOn),true);
                      

                      Message Type: V_TRIPPED
                      Payload Type: P_BYTE

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dmonty
                        wrote on last edited by
                        #12

                        Tried MockMySensors Example - with a light on/off loop and no radio and Domoticz updates light status based on Arduino code. This means Domoticz supports receiving update status for lights.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dmonty
                          wrote on last edited by
                          #13

                          I tracked down the issue. My real sketch had too many large variables using up too much memory. Because the Lights were being declared later they were getting clobbered. After decreasing the number of sensors everything started working fine.

                          1 Reply Last reply
                          0
                          • gohanG Offline
                            gohanG Offline
                            gohan
                            Mod
                            wrote on last edited by
                            #14

                            You could check the code and try using smaller variable types to something that you actually need

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


                            25

                            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