Tiny Fire Alarm Detector Esp8266 MQTT IFTTT Home Automation

3,575

3

22

Introduction: Tiny Fire Alarm Detector Esp8266 MQTT IFTTT Home Automation

About: I like to combine electronics like Arduino's, ESP8266 etc with 3D designing and 3D printing.

I wanted to detect whether my home smoke detector system is in alarm. I have eight smoke detector in my home and they are interconnected. If one smoke detector is in alarm, the other get a signal via the interconnection signal wire. My sensor reads the interconnecting wire and sends the information to my home automation (Openhab2) via MQTT and alarms me also via IFTTT.

This instructable was inspired by this project https://hackaday.io/project/5472-internet-enabled-...

Step 1: Design

Firstly, you need to know how the smoke detectors communicate. I have Ei146 detectors.

The smoke detectors are interconnected via a "IC" line. If one smoke detector is activated, it generates a 6V - 8V signal on the IC line, see the picture of the oscillope screen.

I read the voltage of the IC line via an optocoupler (4N35), to isolate the smoke detectors from my home automation for safety.

The smoke alarm is powered by main voltage (220V AC), which I used to power the ESP-01 module

In the schematic you can see how the parts are connected. I use a ESP-01 sinc it is small and cheap.

Step 2: Building the PCB

In the pictures and the comments on the pictures you can see how the PCB is assembled.

I optimized layout to fit on components on a small PCB, the ESP-01 lies over other components. I attach the ESP-01 via female headers to ensure easy programming via a USB programmer. After the module is assembled, you can flash new firmware Over The Air (OTA) via the Arduino IDE or HTTPupdate (see sketch)

Step 3: Programming the ESP8266

See my Github for the code. I use all usable pins of the ESP-01 as GPIO-pins, that includes GPIO1 (TX) and GPIO3 (RX). So, serial communication is not possible and must not be initialized, otherwise the declaration of GPIO1 and GPIO3 becomes void.

Remark: do not pull GPIO0, GPIO1 or GPIO2 down at startup, because your program does not start. I found that GPIO03 can be pulled down at startup

I program my EPS-01's via this modified adapter.

The program runs as follows:

  • If the flash button is pushed at power up, the module initiates OTA mode.
  • HTTPupdate is initialized.
  • Connecting to WiFi and MQTT (green light on)
  • Reads the value of the sensor pin (attached to the IC pin of the smoke alarm)
  • If a fire is detected, wait for debounce and then raise the alarm (also Red light on) via
    • MQTT - the MQTT message is read via Openhab and a rule generates a notitification via my app
    • IFTTT - 1 - via a IFTTT Webhook a trigger is initiated which sends a notification.
    • IFTTT - 2 - via a IFTTT Webhook a trigger is initiated which sends a SMS to my wife
  • If the MQTT connection is lost (green light off), the LWT message (ERROR) is send to the topic and is read by Openhab.

Step 4: Assembling the Module

I designed and 3D-printed a box which nicely fits in the unused cable opening off the base plate of the smoke alarm, no screws needed.

Edit: stl-files are added.

I glued the LEDs and the OTA switch in place with hot glue. The box is closed via 4 screws.

Power up and ready!

Be the First to Share

    Recommendations

    • Raspberry Pi Contest

      Raspberry Pi Contest
    • Photography Challenge

      Photography Challenge
    • Fix It Speed Challenge

      Fix It Speed Challenge

    22 Comments

    0
    fwestenberg
    fwestenberg

    Question 5 months ago

    Hi Wim,

    Thanks for sharing this! I have the same fire detectors, and I'm going to use the optocoupler for triggering my Xiaomi Aqara Zigbee door sensor. By removing the reed sensor and replacing it with the optocoupler, it should work pretty easy!

    Now I'm wondering, why did you pick the 1k resistor? The 4N35 should typical use 10mA at 1.3v right? (https://www.farnell.com/datasheets/2047068.pdf). So by using this calculator i.e. https://elecurls.tripod.com/drop-res.htm I enter: 8v (in), 1.3v (out) and 0.01 (A current) and it calculates 670 ohm. Did I make some mistake? I'm trying to understand. Thanks!

    0
    Wim3d
    Wim3d

    Answer 5 months ago

    I guess your calculation of the resistor is correct. I don't remember how I determined the value of the 10k resistor. I think I found an example or just started on the safe side. In my case the optocoupler works with this high resistor.
    This was my first application of an optocoupler and in those days I was not used to interpretate datasheets.

    0
    fwestenberg
    fwestenberg

    Reply 4 months ago

    Hi Wim,

    Today I changed the resistor to 4k7 and still the optocoupler works. Even when testing with an external power supply providing 5v it still switches on. But also I experience sometimes it switches on without the alarm being triggered. Does this happen with your setup also? If not, I will also try a 10k resistor...

    0
    Wim3d
    Wim3d

    Reply 3 months ago

    In my code I use a debouncetime of 1000 ms after which the alarm is communicated by the sensor to my home automation. I do nothing with the debug messages which are published when the debouncetime starts. Today I programmed my home automation to register those debug messages to see if I have false triggers. I will let you know if this is the case.

    0
    fwestenberg
    fwestenberg

    Reply 3 months ago

    I see, the same strategy I also use right now to avoid the misleading alarm. I'm still curious why the signal goes high for a short moment. But I guess wel'll never know! Please let me know the outcome of your debug! Thanks!

    0
    HenriBoV
    HenriBoV

    Question 1 year ago on Step 2

    Dag Wim,

    I was wondering. Could you help me set up the MQTT-broker on OpenHab? I'm new to this, have been reading a lot on the topic, but couldn't get a clear grasp of your setup.

    I've isolated the publish messages:

    client.publish("sensor/smokedetector/debug", "no more fire")
    client.publish("sensor/smokedetector/debug", "Started")
    client.publish("sensor/smokedetector/debug", "fire! debounce")
    client.publish("sensor/smokedetector/debug", "no more fire")
    client.publish("sensor/smokedetector/debug", "debounce ended")
    client.publish("sensor/smokedetector/debug", "alarm reset")

    client.publish("sensor/smokedetector/state", "Status OK")
    client.publish("sensor/smokedetector/state", "fire!")
    client.publish("sensor/smokedetector/state", "OTA mode")

    client.publish("sensor/smokedetector/alarm", "FIRE")
    client.publish("sensor/smokedetector/alarm", "NOFIRE")

    Probably there are rules next to the broker. But to get an understanding of the broker is key I guess.

    I hope you can help me with this.

    Kind regards / groeten,

    Henri

    0
    Wim3d
    Wim3d

    Answer 1 year ago

    I use Mosquitto as broker on my Raspi, but you can also use the embedder MQTT broker in Openhab.
    In my Github I added my openhab files so you can study my setup and copy parts you need. https://github.com/Wim3d/ESP-Fire-alarm-detector/blob/master/Openhabfiles
    Please note that in my setup I still use the MQTT-binding 1.x. If you use the MQTT-binding 2.x, you need to define 'things' and channels which contain the MQTT-topic. In the 1.x MQTT setup, the MQTT-topics are in the .items file, as you see in my setup.
    For an explaination of the MQTT binding 2.x, please look at MK-smarthouse at youtube (https://youtu.be/R-SrZvKHXdA) or https://youtu.be/-8Wwi6MY0e8

    0
    HenriBoV
    HenriBoV

    Reply 1 year ago

    Hartelijk dank.

    0
    Craftyalchemist
    Craftyalchemist

    2 years ago

    I think I'm going to try and replicate your creation, any chance you can share the stl files for the enclosure you've designed? Thanks

    0
    Wim3d
    Wim3d

    Reply 2 years ago

    I added the stl files to the Instructable.

    0
    Craftyalchemist
    Craftyalchemist

    Reply 2 years ago

    Thanks for uploading those files. What's the value of the internal pull up resistor?

    0
    Wim3d
    Wim3d

    Reply 2 years ago

    In the program of the ESP8266 the pinmode is defined as INPUT_PULLUP and then the ESP uses the internal pullup resistor. Then there is no need for an external resistor. You can also use an external resistor, then use 10k for example.

    0
    Craftyalchemist
    Craftyalchemist

    Reply 2 years ago

    Hello again, can you share the format of the credentials.h,
    I did delete this from the .ino file and then just defined mySSID, etc. It connects to my WiFi but not my Mqtt server because of a socket error. I was wondering whether there was something in the credentials.h that might help. I also added const char* mqtt_port, mqtt_user etc. to the .ino file.

    0
    Wim3d
    Wim3d

    Reply 2 years ago

    In my credentials.h file no MQTT data is defined, so is it not needed if you defined the WiFi parameters in your code.
    Maybe your MQTT server has another port than 1883? Or maybe you need credentials for connecting to the MQTT server (my MQTT server does not need a password).

    0
    Craftyalchemist
    Craftyalchemist

    Reply 2 years ago

    Thajks for replying so fast.

    I think it something to do with the way the username and password are being defined.

    If I allow_anonymous on MQTT server then it connects, but it's a bit unstable.

    Do you know how I would incorporate a username and password into your sketch?

    Thanks.

    0
    Wim3d
    Wim3d

    Reply 2 years ago

    Did you succeed in making the device?

    0
    Craftyalchemist
    Craftyalchemist

    Reply 2 years ago

    OK, changed the line at around 290 to
    if (client.connect (mqtt_id, mqtt_user name, mqtt_password, mqtt_willTopic, 0, 0, "ERROR"))
    And added
    const char* mqtt_username = "user";
    const char* mqtt_password = "pass";

    Now it connects to my MQTT server without allowing anonymous connections

    0
    Wim3d
    Wim3d

    Reply 2 years ago

    Great that it works now

    0
    Craftyalchemist
    Craftyalchemist

    Reply 2 years ago

    Thanks for clarifying that, I'll post a picture when I'm finished, I'm just waiting for some of the components.