So, I struggled for weeks with getting intermittent NAN values from my DHT22’s on 6 different Bruh multisensors.
When I built the first one I thought it may have been a hardware issue with the nodemcu board, the DHT sensor or the power supply being used, but after building 6 of these with different brand power supplies, NodeMCU’s, DHT’s, etc. I was getting intermittent NANs on all of them at different times.
The only thing that would reliably fix it was to remove power from the nodemcu and reapply it (a reboot). After that it would tend to work for a while but the NANs would come back. Sometimes, very infrequently, it would fix itself.
Well, I think I finally nailed it. The DHT Sensor Library from Adafruit has a bug in it for all versions 1.2.0 and above. It is all over the web. For some reason it took me ages to find it, but now that I have found it, it appears to be rife. https://github.com/adafruit/DHT-sensor-library/issues/94
I didn’t want to stuff around with other libraries as I am just learning Arduino and didn’t want to introduce a possibly conflicting library as I didn’t know what the impact of that would be or how to undo it if I had issues.
The way I fixed it was to install version 1.1.1 of the library (the version previous to 1.2.0). After recompiling and redeploying the new code to all Bruh sensors, I have not had another NAN reported for a couple of weeks now.
There is a side effect though. The ComputeHeatIndex function within the DHT library doesn’t appear work properly in v1.1.1. It produces obviously incorrect heat index data. When humidity is high, heat index is low and vice versa.
I just ignore the heat index value calculated by the nodemcu, and calculate my own heat index inside of hassio using a value template.
I hope this helps someone who has/is experiencing similar frustrations to me. I almost abandoned the project because of it, but now I am stoked it is working. Wifey is not all that happy about seeing little 3D printed black boxes everywhere that flash red when she walks past them, but that is part of the fun isn’t it? Annoying the missus!
Built one of these a few weeks ago and damn I think the wife hates it. HA! Why does she hate it? Because I’ve been spending hours learning the code. Think I’ve tore into just about every piece of this sketch except the LED part as I didn’t have one to play with. Have a batch coming and will probably fix/change a lot of that too. Reminds me of the old school days writing efficient and tight code in the DOS days.
It’s probably a little overblown but I’ve broken out the MQTT calls to each sensor to get rid of those spikes in the graphs at times, added some status changes with the internal LEDs, such as blue with no motion and red with motion, cycling LEDs for WiFi disconnects or MQTT disconnects, controllable internal LEDs, configuration files on the EEPROM, etc. Working on the HTTP status page and throwing in the WiFi AP stuff on new/reset configs. I hate hard coding stuff! Will probably see about ordering a few different sensor types to add to the config. I’ll probably drop the source code later once I get things cleaned up.
Now I just need to find some cases for them or breakdown and buy a 3D printer. Been thinking of some ideas to do an all in one with a wall power supply where I can just plug these in the wall and point the PIR, or mounting them in some 1 gang boxes with the sensors mounted in a 1 gang plate. Anyone use the BME280 sensor yet?
I’ve also thought about the gang box route - would love to hear about your experience if you do it! I was looking at getting/making something like this AC-to-DC converter so that I could just tap into an existing power source in the wall, and in the event that I move I can just replace my sensor with a standard outlet and not have a random hole in the wall.
I was trying to keep some costs down and labor, been thinking of a few things.
One would be to buy a 2 gang box, old work style(deep) (US here). Mounted over something like a doorway for motion. Like in a bathroom above the door, you probably wouldn’t see it unless you were looking up on the way out. Throw in one of those all in one USB all in one chargers outlets on one side and blank on the other side. The USB wire would be shown a bit but loop it back inside and attach to the NodeMCU. Other three sensors would attach to the blank side of the plate. It would be relatively easy to fish down a piece of romex to power the plug, although it would never get used but you aren’t modifying anything on the 120vac side, all of your “hackery” is on the low voltage side. But would that comply with things mixing voltages in the same box. Probably not. I guess you could mount two 1 gang boxes but then what do you do when you don’t want it there anymore? So I kinda scratched this one.
It would be awesome to get one of those little taps to 2 prong for a phone style charger and throw it all in the 1 gang box. Again does it comply with things… hmm…not sure. Or an alternative would be a decent little power supply that has two screw terminals in and 5vdc out on the other of course.
This evening i built the other sensor with the other node mcu. But with one of the temt6000 that didn’t work on the other node.
I don’t understand it, but now the light sensor on that node does work.
So that problem is solved.