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

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?

https://shelly.cloud/product/shelly-wifi-humidity-and-temperature-sensor/

This thingy is ESP8266 based with a CR123A – 3V 1400mAh Battery and supposed to last 1 year.
And yes you can Reflash it.

Downside is the price of about 24$

Good day, everyone. Digging this old thread up, it’s the most relevant that I could find.
I have a few NodeMCU ESP-12P development boards and AM2302 (DHT22) sensors and the goal is to get them inputting via my Mosquitto MQTT. An added handicap is that I’ve done very little with Arduino and don’t quite get many of those programming commands yet.
I found a very simple program to load into the board and via serial monitor can get it to show output values. But when I get to the point of configuring values to feed to openhab via MQTT…it’s gets very fuzzy for me. Does someone have a good workable example I can use to learn? The code examples above are old and I’m having trouble getting them to work at all.
Thanks in advance for the help.

If you want an easy route: flash the esp8266 with Tasmota.

You’ll then be able to get at the data using the MQTT binding.

Related: Tasmota flashed Sonoff Basic with DHT22 via MQTT

Of course, if this is an exercise in getting your own code to work, check some similar projects to see how they handle MQTT.

Another solution available recently is an LYWSD03MMC + an ESP32, no soldering required, you will have a cheap, durable, low power solution to get temperature and humidity.
More info below:

Huh. I hadn’t thought of that. I have a few Sonoff Basics laying around and I may try this. I’d still like to get the NodeMCU work as well, it will help me learn some of those programming skills. But I have been successful in getting the Sonoff/Tasmotas on my system to work. Thanks, great suggestion!

You don’t need to use the Basics - you should be able to flash your NodeMCU with Tasmota too.