Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Commodoreuno
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by Commodoreuno

    • RE: DHT22 wrong sensor type in Home Assistant

      Okay, I have now taken all the suggestions into account, including deleting the application in Home Assistant. I also worked with the official script for deleting the Arduino, which I hadn't done before, and made changes in the program, especially with the IDs and various names, in order to essentially create a completely new program. Now it works with this script. Thanks so far for the help!

      // Enable debug prints
      #define MY_DEBUG
      
      // Set static node ID
      #define MY_NODE_ID 45
      
      // Enable only USB, disable radio
      #define MY_GATEWAY_SERIAL
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <DHT.h>
      #include <Adafruit_Sensor.h>
      
      // ---------- DHT CONFIG ----------
      #define DHTPIN 4         // Datenpin des DHT22
      #define DHTTYPE DHT22    // Sensor-Typ DHT22
      #define USE_CELSIUS true // Immer Celsius verwenden
      #define SENSOR_TEMP_OFFSET 0
      
      #define UPDATE_INTERVAL 5000           // 5 Sekunden
      #define FORCE_UPDATE_N_READS 10        // nach 10 gleichen Werten senden
      
      #define CHILD_ID_HUM 20
      #define CHILD_ID_TEMP 21
      
      DHT dht(DHTPIN, DHTTYPE);
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp = 0;
      uint8_t nNoUpdatesHum = 0;
      
      // ---------- BUTTON CONFIG ----------
      #define PRIMARY_BUTTON_PIN 2
      #define SECONDARY_BUTTON_PIN 3
      
      #define PRIMARY_CHILD_ID 22
      #define SECONDARY_CHILD_ID 23
      
      MyMessage msgButton1(PRIMARY_CHILD_ID, V_TRIPPED);
      MyMessage msgButton2(SECONDARY_CHILD_ID, V_TRIPPED);
      
      static uint8_t lastButton1 = 2;
      static uint8_t lastButton2 = 2;
      
      // ---------- SETUP & PRESENTATION ----------
      void presentation() {
        sendSketchInfo("Combined Sensor Node", "1.0");
      
        // Sensoren anmelden
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        present(PRIMARY_CHILD_ID, S_DOOR);
        present(SECONDARY_CHILD_ID, S_DOOR);
      }
      
      void setup() {
        dht.begin();  // DHT starten
      
        pinMode(PRIMARY_BUTTON_PIN, INPUT_PULLUP);
        pinMode(SECONDARY_BUTTON_PIN, INPUT_PULLUP);
      }
      
      // ---------- LOOP ----------
      void loop() {
        // ----- DHT AUSLESEN -----
        float temperature = dht.readTemperature(); // immer Celsius
        float humidity = dht.readHumidity();
      
        if (!isnan(temperature) && (temperature != lastTemp || nNoUpdatesTemp >= FORCE_UPDATE_N_READS)) {
          lastTemp = temperature + SENSOR_TEMP_OFFSET;
          send(msgTemp.set(lastTemp, 1));
          nNoUpdatesTemp = 0;
          Serial.print("Temp: ");
          Serial.println(lastTemp);
        } else {
          nNoUpdatesTemp++;
        }
      
        if (!isnan(humidity) && (humidity != lastHum || nNoUpdatesHum >= FORCE_UPDATE_N_READS)) {
          lastHum = humidity;
          send(msgHum.set(lastHum, 1));
          nNoUpdatesHum = 0;
          Serial.print("Hum: ");
          Serial.println(lastHum);
        } else {
          nNoUpdatesHum++;
        }
      
        // ----- BUTTONS -----
        uint8_t val1 = digitalRead(PRIMARY_BUTTON_PIN);
        if (val1 != lastButton1) {
          send(msgButton1.set(val1 == HIGH));
          lastButton1 = val1;
        }
      
        uint8_t val2 = digitalRead(SECONDARY_BUTTON_PIN);
        if (val2 != lastButton2) {
          send(msgButton2.set(val2 == HIGH));
          lastButton2 = val2;
        }
      
        // ----- SLEEP -----
        //sleep(PRIMARY_BUTTON_PIN - 2, CHANGE, SECONDARY_BUTTON_PIN - 2, CHANGE, UPDATE_INTERVAL);
        delay(50);
      }
      
      
      posted in Troubleshooting
      Commodoreuno
      Commodoreuno