arduino dht11 to domoticz

Moderator: leecollings

Post Reply
peterjenp
Posts: 1
Joined: Thursday 29 September 2022 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

arduino dht11 to domoticz

Post by peterjenp »

Hello all.

I have the following script running on my arduino for communication between my arduinoe and domoticz on my raspbery pi 3b.
I can also switch on and off closed relays via domoticz.
However, I still can't figure out how to send the temperature and air humidity from the dht11 sensor to domoticz.

the question is now also can someone tell me which lines I should add to send the data from dht11 to the arduino to domoticz?

thanks: peter

Code: Select all

// Enable debug prints to serial monitor
#define MY_DEBUG 

// Enable and select radio type attached
//#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

// Set LOW transmit power level as default, if you have an amplified NRF-module and
// power your radio separately with a good regulator you can turn up PA level. 
//#define MY_RF24_PA_LEVEL RF24_PA_LOW

// Enable serial gateway
#define MY_GATEWAY_SERIAL

// Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
#if F_CPU == 12000000L
#define MY_BAUD_RATE 115200
#endif

// Flash leds on rx/tx/err
// #define MY_LEDS_BLINKING_FEATURE
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300

// Inverses the behavior of leds
// #define MY_WITH_LEDS_BLINKING_INVERSE

// Enable inclusion mode
//#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
//#define MY_INCLUSION_BUTTON_FEATURE

// Inverses behavior of inclusion button (if using external pullup)
//#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP

// Set inclusion mode duration (in seconds)
//#define MY_INCLUSION_MODE_DURATION 60 
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN  3 

// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
//#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED

#include <SPI.h>
#include <MySensors.h>  
#include <Bounce2.h>
#include "DHT.h"  //dht11

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE

#define RELAY_1  22  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_2  23
#define RELAY_3  24
#define RELAY_4  25
#define RELAY_5  26
#define RELAY_6  27
#define RELAY_7  28
#define RELAY_8  29
#define RELAY_9  30
#define RELAY_10  31
#define RELAY_11  32
#define RELAY_12  33
#define NUMBER_OF_RELAYS  12 // Total number of attached relays                             dodać na próbę wejścia
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
#define DHTPIN 46 //dht11
#define DHTTYPE DHT11 //dht11

#define CHILD_ID_1 20
#define CHILD_ID_2 21
#define INPUT_1  20
#define INPUT_2  21

Bounce debouncer1 = Bounce(); 
Bounce debouncer2 = Bounce(); 

int oldValue1 = -1;
int oldValue2 = -1;
DHT dht(DHTPIN, DHTTYPE); //dht11
void before() { 
  for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);   
    // Set relay to last known state (using eeprom storage) 
    digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
  }
}

void setup()  {

  pinMode(INPUT_1,INPUT);
  debouncer1.attach(INPUT_1);
  debouncer1.interval(5);
  digitalWrite(INPUT_1,HIGH);
  
  pinMode(INPUT_2,INPUT);
  debouncer2.attach(INPUT_2);
  debouncer2.interval(5);
  digitalWrite(INPUT_2,HIGH);
dht.begin();  //dht11
}

void presentation()  
{   
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Relay", "1.0");
 present(CHILD_ID_1, S_DOOR);
 present(CHILD_ID_2, S_DOOR);

  for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    present(sensor, S_LIGHT);

  }
}

MyMessage msg(1, V_LIGHT);
MyMessage msg2(2, V_LIGHT);
MyMessage msg3(3, V_LIGHT);
MyMessage msg4(4, V_LIGHT);
MyMessage msg5(5, V_LIGHT);
MyMessage msg6(6, V_LIGHT);
MyMessage msg7(7, V_LIGHT);
MyMessage msg8(8, V_LIGHT);
MyMessage msg9(9, V_LIGHT);
MyMessage msg10(10, V_LIGHT);
MyMessage msg11(11, V_LIGHT);
MyMessage msg12(12, V_LIGHT);
MyMessage msg13(CHILD_ID_1, V_TRIPPED);
MyMessage msg14(CHILD_ID_2, V_TRIPPED);

void loop() {
// volgenderegels zijn dht11
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
  // einde dht11
  debouncer1.update();
  int value1 = debouncer1.read();
 
  if (value1 != oldValue1) {
     send(msg13.set(value1 == HIGH ? 1 : 0));
     oldValue1 = value1;
  }

       debouncer2.update();
  int value2 = debouncer2.read();
 
  if (value2 != oldValue2) {
     send(msg14.set(value2 == HIGH ? 1 : 0));
     oldValue2 = value2;
  }
}
  
void receive(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.type==V_LIGHT) {
     // Change relay state
     digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(message.sensor, message.getBool());
     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   } 
}
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: arduino dht11 to domoticz

Post by thomasbaetge »

Sorry, I may be a bit late to this party....

that's a lot of code you're having there.
I am using a couple of DHT11 with ESP8266. they are sending readings every 5 minutes via MQTT to domoticz and then go to deep sleep (otherwise you may find yourself measuring the temperature of the ESP/arduino board, if they are enclosed together.

If that's an option for you, let me know and I'll give you the code here.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests