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. Controllers
  3. Domoticz
  4. Of 2 sensors on a node only one reports values

Of 2 sensors on a node only one reports values

Scheduled Pinned Locked Moved Domoticz
11 Posts 5 Posters 4.0k 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.
  • L LastSamurai

    I am testing a soil moisture sensor that has both a digital and an analog output. So I took the example sketch and added a V_LIGHT_LEVEL sensor for the analog value (is there a better choice somewhere?). The V_TRIPPED sensor for the digital part is unchanged.
    Both sensors appear in Domoticz, but only the analog updates.
    Is there a stupid error in the code I overlooked?

    #include <SPI.h>
    #include <MySensor.h>  
    
    #define DIGITAL_INPUT_SOIL_SENSOR 3   // Digital input did you attach your soil sensor.
    #define ANALOG_INPUT_SOIL_SENSOR A0
    #define CHILD_ID 0   // Id of the sensor child
    #define CHILD_ID_2 1
    #define sleepTime 30000
    
    MySensor gw;
    MyMessage msg(CHILD_ID, V_TRIPPED);
    MyMessage msgLevel(CHILD_ID_2, V_LIGHT_LEVEL);
    
    void setup()  
    { 
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Soil Moisture Sensor", "1.0");
      // sets the soil sensor digital pin as input
      pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT); 
      pinMode(ANALOG_INPUT_SOIL_SENSOR, INPUT);   
      // Register all sensors to gw (they will be created as child devices)  
      gw.present(CHILD_ID, S_MOTION);
      gw.present(CHILD_ID_2, S_LIGHT_LEVEL);
    }
     
    void loop()     
    {     
      // Read digital soil value
      int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water 
      int soilAnalog = analogRead(ANALOG_INPUT_SOIL_SENSOR);
      
        Serial.println(soilValue);
        Serial.println(soilAnalog);
        gw.send(msg.set(soilValue==0?1:0));  // Send the inverse to gw as tripped should be when no water in soil
        gw.send(msgLevel.set(soilAnalog));
    
      gw.sleep(sleepTime);
    }
    

    Thanks for the help :)

    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #2

    @LastSamurai What about S_MOISTURE. (is in the API description). There is a soil moisture sensor in the Domoticz beta. i don't see strange things in your sketch other than that you are not "mapping" the analog value to something sensible (if needed at all)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LastSamurai
      Hardware Contributor
      wrote on last edited by LastSamurai
      #3

      Thanks! I did overlook the S_MOISTURE. I made a new sketch using that one. I also changed the sensor child IDs and flashed the new sketch. Now everything seems to be working.

      If someone needs something like this:

      #include <SPI.h>
      #include <MySensor.h>  
      
      #define DIGITAL_INPUT_SOIL_SENSOR 3   // Digital input did you attach your soil sensor.
      #define ANALOG_INPUT_SOIL_SENSOR A0
      #define CHILD_ID_1 3   // Id of the sensor child
      #define CHILD_ID_2 2
      #define sleepTime 30000
      
      MySensor gw;
      MyMessage msgDigital(CHILD_ID_1, V_TRIPPED); // digital = on/off
      MyMessage msgAnalog(CHILD_ID_2, V_LEVEL); // analog = int value
      
      void setup()  
      { 
        gw.begin();
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Soil Moisture Sensor", "1.0");
        
        // sets the soil sensor pins as input
        pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT); 
        pinMode(ANALOG_INPUT_SOIL_SENSOR, INPUT);  
        
        // Register all sensors to gw (they will be created as child devices)  
        gw.present(CHILD_ID_1, S_MOISTURE);
        gw.present(CHILD_ID_2, S_MOISTURE);
      }
       
      void loop()     
      {     
        // Read soil values
        int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water 
        int soilAnalog = analogRead(ANALOG_INPUT_SOIL_SENSOR);
        
        // debugging
        Serial.println(soilValue);
        Serial.println(soilAnalog);
        
        // send values
        gw.send(msgAnalog.set(soilAnalog));
        gw.send(msgDigital.set(soilValue==0?1:0));  // Send the inverse to gw as tripped should be when no water in soil  
      
        // sleep until the next cycle starts
        gw.sleep(sleepTime);
      }
      
      1 Reply Last reply
      0
      • L Offline
        L Offline
        LastSamurai
        Hardware Contributor
        wrote on last edited by LastSamurai
        #4

        Update: Somehow the updates from the digital sensor stopped again after about 5 updates this time (while the analog one still updates perfectly...).
        Does anyone have an idea why? So strange...
        Is it possible that the sending isn't 100% before the node goes to sleep?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LastSamurai
          Hardware Contributor
          wrote on last edited by
          #5

          It's getting even stranger. Today it worked again but only for about 5 readings...

          SparkmanS AWIA 2 Replies Last reply
          0
          • L LastSamurai

            It's getting even stranger. Today it worked again but only for about 5 readings...

            SparkmanS Offline
            SparkmanS Offline
            Sparkman
            Hero Member
            wrote on last edited by
            #6

            @LastSamurai I would add a small delay between sending using the gw.wait method and see if that improves the reliability of the transmissions.

            Cheers
            Al

            1 Reply Last reply
            0
            • L LastSamurai

              It's getting even stranger. Today it worked again but only for about 5 readings...

              AWIA Offline
              AWIA Offline
              AWI
              Hero Member
              wrote on last edited by
              #7

              @LastSamurai Did you check the debug information on the sensor node and checked for "fail" messages? It could be a power issue. As you are sending two values directly after each other (first analog, second digital) the last one could be suffering. Have you followed the instructions for connecting the radio ?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                LastSamurai
                Hardware Contributor
                wrote on last edited by LastSamurai
                #8

                I have connected the radio like in the instructions (otherwise how could any message get through anyways?).
                I also added pauses. It still doesn't work though. Only the analog values get updated.

                New Code:

                #include <SPI.h>
                #include <MySensor.h>  
                
                #define DIGITAL_INPUT_SOIL_SENSOR 3   // Digital input did you attach your soil sensor.
                #define ANALOG_INPUT_SOIL_SENSOR A0
                #define CHILD_ID_1 3   // Id of the sensor child
                #define CHILD_ID_2 2
                #define sleepTime 30000
                
                MySensor gw;
                MyMessage msgDigital(CHILD_ID_1, V_TRIPPED); // digital = on/off
                MyMessage msgAnalog(CHILD_ID_2, V_LEVEL); // analog = int value
                
                void setup()  
                { 
                  gw.begin();
                
                  // Send the sketch version information to the gateway and Controller
                  gw.sendSketchInfo("Soil Moisture Sensor", "1.0");
                  
                  // sets the soil sensor pins as input
                  pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT); 
                  pinMode(ANALOG_INPUT_SOIL_SENSOR, INPUT);  
                  
                  // Register all sensors to gw (they will be created as child devices)  
                  gw.present(CHILD_ID_1, S_MOISTURE);
                  gw.present(CHILD_ID_2, S_MOISTURE);
                }
                 
                void loop()     
                {     
                  // Read soil values
                  int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water 
                  int soilAnalog = analogRead(ANALOG_INPUT_SOIL_SENSOR);
                  
                  // debugging
                  Serial.println(soilValue);
                  Serial.println(soilAnalog);
                  
                  // send values
                  gw.send(msgAnalog.set(soilAnalog));
                  gw.sleep(200);
                  gw.send(msgDigital.set(soilValue));  // Send the inverse to gw as tripped should be when no water in soil - no inverse atm => high == needs water
                  gw.sleep(200);
                
                  // sleep until the next cycle starts
                  gw.sleep(sleepTime);
                }
                
                

                The node with the sensor has output like this:

                sensor started, id=2, parent=0, distance=1
                send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=20,sg=0,st=ok:Soil Moisture Sensor
                send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
                send: 2-2-0-0 s=3,c=0,t=35,pt=0,l=0,sg=0,st=ok:
                send: 2-2-0-0 s=2,c=0,t=35,pt=0,l=0,sg=0,st=ok:
                1
                1023
                send: 2-2-0-0 s=2,c=1,t=37,pt=2,l=2,sg=0,st=ok:1023
                send: 2-2-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
                1
                1023
                send: 2-2-0-0 s=2,c=1,t=37,pt=2,l=2,sg=0,st=ok:1023
                send: 2-2-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
                

                To me everything looks fine. Is it possible that this is a bug in Domoticz? I am using the newest beta version already.

                PS Now it did just send one value again, after restarting the node... but only one, now there are only analog values again.

                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #9

                  Any difference if you try gw.wait(50) instead of gw.sleep(200)?

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    LastSamurai
                    Hardware Contributor
                    wrote on last edited by
                    #10

                    Thanks hek, thats what I really wanted to do... typo... I will try that one too later.
                    I might have found the "error" though (need to confirm). The logs are showing lots of changes yesterday and today, but always only if the value changed (off => on or on => off). So I think it might be that domoticz ignores updates (even in the log) that don't change the value.
                    Can anyone confirm this behaviour? Else I need to check in their forum.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      malarcy
                      wrote on last edited by
                      #11

                      I can confirm that the mysensors "adapter" for domoticz does not update anything for a sensor if the value has not changed - including last seen time. There has been a bit of a discussion about it and I have a bug and feature request in for it to be a configurable choice for the user - but as it stands - if no change in value then update is ignored.

                      I modified the mysensors adapter code to always update - even if values haven't changed - but that isn't really a long term solution since it gets overwritten on every update.

                      https://www.domoticz.com/forum/viewtopic.php?f=42&t=9272

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


                      12

                      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