It also sends you alerts to your smartphone or Echo speakers.

You will also need aHome Assistant server setup on a Raspberry Pior any compatible hardware.

If interested, you canlearn everything about Home Assistantand see how it works before getting started.

gas leak sensor detector installed in kitchen beside chimney

Step 1: Compile the Firmware

To compile the firmware, install theESPHome add-onin Home Assistant.

Once installed, adhere to these instructions to compile the firmware for D1 Mini or NodeMCU.

The code should look like the screenshot below.

gas leakage yaml code for esphome

This will start compiling the firmware and may take roughly 10 minutes to finish.

Once finished, clickDownload projectto download the compiledgas-leakage-factory.binfirmware file.

You may also download and use theESPHome Flashertool to flash thegas-leakage-factory.binfirmware file to your NodeMCU or D1 Mini board.

download the compiled gas leakage detector firmware

Step 3: Add Gas Leakage Sensor to Home Assistant Dashboard

That’s it.

The gadget will be added to the selected Home Assistant dashboard.

Next, you’re able to connect the MQ-2 gas sensor to the microcontroller.

flash the gas leakage firmware

it’s possible for you to test the sensor by exposing it to smoke or gas.

Wear a mask and do not smell the gas or smoke.

The percent value should increase in the Home Assistant dashboard.

add lpg png methane gas leakage sensor to home assistant dashboard

For example, the sensor we built normally shows 10-15%.

To create an automation, go toSettings > Automations & Scenesand clickCreate Automation.

ChooseStart with empty automationand then pick the three dots at the top left.

lpg-natural-gas-co-gas-detector-in home-assistant-with-24hr-graph

Now, chooseEdit in YAMLand paste the following code.

Next, click thethree dotsagain and chooseEdit in visual editor.

Usually, the sensor remains at 10-15%.

mq2 gas sensor connected to d1 mini wifi microcontroller

gas leak automation sends voice alerts notifications