Mysensor DHT22 to HA

Dear all,

I want to send the DHT to HA via USB connection between Arduino and RPI. I looked and searched on this forum and I figured out that I need to use mysensor. So this is what I have as arduino script /

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

#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

MySensor gw;
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true; 
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);


void setup()  
{ 
  gw.begin();
  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 

  // Send the Sketch Version Information to the Gateway
  gw.sendSketchInfo("Humidity", "1.0");

  // 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);
  
  metric = gw.getConfig().isMetric;
}

void loop()      
{  
  delay(dht.getMinimumSamplingPeriod());

  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);
  }

  gw.sleep(SLEEP_TIME); //sleep a bit
}

and this is my config in yaml:

mysensors:
  gateways:
    - device: /dev/ttyACM0
      persistence_file: /var/opt/homeassistant/sensor/mysensors2.json
      baud_rate: 115200
  debug: true
  optimistic: false
  persistence: true
  retain: true
  version: 2.0

But or I do something wrong most likely or I forget something because I don’t see any values on the serial monitor of the arduino and on HA. I installed the libraries and copied the DHT22 script from the mysensor website so far no own input :).

Is there anyone who could help me with this issue and I don’t want to use ESP8266 because I prefer the more difficult way and also more inputs are connected to the arduino and I have 4 USB on the PI.

Please post serial log and home assistant debug level log.

Also, your sketch is written for mysensors version 1.5 or less, while you configure home assistant for mysensors version 2.0. That’s not a good idea. I suggest using the latest mysensors version 2.x something.

If you want to have the sensor locally on the gateway, you need mysensors 2.x too.