D1 mini and magnetic door trap

Hi all
I have a d1 mini, and magnetic door contact and I need to connect them to HA to know the status of the door. (open-closed)

I have installed espHome but (since I am a beginner) I don’t know

  1. how to to connect the wires in the d1
  2. how to add it as a senor to HA.

I have watched some videos and I think if I can make the right connection and know the code I will manage it.

Can someone help on please?

image

Take a look at ESPHome GPIO Binary Sensor.
The reed switch is normaly connected to ground and one GPIO pin.
Here’s an example:

binary_sensor:
  - platform: gpio
    pin:
      number: D5
      mode: INPUT_PULLUP
    name: og_roof_window
    filters:
      - delayed_on_off: 1000ms
    device_class: window

The esphome node should be auto detected in HA if you’re using the api key.

EDIT: And be carefull with D3 :slight_smile:

2 Likes

And D4 and D8. There’s a handy table of which GPIOs to use on this page:

2 Likes

Thanks for the response. If I understand correct the in the above example I suppose to connect the wires in the ground and d5 pin. Is that correct?

One more regarding the wires of the magnetic switch. If you see my photo on of them is longer than the other. does it matter which one goes to to the ground and which in d5?

Hi, do you mean I should be careful with D4 +D8 as per D3 that VDRainer suggests?

yes…

no…

2 Likes

I will go with D5 then. Thanks.

If I may I have 1 more questions. Suppose that after a month I want to add a temperature sensor for example. I should attach the sensor to D1 mini and just add the required code for the sensor below the code for this switch and if all are well it will work?

Yes that will work, after you compile and upload the new code.

1 Like

I just returned home and tried to connect the d1 mini to espHome. I have already installed an esp32 and it is online. When I installed esp32 I just plug it in the NUC where home assistant is and it was easy to connect it. Now that I am trying to connect the d1 I get this (no compatible devices found)

I watched this video for example that says that I can attach the d1 in every laptop or desktop and I can connect it. (@ 5:54) Although I tried I get the above message.

This is SO Much Better! Getting Started with ESPHome 2021 - YouTube

What could be wrong?

There is many ways to get the same job done.
But I think you are mixing two that can’t be mixed.

Connect the controller to your computer, the one with a keyboard and mouse, not the HA computer.
Then go to your secure HA address (HTTPS) and try again.

I tried with my windows laptop but again. is there a problem with the HTTPS?

In that case just compile it and download the binary to your computer and program the MCU with ESP tool or what it’s called.

yes, but I would like to be able to fix this problem. I have bought (several esp8266-32 boards) and I prefer to perform the actions from HA. Any sign what could be wrong?

I can’t see what is wrong.
I know some boards need you to push a button or ground a pin to be in programming mode.

But I don’t use duckdns so I have not tried it that way.
Maybe that is a limitation of duckdns, but I doubt it.

my windows was missing a driver = https://cdn.sparkfun.com/assets/learn_tutorials/5/9/7/Windows-CH340-Driver.zip

1 Like

after the drivers installation it worked with the below code

binary_sensor:
  - platform: gpio
    pin:
      number: D5
      mode: INPUT_PULLUP
    name: "Garage Door"
    device_class: door
``
thank you all for the help

Ah, yes, the drivers are important. I usually find it easier to just connect directly to the computer running Home Assistant and once that initial code is uploaded, I can do everything wirelessly OTA.

Having to install drivers that MS can’t be bothered to put in their OS is immensely frustrating.

I have never had to install a driver in linux for this sort of device.

Well, I did try to connect it to my NUC with ubuntu 18 and HA but didn’t find it either
I have to look up why it didn’t