Node with DS18B20 and DHT22



  • Hi!

    First sorry for my bad english ๐Ÿ™‚

    I'm trying to make a node with 2 DS18B20 and 2 DHT22 but in domoticz the DS18B20 is show like "Temp + Humidity" sensors (with the humidity value of the 1st DHT22).

    I've read on github that it's possible to set "groupID" to resolve this problem, but i don't understand how to set this.

    I've try this, but not working:

      present(0, S_TEMP, "SENSOR1");
      present(1, S_TEMP, "SENSOR2");
      present(CHILD_ID_TEMP1, S_TEMP, "SENSOR3");
      present(CHILD_ID_HUM1, S_HUM, "SENSOR3");
      present(CHILD_ID_TEMP2, S_TEMP, "SENSOR4");
      present(CHILD_ID_HUM2, S_HUM, "SENSOR4");
    

    Does someone can explain me please ?

    Thank you.


  • Mod

    Welcome to the MySensors community @dokho !

    I think the discussion in https://forum.mysensors.org/topic/5132/ds18b20-ans-sht31-d-show-up-as-combined-sensors-on-domoticz/8 will give you what you need. See if that helps and report back the result. We'll try to help if you get stuck.



  • 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 ...



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



  • 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.



  • 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...



  • Up ... please :s


  • Admin

    Isn't the left column the sensor id? 0,1,6,7,8,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)


  • Admin

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



  • 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.



  • 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



  • 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...


Log in to reply
 

Suggested Topics

  • 5
  • 3
  • 2
  • 2
  • 1
  • 4

9
Online

11.4k
Users

11.1k
Topics

112.7k
Posts