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. Node with DS18B20 and DHT22

Node with DS18B20 and DHT22

Scheduled Pinned Locked Moved Domoticz
13 Posts 5 Posters 5.5k Views 4 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.
  • dokhoD Offline
    dokhoD Offline
    dokho
    wrote on last edited by
    #3

    Hi !

    Thank you for the greeting @mfalkvidd :)

    I've already read the discussion you've quote but i'm not sure to understand: some say "modify domoticz code" other say "present sensor after each other" ...

    Witch version of mysensors is needed to do what i try ? 2.0 or beta ?
    I'm using, perhaps it's not the good version ...

    1 Reply Last reply
    0
    • dbemowskD Offline
      dbemowskD Offline
      dbemowsk
      wrote on last edited by
      #4

      Just out of curiosity, why are you using DS18B20s with a DHT22? Are these all mounted on the same sensor board?

      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
      • dokhoD Offline
        dokhoD Offline
        dokho
        wrote on last edited by
        #5

        Hi!

        It's to make a node for the 2nd floor of my house: 6 DS18B20 for bedrooms, office (?), stairs and 2 DHT22 for the 2 bathrooms.

        DHT22 are more expensive than DS18B20 and i need to know humidity only for the bathrooms.

        1 Reply Last reply
        1
        • dokhoD Offline
          dokhoD Offline
          dokho
          wrote on last edited by dokho
          #6

          Hi!

          I've try with developpement librairies and it's the same.

          For information this is the sketch i'm using:

          // Enable debug prints
          #define MY_DEBUG
          
          // Enable and select radio type attached 
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          //#define MY_RS485
           
          #include <SPI.h>
          #include <MySensors.h>  
          #include <DHT.h>
          #include <DallasTemperature.h>
          #include <OneWire.h>
          
          #define MAX_ATTACHED_DS18B20 6
          
          #define ONE_WIRE_BUS 4
          #define DHT1_DATA_PIN 2
          #define DHT2_DATA_PIN 3
          
          #define CHILD_ID_DHT1HUM 6
          #define CHILD_ID_DHT1TEMP 7
          #define CHILD_ID_DHT2HUM 9
          #define CHILD_ID_DHT2TEMP 8
          
          #define SENSOR_TEMP_OFFSET 0
          
          // Sleep time between sensor updates (in milliseconds)
          // Must be >1000ms for DHT22 and >2000ms for DHT11
          static const uint64_t UPDATE_INTERVAL = 3000;
          
          unsigned long SLEEP_TIME = 30000;
          bool metric = true;
          bool receivedConfig = false;
          int numSensors=0;
          
          OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
          DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
          
          MyMessage msgDallas(0,V_TEMP);
          MyMessage msgDHT1Temp(CHILD_ID_DHT1TEMP,V_TEMP);
          MyMessage msgDHT1Hum(CHILD_ID_DHT1HUM,V_HUM);
          MyMessage msgDHT2Hum(CHILD_ID_DHT2HUM,V_HUM);
          MyMessage msgDHT2Temp(CHILD_ID_DHT2TEMP,V_TEMP);
          
          DHT dht;
          
          void before()
          {
            // Startup up the OneWire library
            sensors.begin();
          }
          void setup()
          {
          // requestTemperatures() will not block current thread
            sensors.setWaitForConversion(false);  
          }
          void presentation()  
          { 
            // Send the sketch version information to the gateway
            sendSketchInfo("DualDHTandDallas", "1.1");
          
           // Fetch the number of attached temperature sensors  
            numSensors = sensors.getDeviceCount();
          
            // Present all sensors to controller
            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
               present(i, S_TEMP);
            }
             
            present(CHILD_ID_DHT1TEMP,S_TEMP);
            present(CHILD_ID_DHT1HUM,S_HUM);
            present(CHILD_ID_DHT2HUM,S_HUM);
            present(CHILD_ID_DHT2TEMP,S_TEMP);
            
            
            metric = getConfig().isMetric;
          }
          
          void loop()      
          { 
          
          // Fetch temperatures from Dallas sensors
            sensors.requestTemperatures();
          
            // query conversion time and sleep until conversion completed
            int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
            sleep(conversionTime);
          
          // Read temperatures and send them to controller 
            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
           
              // Fetch and round temperature to one decimal
              float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
           
            // Send in the new temperature
            send(msgDallas.setSensor(i).set(temperature,1));
                #ifdef MY_DEBUG
                Serial.print("Dallas");
                Serial.print(i);
                Serial.print(" :");
                Serial.println(temperature);
                #endif
          
          //  sleep(SLEEP_TIME);
            }
             
            dht.setup(DHT1_DATA_PIN); // set data pin of DHT1 sensor
            if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
              Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
            }
            // Sleep for the time of the minimum sampling period to give the sensor time to power up
            // (otherwise, timeout errors might occure for the first reading)
            sleep(dht.getMinimumSamplingPeriod());
            
            // Force reading sensor, so it works also after sleep()
            dht.readSensor(true);
            
            // Get temperature from DHT library
            float dht1temperature = dht.getTemperature();
            if (isnan(dht1temperature)) {
              Serial.println("Failed reading temperature from DHT!");
            } else 
              if (!metric) {
                dht1temperature = dht.toFahrenheit(dht1temperature);
              }
              
              dht1temperature += SENSOR_TEMP_OFFSET;
              send(msgDHT1Temp.set(dht1temperature, 1));
          
              #ifdef MY_DEBUG
              Serial.print("DHT1TEMP: ");
              Serial.println(dht1temperature);
              #endif
            sleep(UPDATE_INTERVAL);
          
            // Get humidity from DHT library
            float dht1humidity = dht.getHumidity();
            if (isnan(dht1humidity)) {
              Serial.println("Failed reading humidity from DHT");
            } 
            else {
             send(msgDHT1Hum.set(dht1humidity, 1));
              
              #ifdef MY_DEBUG
              Serial.print("DHT1HUM: ");
              Serial.println(dht1humidity);
              #endif
            } 
          
            // Sleep for a while to save energy
            sleep(UPDATE_INTERVAL); 
          
          
            dht.setup(DHT2_DATA_PIN); // set data pin of DHT2 sensor
            if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
              Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
            }
            // Sleep for the time of the minimum sampling period to give the sensor time to power up
            // (otherwise, timeout errors might occure for the first reading)
            sleep(dht.getMinimumSamplingPeriod());
            
            // Force reading sensor, so it works also after sleep()
            dht.readSensor(true);
            
            // Get temperature from DHT library
            float dht2temperature = dht.getTemperature();
            if (isnan(dht2temperature)) {
              Serial.println("Failed reading temperature from DHT!");
            } else 
              if (!metric) {
                dht2temperature = dht.toFahrenheit(dht2temperature);
              }
              dht2temperature += SENSOR_TEMP_OFFSET;
              send(msgDHT2Temp.set(dht2temperature, 1));
          
              #ifdef MY_DEBUG
              Serial.print("DHT2TEMP: ");
              Serial.println(dht2temperature);
              #endif
            
          sleep(UPDATE_INTERVAL);
          
            // Get humidity from DHT library
            float dht2humidity = dht.getHumidity();
            if (isnan(dht2humidity)) {
              Serial.println("Failed reading humidity from DHT");
            } else {
             send(msgDHT2Hum.set(dht2humidity, 1));
              
              #ifdef MY_DEBUG
              Serial.print("DHT2HUM: ");
              Serial.println(dht2humidity);
              #endif
            }
          
            sleep(UPDATE_INTERVAL); 
          
          }
          

          And in domoticz all childs have the same ID (#1)
          0_1478106899752_Screenshot - 02112016 - 18:14:09.png

          Noboby have an idea of the problem ?

          [EDIT]
          And i just discover an other "problem": the 2nd DHT22 humidity value is updated with the value of the 1st one...

          1 Reply Last reply
          0
          • dokhoD Offline
            dokhoD Offline
            dokho
            wrote on last edited by
            #7

            Up ... please :s

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

              Isn't the left column the sensor id? 0,1,6,7,8,9 ?

              dokhoD 1 Reply Last reply
              0
              • hekH hek

                Isn't the left column the sensor id? 0,1,6,7,8,9 ?

                dokhoD Offline
                dokhoD Offline
                dokho
                wrote on last edited by
                #9

                @hek
                No it's the #1 in the "Values" column

                On an other node with 4 DS18B20:
                0_1479066924561_Screenshot - 13112016 - 20:53:28.png

                The DS18B20 have different ID (#1, #2, #3 and #4)

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

                  I don't run Domoticz myself. But the numbers in the left column matches child ids in your sketch exactly.

                  1 Reply Last reply
                  0
                  • dbemowskD Offline
                    dbemowskD Offline
                    dbemowsk
                    wrote on last edited by
                    #11

                    The numbers in the left column ARE the child IDs. The numbers next to V_TEMP in the values column are not the child IDs. Look at your Domoticz indexes and IDs for these under Setup > Devices.

                    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
                    • dokhoD Offline
                      dokhoD Offline
                      dokho
                      wrote on last edited by dokho
                      #12

                      Ok so the number next to V_TEMP in the values column are groupID ?

                      The problem in my DS18B20+DHT22 node is that they have all the same groupID, so domoticz group TEMP and HUM in the same device and the HUM of the 1st DHT22 is updated with the HUM of the 2nd one ...

                      alt text

                      1 Reply Last reply
                      0
                      • Jon EngJ Offline
                        Jon EngJ Offline
                        Jon Eng
                        wrote on last edited by
                        #13

                        So I researched this a bit and here is the answer:

                        The grouping of devices origins from this commit:
                        https://github.com/domoticz/domoticz/pull/847

                        and the logic is:
                        https://github.com/domoticz/domoticz/issues/276

                        Unfortunately it doesn´t work very well with other sensor combinations that Temp/hum/pressure - like mine with voltage, impedance and so on..

                        I found a workaround by naming all sensors v_hum - then they are placed in different groups and are possible to work with in domoticz...

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


                        26

                        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