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. Not seeing child id 0 Humidity from DHT

Not seeing child id 0 Humidity from DHT

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.1k 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.
  • derksuhD Offline
    derksuhD Offline
    derksuh
    wrote on last edited by
    #1

    Hello all,

    i made myself a sketch and uploaded it to a arduino nano.
    I'm using pimatic and can find the temperature and the relay but i don't see the humidity.

    This is the sketch.

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>

    #define NODE_ID 5 // ID of node

    //child ids
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_VLIGHT0 2

    //pin definitions
    #define RELAY_PIN0 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3

    //relay state
    #define RELAY_ON 0
    #define RELAY_OFF 1
    #define NUMBER_OF_RELAYS 1

    //sleep timer settings
    unsigned long SLEEP_TIME = 1000; // Sleep time var, first read is 0
    unsigned long SLEEP_TIME_POST = 60000; // Sleep time var changes to this value after
    unsigned long LAST_SLEEP_TIME = millis(); // Sleep time between reads (in milliseconds)

    bool state;

    //mysensors setup
    MySensor gw;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLSW0(CHILD_ID_VLIGHT0, V_LIGHT);

    //dht setup
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;

    void setup()
    {
    // Make sure relays are off when starting up
    digitalWrite(RELAY_PIN0, RELAY_OFF);
    // Then set relay pins in output mode
    pinMode(RELAY_PIN0, OUTPUT);
    dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // mysensor startup and Send the Sketch Version Information to the Gateway
    gw.begin(incomingMessage, NODE_ID, true);
    gw.sendSketchInfo("DHT&relay&button", "1.1");
    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_HUM, S_HUM);
    gw.present(CHILD_ID_TEMP, S_TEMP);
    gw.present(CHILD_ID_VLIGHT0, S_LIGHT);
    delay(1000);
    metric = gw.getConfig().isMetric;
    // Set relay to last known state (using eeprom storage)
    state = gw.loadState(CHILD_ID_VLIGHT0);
    digitalWrite(RELAY_PIN0, state?RELAY_ON:RELAY_OFF);
    }

    void loop()
    {

     if (millis() - LAST_SLEEP_TIME > SLEEP_TIME) {   
    

    dhtupdate();
    LAST_SLEEP_TIME=millis();
    if (SLEEP_TIME < SLEEP_TIME_POST) {
    SLEEP_TIME=SLEEP_TIME_POST;
    }

    }

    gw.process();

    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.isAck()) {
    Serial.println("This is an ack from gateway");
    }

    if (message.type == V_LIGHT) {
    if (message.sensor == CHILD_ID_VLIGHT0){
    // Change relay state
    digitalWrite(RELAY_PIN0, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for relay1 sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }
    }

    void dhtupdate() {
    float temperature = dht.getTemperature();
    if (isnan(temperature)) {
    Serial.println("Failed reading temperature from DHT");
    } else if (temperature != lastTemp) {
    lastTemp = temperature;
    if (!metric) {
    temperature = dht.toFahrenheit(temperature);
    }
    gw.send(msgTemp.set(temperature, 1));
    Serial.print("T: ");
    Serial.println(temperature);
    }

    float humidity = dht.getHumidity();
    if (isnan(humidity)) {
    Serial.println("Failed reading humidity from DHT");
    } else if (humidity != lastHum) {
    lastHum = humidity;
    gw.send(msgHum.set(humidity, 1));
    Serial.print("H: ");
    Serial.println(humidity);
    }

    }

    1 Reply Last reply
    0
    • derksuhD Offline
      derksuhD Offline
      derksuh
      wrote on last edited by
      #2

      Fixed it! i manually added the sensor in pimatic and now it works

      mfalkviddM 1 Reply Last reply
      1
      • derksuhD derksuh

        Fixed it! i manually added the sensor in pimatic and now it works

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

        @derksuh great work. Thanks for reporting back.

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


        21

        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