MQTT assistance

I’m really not sure where the issue is so I think I’ll try the whole thing again from scratch. New MCU and new DHT sensor and try this again.

The fact that you got the thing to work of the sketch right away gives me hope that it was an issue somewhere along the way I need to be aware of.

Thanks again for your help.

Did you try my sketch?
The MQTT setup is a bit easier than the one you used. I tried the one you posted without any luck too…

1 Like

If you like to improve your setup I can recommend a BME280 (pressure, temperature, humidity) instead of the DHT22. It can be hooked on the same I2C bus as the BH1750. I used both (DHT & BME) in parallel for half of a year. The measurements of the BME are more accurate and less noisy.

I know :wink:
Have another setup with the BME280.
I use that one outside with solar cell charging.
This is also hooked up to HA with MQTT

7 Likes

Awesome! Good job!

1 Like

Can you link the solar panel and charger/battery you used for this please?

Thank you!

Last remark: Did you remove the voltager divider of the Wemos D1 mini? Otherwise the measurements of ADC_MODE(ADC_VCC) aren’t useful. The ADC pin must float for ADC_VCC measurements.

Didn’t do anything about that no.
But I am not interested in the actual voltage. I just need to know approximately when I need to charge the battery :stuck_out_tongue:

The voltage divider is a feature of the Wemos D1 mini and can be hindrance if you want to use ADC_VCC. You can just remove the ADC_VCC code line and wire the ADC pin to your battery if the battery doesn’t supply more than 3.3V. I assume there is a voltage regulator between the battery and your ESP8266.

Yes, I have a TP4056 between battery and esp. Might need to try out your suggestion.

ok, your sketch has been verified and uploaded to my NodeMCU db. All good so far.

I’ve adjusted my sensors in HA as well to be subscribed to the correct topics (I change livingroom to bathroom as that’s where I’ll have it)

and here’s what I get when I query the mqtt broker on the pi

sensor/bathroom/temperature nan
sensor/bathroom/battery 2.94
sensor/bathroomroom/humidity nan

Awesome, it works, however no temp and humidity as yet. Either my sensor is kaput or I’ve got it wired to the wrong pin on the NodeMCU.

In your sketch you state
#define DHTPIN 2

Is this the second PIN on the sensor, so in my case as I’m using a 3 pin DHT11, I should change this to DHTPIN1?

Should I also be attaching the data wire from the sensor to which pin on the DB?

Thanks for all your assistance with this. I’ve learned a lot more about the inner workings of MQTT as a result and will be delving further into this area with future automations.

Let’s look at the pinout of the ESP/NodeMCU.
My

#define DHTPIN 2

refers to GPIO2 on the NodeMCU. On the drawing you can see that this is D4, and this is where I have connected my sensor.
From your picture I see you have connected it to D6.
So you should try this line

#define DHTPIN 12

or move it to D4.

If you want to use the deep sleep function, you also need to solder a wire between D0 and RST pin.

Solar panel:


Charger:

Battery:
3 Likes

ok, sorry that makes sense. D04 is GPI02 on my db as well so that’s where I’ll place the wire. I have the RST to D0 pin as well to allow for deep sleep.

Still no response for temp and humidity but the NodeMCU light is now constantly on, not just flicking on when power is connected.

would that be a good sign or not?

Could you check the size of your pull resistor of your DHT11 sensor board. May be this is the problem and the pull-up resistor is sized for 5V instead of 3.3V.

it’s 4.7k ohm but I am powering it from the VIN pin which is 5V isn’t it? This is from the original layout from the initial sketch I used. Should I change to 3.3 pin?

Nope. This is fine.

cool. so at this stage I’m thinking the DHT11 is cactus. the fact I get this output now

sensor/bathroom/temperature nan
sensor/bathroom/battery 2.94
sensor/bathroom/humidity nan

makes me very happy. Sadly I do not have a spare DHT or alternative sensor available to test but will try to organise something tomorrow. Here in Australia everything needs to be ordered in but I can get something within a week or so at the outside so will then hopefully have this up and reporting in as desired.

Can’t wait as then I can set several of them up for other rooms to assist in triggering automations.

I’m doing the same. Don’t forget to add a BH1750 or TSL2561 light sensor to your setup. Light conditions can be important, too. :slight_smile: