BRUH DIY Multisensor

Updated to allow MQ2 and MQ135 support in one sketch. Just uncomment which sensor you’d like to use.

https://raw.githubusercontent.com/firstof9/ESP-MQTT-JSON-Multisensor/MQ-support/bruh_mqtt_multisensor_github/bruh_mqtt_multisensor_github.ino

Enjoy!

3 Likes

Great!
Thank you very much

Here is Sensor Comparison:
MQ-2 Methane, Butane, LPG, smoke
MQ135 Air Quality (Benzene, Alcohol, smoke)

I’ve tried many supplies, from an iPad power supply and arious other ones I had lying around, to a 3A 5V one I bought at an electronics store specifically for this application… the latter tested at 5.3 V on my multimeter. So far the only one thats worked is the iPad charger, but it still drops out all the time.

Have you tried different cables? Or even a different brand cable? I have noticed that some USB cables have very small conductors in the cable, there may be a voltage drop under higher current power peaks (like when the WiFi radio wants to transmit). If you have a voltmeter you might try measuring the voltage at the ESP8266 and see if it seems reasonable and doesn’t wiggle around much.

Yessir, many different cables! I finally found what may have been the issue- I had it all wired un on a solderless bread board. once I took that out of the mix it seems to work great, been up and running for 24 hr now solid!

That’s great news! Nice to attribute a cause to the broken behavior that’s more than just “ghosts”.

1 Like

@lambtho Has this code been modified as the heatindex is not present. If I use your code and blow on my DHT22 sensor the readings change instantly but the readings are way high like +10degrees.

However, if I use BRUH’s original code with heatindex, and if I blow on my DHT22 sensor the readings dont change as quickly but the readings are 5 degrees high.

Have you changed the code you posted on here? I cannot understand what am I doing wrong. I have got a new DHT22 sensor as well.

No, this code was the first version of Ben’s code when he posted the video. He then added some features like the heatindex.

Concerning the ‘fast’ response of the sensor, maybe the delays he set into his loops have changed (if the delay between two readings is increased, obviously the sensor is going to take longer to respond). Keep in mind however that there is no need to poll data every 10 micro second… So a delay of 100 (0.1s) or even a bit higher is sufficient enough. Maybe the heatindex calculation alone is what slows down the updating. I am not an expert on those things, so I can not tell for sure if it could be introducing a significant delay or not.

For the temperature change, I am not sure to understand what you say.

  1. Does the temperature always differ if you do not touch the sensor ? If that is the case, are you sure you compare the two temperature and not temp and heatindex ? If you use two different DHT (one for each code) it might also be that one if faulty.
  2. Or do you mean that when you blow on it, the temp increases fast of about 10 deg in one case, and increases slower of about 5 deg in the second case ? If that is it, I think that it is due to the slower updating of the temp in the second sensor. Basically, on the first one you get the rise of temp directly, and in the second one the sensor has already cooled down a bit when it polls the value, hence returning a lower temp.

I hope this helps you a bit. I will redesign a bit the codes to better fit my expectations (I still have to find time to do it tough, maybe next month). Then I will post them if you want. For instance, when the sensor loses connection during the reconnect it sends a 0 value (for calibration I think). So if the sensor was not updated from a long time in HA, when you have the zero value, all the graphs are messed up, and I do not like it. I will either force the value to be sent every 5min or so (in order to have a smaller peak in the graph) or have it calibrate the sensor in an otherway. I also merge the bruh’s sensor code with the IR-RF mqtt gateway from 1technophile

1 Like

That is awesome, would you share the sketch with both integrated? Is everything working perfectly together?

Hi, currently I did a very very very simple merging of both scripts and it has been working great for the last month or so (I use only the IR part of the 1technophile gateway, but I assume the rest works as well).
I am a complete noob with arduino IDE and programming an ESP, so I basically created a function like the ZgatewayIR.ino or ZgatewayRF.ino that it called ZgatewayBRUH.ino, then added the good functions in the main loop and voilà. However, the code is not elegant at all, I want to make sure I understand everything in order to make it a bit more cleaner before sharing it in full.

Currently, the multisensor I have is:
ESP8266 powered by micro USB, and small breadboards in order to connect everything to ground and 3v3 or Vin

  • PIR sensor
  • Light Sensor
  • RGB Led
  • DHT22
  • IR receiver
  • 2 IR emitter (and a transistor to boost the current trough them)
1 Like

I might give it a go during the weekend then!
I have been just playing around with all the different sensor modules I bought in hopes of learning how to program on Arduino or at least a better understanding of it.

Might be a silly question but can I connect a breadboard to pin A0 and use multiple sensors from it?

Hi

Can you please share your automation code for controlling the fans if the temp is above X.

Thanks.

Thanks I discovered it was the faulty usb cable giving me issues. All sorted now.

1 Like

I haven’t set it up for the kids rooms yet, I need some cases before I put anything in their rooms. But I do have it set up from the AC. It’s portable unit that retains it’s state when unplugged so I was able to use a z wave appliance module to turn it off an on.

Nothing to fancy, only comes on if the temp is 25 or above, we are home and only between certain hours of the day.

alias: Turn on Air Conditioner
trigger:
  - platform: numeric_state
    entity_id: sensor.sn1_temperature
    above: 25
condition:
  - condition: state
    entity_id: input_boolean.presence
    state: 'on'
  - condition: time
    after: '9:00:00'
    before: '22:00:00'
action:
  - service: switch.turn_on
    entity_id: switch.leviton_dzpa11lw_plugin_appliance_module_switch

Edit: I’ve been thinking about adding in some predictability to it. Say if the outside temp is expected to be above X today, start the AC prior to the room reaching 25 degrees. Just to give the AC a jump start on cooling. I haven’t worked out how yet but I’m sure it’s probably fairly straight forward.

2 Likes

I was trying this project again since I made some other sensors successfully based on this code and I had the idea of looking through the github forks because I discovered when re-using the code there was a lot of room for improvements. I found this code which looks like it might be a big improvement. I don’t suppose someone has tried it?

So I am trying to turn my kitchen lights on when the temperature is above 18 degrees celsius, here is my code:

- alias: Temperature above 18 degrees celsius turn on Kitchen Lights
  trigger:
    platform: numeric_state
    entity_id: sensor.sn1_real_feel
    above: 18.0
  action:
   service: switch.turn_on
   entity_id:
    - switch.kitchen_lights

the automation seems to be working when I trigger it from the front end, however it doesn’t work when the temperature goes above 18 degrees celsius because at present the temperature is above 19.5 and it doesn’t seem to turn the Kitchen Lights on.

Am I missing something?

I believe it’s because the automation doesn’t technically trigger because the temp is already above the set point when you started. The temp didn’t go from 17.9 to 18.0. so it doesn’t fire.

Change your “above” temp to something higher then the present room temp and then try to trigger it by blowing on the sensor to raise the temp. This worked for me in testing. Someone smarter then me can probably tell us if there’s way to code it so it fires if the temp is already above the set point automatically. This would be case if you restarted HA and the temp was above the set point for instance. Similar to a Sunset trigger won’t fire at 2am.

I’m just learning myself so anyone feel free to correct me.

Right I see.

Did you mean I should raise my numerical “above” value of the temperature?

Try this:

  trigger:
    platform: template
    value_template: >
         {% if states.sensor.sn1_real_feel > 18 %}
              true
         {% endif %}
2 Likes