<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[DHT22 wrong sensor type in Home Assistant]]></title><description><![CDATA[<p dir="auto">Hi, I’m pretty sure the error is somewhere in the program, I just don’t know where. I want to use an Arduino Uno to read two limit switches and a DHT22 sensor. For this, I combined two programs with the help of ChatGPT, made some small adjustments, and tested it. Everything seemed to work fine in the Serial Monitor. However, in Home Assistant, the limit switches are recognized correctly, but the DHT22 is also detected as a door contact. Where is my mistake here?</p>
<pre><code>
// Enable debug prints
#define MY_DEBUG

// Enable only USB, disable radio
//#define MY_RADIO_RF24
//#define MY_RADIO_RFM69
//#define MY_RS485

//USB Modus
#define MY_GATEWAY_SERIAL

#include &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;
#include &lt;DHT.h&gt;
#include &lt;Adafruit_Sensor.h&gt;

// ---------- DHT CONFIG ----------
#define DHTPIN 4       // &lt;-- DHT Datenpin
#define DHTTYPE DHT22  // DHT-Typ (z.B. DHT11, DHT22)
DHT dht(DHTPIN, DHTTYPE);

#define SENSOR_TEMP_OFFSET 0
static const uint64_t UPDATE_INTERVAL = 30000;  // 30 Sekunden für DHT-Update
static const uint8_t FORCE_UPDATE_N_READS = 10;

#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1

float lastTemp;
float lastHum;
uint8_t nNoUpdatesTemp;
uint8_t nNoUpdatesHum;
bool metric = true;

MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

// ---------- BUTTON CONFIG ----------
#define PRIMARY_CHILD_ID 2
#define SECONDARY_CHILD_ID 3

#define PRIMARY_BUTTON_PIN 2     // bleibt auf D2
#define SECONDARY_BUTTON_PIN 3   // bleibt auf D3

#if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
#error PRIMARY_BUTTON_PIN and SECONDARY_BUTTON_PIN cannot be the same
#endif
#if (PRIMARY_CHILD_ID == CHILD_ID_TEMP || PRIMARY_CHILD_ID == CHILD_ID_HUM || \
     SECONDARY_CHILD_ID == CHILD_ID_TEMP || SECONDARY_CHILD_ID == CHILD_ID_HUM)
#error Child IDs must be unique
#endif

MyMessage msgButton1(PRIMARY_CHILD_ID, V_TRIPPED);
MyMessage msgButton2(SECONDARY_CHILD_ID, V_TRIPPED);

static uint8_t lastButton1 = 2;
static uint8_t lastButton2 = 2;

void presentation() {
  sendSketchInfo("Combined Sensor Node", "1.0");

  // DHT
  present(CHILD_ID_HUM, S_HUM);
  present(CHILD_ID_TEMP, S_TEMP);

  // Buttons
  present(PRIMARY_CHILD_ID, S_DOOR);
  present(SECONDARY_CHILD_ID, S_DOOR);

  metric = getControllerConfig().isMetric;
}

void setup() {
  dht.begin();
  delay(2000); // Sensor bootzeit

  pinMode(PRIMARY_BUTTON_PIN, INPUT_PULLUP);
  pinMode(SECONDARY_BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // ----- BUTTON HANDLING ----- (Ständig überprüfen)
  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;
  }

  // ----- DHT SENSOR ----- (Nur alle UPDATE_INTERVAL Millisekunden aktualisieren)
  static uint64_t lastDHTUpdate = 0;
  uint64_t currentMillis = millis();

  if (currentMillis - lastDHTUpdate &gt;= UPDATE_INTERVAL) {
    lastDHTUpdate = currentMillis;

    float temperature = dht.readTemperature(metric); // true = Celsius
    float humidity = dht.readHumidity();

    if (!isnan(temperature) &amp;&amp; (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS)) {
      lastTemp = temperature + SENSOR_TEMP_OFFSET;
      send(msgTemp.set(lastTemp, 1));
      nNoUpdatesTemp = 0;
      Serial.print("T: ");
      Serial.println(lastTemp);
    } else {
      nNoUpdatesTemp++;
    }

    if (!isnan(humidity) &amp;&amp; (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS)) {
      lastHum = humidity;
      send(msgHum.set(lastHum, 1));
      nNoUpdatesHum = 0;
      Serial.print("H: ");
      Serial.println(lastHum);
    } else {
      nNoUpdatesHum++;
    }
  }

  // Sleep für Buttons und DHT
  delay(100);  // Schnelle Verzögerung, damit der Button-Check nicht zu oft passiert
}

</code></pre>
<p dir="auto">I should mention that although I tested the DHT22 earlier, I didn’t connect it when testing with Home Assistant—just in case that’s relevant to the issue.</p>
]]></description><link>https://forum.mysensors.org/topic/12278/dht22-wrong-sensor-type-in-home-assistant</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 13:52:15 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/12278.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Apr 2025 05:25:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Tue, 15 Apr 2025 17:40:50 GMT]]></title><description><![CDATA[<p dir="auto">I'm glad that worked!</p>
]]></description><link>https://forum.mysensors.org/post/114291</link><guid isPermaLink="true">https://forum.mysensors.org/post/114291</guid><dc:creator><![CDATA[OldSurferDude]]></dc:creator><pubDate>Tue, 15 Apr 2025 17:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Sun, 13 Apr 2025 20:16:56 GMT]]></title><description><![CDATA[<p dir="auto">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!</p>
<pre><code>// 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 &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;
#include &lt;DHT.h&gt;
#include &lt;Adafruit_Sensor.h&gt;

// ---------- 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 &amp; 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) &amp;&amp; (temperature != lastTemp || nNoUpdatesTemp &gt;= 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) &amp;&amp; (humidity != lastHum || nNoUpdatesHum &gt;= 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);
}

</code></pre>
]]></description><link>https://forum.mysensors.org/post/114290</link><guid isPermaLink="true">https://forum.mysensors.org/post/114290</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Apr 2025 20:16:56 GMT</pubDate></item><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Sun, 13 Apr 2025 14:54:07 GMT]]></title><description><![CDATA[<p dir="auto">Good call <a class="plugin-mentions-user plugin-mentions-a" href="/user/skywatch" aria-label="Profile: skywatch">@<bdi>skywatch</bdi></a> !</p>
<p dir="auto">wait() is a MySensors function that looks for MySensors operations that run asynchronously to loop().  Search for "What is the difference between delay() and wait()"</p>
<p dir="auto">I have experienced the symptoms you describe.  I put a wait() after functions that send MySensors data: send() and present() (but for some reason not sendSketchInfo()?).  If I'm using an MQTT gateway Its 500 and 4000 milliseconds, respectively; Serial, 100 and 500.</p>
<p dir="auto">I think this will work for you! :)  Letting us know your results helps someone else that is experiencing what you are.</p>
<p dir="auto">OSD</p>
]]></description><link>https://forum.mysensors.org/post/114289</link><guid isPermaLink="true">https://forum.mysensors.org/post/114289</guid><dc:creator><![CDATA[OldSurferDude]]></dc:creator><pubDate>Sun, 13 Apr 2025 14:54:07 GMT</pubDate></item><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Sat, 12 Apr 2025 11:12:48 GMT]]></title><description><![CDATA[<p dir="auto">@Commodoreuno I can't see anything obvious at a quick look through, but I would suggest that you change all the delay() functions to wait() functions and comment out the serial print instructions and see how it goes then.</p>
]]></description><link>https://forum.mysensors.org/post/114288</link><guid isPermaLink="true">https://forum.mysensors.org/post/114288</guid><dc:creator><![CDATA[skywatch]]></dc:creator><pubDate>Sat, 12 Apr 2025 11:12:48 GMT</pubDate></item><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Fri, 11 Apr 2025 07:17:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oldsurferdude" aria-label="Profile: OldSurferDude">@<bdi>OldSurferDude</bdi></a> First of all, thanks for the reply. I tried it that way, but it looks like the third “door” sensor is completely gone. The issue is probably in the code after all.</p>
]]></description><link>https://forum.mysensors.org/post/114287</link><guid isPermaLink="true">https://forum.mysensors.org/post/114287</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Fri, 11 Apr 2025 07:17:20 GMT</pubDate></item><item><title><![CDATA[Reply to DHT22 wrong sensor type in Home Assistant on Fri, 11 Apr 2025 02:26:50 GMT]]></title><description><![CDATA[<p dir="auto">I'm going to make an assumption:  You have connected to Home Assistant many times during your development.</p>
<p dir="auto">Home Assistant is not very flexible with MySensors.  If you change Child_IDs it sometimes ignores the change.</p>
<p dir="auto">Try deleting your MySensors device.  This is not a friendly operation.  Assuming that your Uno is acting as a serial gateway and as your sensor monitory device,</p>
<ul>
<li>disconnect the Uno from your computer.  th</li>
<li>In HA: settings--&gt;Devices and Services--&gt;n DEVICES in MySensors integration--&gt;click on device your going to delete--&gt;3 vertical dots next to Remove Device from MySensors--&gt;&gt;Remove<br />
Then restart HA</li>
<li>Developer Tools--&gt;restart--&gt;restart<br />
After HA is restarted, plug your Uno back in</li>
</ul>
<p dir="auto">If your MySensors gateway is MQTT you have to stop the MQTT gateway and delete all vestiges of your device in the MQTT broker (I use MQTT Explore to do this which has to be running befor you do anything to see the topics that will be erased.)</p>
<p dir="auto">Let us know if that fixed it.</p>
<p dir="auto">OSD</p>
]]></description><link>https://forum.mysensors.org/post/114284</link><guid isPermaLink="true">https://forum.mysensors.org/post/114284</guid><dc:creator><![CDATA[OldSurferDude]]></dc:creator><pubDate>Fri, 11 Apr 2025 02:26:50 GMT</pubDate></item></channel></rss>