DIY: Cheap wifi-based temperature/humidity sensor based on ESP8266 & DHT22

Ah Ok. Home Automation is quite new to me, and so is making stuff to connect to openhab.

So any help is very much appreciated.

Thanks :slight_smile:

Hi Robinson - would you mind sharing the code?
Ordered a few of these as cheap temperature sensors for around the house, but having only built arduino and netduini before, have to start over. If youā€™ve got some code and an explanation, will save me a chunk of time.
Are you ouxhi g data from the D1, or polling th D1 from OH?

Iā€™m asking myself if ESP8266 is a good choice for a battery powered sensor, mainly due to its power consumption. Does someone reached a duration of one year or more on a battery powered esp8266 sensor sending every hour?

This was a really cool projectā€¦

Found one issue, Adafruits library files had some changes made, so make sure you grab the latest batch.

Unfortunately Im not a code guy, Im more of the intergration interface kinda guy.

Is there a way to get this to send its data as fahrenheit?
Thanks
Dave

Hi,
You should ask ā€œIs wifi the best platform for battery powered sensors?ā€ No! It was never designed for that. Zigbee, Bluetooth LE and others are especially designed for low energy designs. What makes the esp so appealing ist: cheap, greate community, easy to program, standard protocols, your router is your hub ā€¦
For power consumption and best practices on battery powered sensors based on the esp you find a lot of info in the net. (Start here: https://youtu.be/wf_msvWv1jk)
Connecting a dht22 to a nodeMCU or wemos board will be disappointing! But it is possible to build a battery powered sensor: https://youtu.be/IYuYTfO6iOs

Firmaware for sensors board - Minimalist SDK on ESP8266ex v1.5.2.
After powerup, reset or deep-sleep connection established within 540ms, using static IP.

1 Like

Hello,

I want to use an ESP8266 based temperature sensor, mainly for Room temperature logging. No Actions or other home automation planned at all. Thinking about running OpenHab and MQTT on my Synology NAS (should workā€¦ right?) and Logging the temperature every 1-2 Minutes, but only activating WiFi and sending all stored results every 10-30 Minutes, because i want to use a Battery powered sensor. This should decrease batterydrain by quite a bitā€¦ if itā€™s possible. is it ?

Greetings,
haldi

I tried this some time ago: you wonā€™t be happy, battery life will be two weeks at most ā€¦ even with deep sleep function enabled.

Saw this Video now.

But then again ESP32 with BLuetooth Low Energy might be a better option. BUT this would mean you need a Host/Control Unit (Not Battery Powered preferably) somewhere which does the Redirection BLE -> Network/WiFi.

Iā€™m Certain someone has done something similar before. Are my google skills just too bad?

Yep did the same wifi is just too much of a battery killer. I ended up going with USB powered units. :frowning:

1 Like

Use the ESP32/8266 as an NRLF2301 receiver publishing to MQTT and the sensors are NRLF2301 based senders running off of coin batteries (2301). Lost of tutorials online for the NRLF2301.

1 Like

Hello,

As said before wifi is not designed for battery powered sensors, even if the esp8266 is easy to program and to connect to the hub that 95% of people have (a router). If you go to sub ghz techno; 433mhz or 868mhz and want to diy, you will find possibilities with less consumptions and sensors that last years, Take a look at:
-jeenode
http://jeelabs.net/projects/hardware/wiki/JeeNode
-moteino
https://lowpowerlab.com/guide/moteino/
Or even with some basic arduino board you will have far better duration compared to a wifi sensor on battery.

Ble can be a solution here is some info

1 Like

Ok NRLf24L01 as the remote sensor on coin batteries works for meā€¦lower freq ~ lower ah consumption get itā€¦the NRLF24l01 consumption when not awake is minimal so a life of a year on battery along with the cost makes it a throw away no brainer for me. YMMV. No religion just experience.

Can someone edit the above code and include a sleep state of the esp8266 while there is no measuring?

Battery consumption doesnĀ“t matter, my problem with this is, i donĀ“t want to measure the own heat of the esp8266. So if it is sleeping all the time and only wakes up all 5 minutes, there will not be much own heat of it.

ESP8266 using the REST Interface to post the data @ wakepup every 30 minutes = ~1 year battery life

@halloween
simple ESP.deepSleep(1800000000); //30 minutes
Dont forget to tie the RST pin to GPIO 16 (ESP-12)

1 Like

I have KNX Installation and so i have wires all around the house, with the two free wires of the knx cable, i will provide 12V or whatever i will need. Only problem i see is the self heating of the esp8266 and so i could get wrong temperature measurements.

If i want to go the 12V way, what do i need to get a lower voltage for my esp? I think i need 3,3 volt? What is the best solution for this - with lowest self heating? linear power regulator? Can someone give me the right name of that?

@rockster
What kind of batteries do you use? 2 x AA ?

Can you provide your complete esp-code? IĀ“m a noob in esp or arduino programming :frowning:

Do i have a benefit, if i use mqtt? I think, with rest interface i will get the same data into openhab with less work? I only want to get temp/humidity and maybe with another sensor board co2 and VOC.

@halloween
no problem, im using 2x AA batteries:

#include <ESP8266WiFi.h>
#include "DHT.h"
#include "RestClient.h"

extern "C" {
  #include "user_interface.h"
}

const char* ssid     = "ssid";
const char* password = "pass";
const int   sensorID = 1;

ADC_MODE(ADC_VCC); 
DHT dht(D1, DHT11);
RestClient client = RestClient("openhab",8080);

void setup() {
  wifi_set_phy_mode(PHY_MODE_11B);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  int wificounter = 0;
  while (WiFi.status() != WL_CONNECTED) {
    if (wificounter > 10) {
      //wifi failed, go to sleep
      ESP.deepSleep(1800000000);
    }
    delay(500);
    wificounter = wificounter + 1;
  }
  dht.begin();
}


void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  if (isnan(h) || isnan(t)) {
    ////temp failed, go to sleep
    ESP.deepSleep(1800000000);
  }

  String openhab = "{\"device\":\"tempSensor\",\"id\":";
  openhab += sensorID;
  openhab += ",\"temp\":";
  openhab += t;
  openhab +=",\"humi\":";
  openhab += h;
  openhab +=",\"volt\":";
  openhab += ESP.getVcc();
  openhab +="}";
  
  client.setContentType("text/plain");
  char postbuffer[openhab.length()+1];
  openhab.toCharArray(postbuffer, openhab.length()+1);
  client.post("/rest/items/sensorData", postbuffer);
  
  ESP.deepSleep(1800000000);
}
4 Likes

Do you have a picture of your sensor? Maybe where i can see the whole sensor-board and a second picture where i can see, how you installed it in your home? Did you flash mount it in the wall?

sorry, i have no picture avaiable. i recommend not use a development board and to remove the led to save battery. I have placed the sensor on top off furniture (rack, wardrobe, etc)

I am on a learning curve ā€¦
I read that the REST API is for controlling openhab2 and MQTT to update items in openhab2 from external sensors.
In your ESP code above you post data to openhab2 with the REST API?
What items have you created to receive the data?