Garage Door Open/Closed Monitor via ESP-NOW or Domestic LAN

Hello,
My name is David. I am a retired mechanical engineer living in the UK. I am in the fortunate position of having three garages at my disposal at the rear of my house. There are a total of four electrically operated doors on the garages, non of which can be seen from the house. Unfortunately probably due to advancing years, I have occasionally left one of the doors open all night.
I am trying to construct a monitoring system that will indicate via a small panel in the house when the doors are open or closed.
I am exploring doing this by using a reed switch et each door that signals it's state to either a red or green LED connected by nodeMCU's using either ESP-NOW or over the domestic LAN which is available in all garages via wifi extenders.
I have trialed the ESP-NOW idea by copying and pasting Arduino IDE sketches to some nodeMCU's but the programmes only transmit textual messages. I can' seem to find out how to replace the text with instructions to accept switching input at one nodeMCU and and send to a second nodeMCU to switch an LED.
If I could make this work my only concern would be whether the ESP8266 wifi signal would travel through a number of masonery walls. If not I would have to use the LAN.
I would be extremely grateful if anyone can offer me any pointers.

Unless you particularly want to do this, can't you buy a security camera and point it to the garage?

These security cameras connect to your home wifi network and have an app which gives you a live view.

.

If you can see part of the garage why not simply put some LEDs that will show the status of each door, or one that will show if any one is open. I would consider Green to show it is powered and Red to show a fault. If you recess the LED(s) a bit it will shield them from direct sunlight and make them easier to see. This can be powered from some wall wart you have around, DC output voltage is not critical, you just need it to calculate the LED resistors.

Thank you for your replys.
I am looking for a simple system that just indicates by red or green LED whether any of the four doors are open.
The suggestion to use cameras (4) suggests an expensive installation which would require an app to monitor. A panel with either red or green led's that is always evident seems to me to be a simpler solution.
Unfortunately none of the doors are visible from within the house and wiring difficulties preclude direct connection from door contact switches to an led panel, hence the desire to use some form of wifi communication.
There is also the desire to solve the problem as a learning exercise as I have very little prior knowledge in this area.
Do the replies suggest that what I would like to do is either not possible, or very complicated?

I haven't used ESP-NOW (or heard of it until this thread) but if you can send text messages between nodeMCU's, then your project is achievable.

Try it for a single door. Read the status of a switch that tells you whether it's open or closed. Send "Door1 open" or "Door1 closed" to the master in charge of lighting the LEDs and use string comparison operations (strcmp) to see what state the door is in and set the LEDs accordingly.

Have you considered the multi-purpose sensors from smartthings? battery operated, and offer vibration, open/closed, temp and acceleration functionality all in one, then to montior, yes it comes with its own app, BUT you can incorporate it with a central dashboard of sorts to have a visual anywhere in the house, or phone

I use the these as temp sensors for my outdoor pets enclosures and using home assistant, i am able to setup notifications if my thresholds are met and i need to act on anything..

If not, the nodemcu should work as well, i have two of those im using within my house to monitor our washer and dryer so we can get a notification that they are done. due to the distance from the laundry room to our room, we dont always hear them finish, so i have the boards monitor and notify us, and they are sending numerical values and within my home assistant i have a notification that if my threshold is met, it sends the notification.

theoldengineer:
Thank you for your replys.
I am looking for a simple system that just indicates by red or green LED whether any of the four doors are open.
The suggestion to use cameras (4) suggests an expensive installation which would require an app to monitor. A panel with either red or green led's that is always evident seems to me to be a simpler solution.
Unfortunately none of the doors are visible from within the house and wiring difficulties preclude direct connection from door contact switches to an led panel, hence the desire to use some form of wifi communication.
There is also the desire to solve the problem as a learning exercise as I have very little prior knowledge in this area.
Do the replies suggest that what I would like to do is either not possible, or very complicated?

Why does there need to be 4 cameras?????

ieee488:
Why does there need to be 4 cameras?????

Unfortunately the four garage doors are so situated that it would not be possible to see all the doors unless having a minimum of 3 cameras. Even then, the positioning and cabling to the cameras would be difficult.
I am really trying to come up with a system that would enable me to have a small panel inside the house that has indicator lights that would show at a glance that all the doors were closed (or not).
A camera system would require that it would be necessary to positively switch on either a phone or PC to view the camera output, whereas a red light in an obvious place would not be likely to be missed.

Can you post the sketch you are trying to use on the nodeMCU's?

If you have communications already working and its just a matter of modifying it to meet your needs maybe we can help determine where to make the changes.

Like i said in my post, im currently using my NodeMCU's to monitor our washer and dryer status, i have a light sensor mounted to the board and adhered to the machines status lights, when the light on the washer or dryer comes on, we get notified...

In your case, you can take the data coming from the reed switches and write the code to trigger some LED's in the house..

what you are asking for is def doable, just need some testing on the communications to make sure that the boards out on the doors are able to send what you want and translate it on the board in the house.

cubangt:
Can you post the sketch you are trying to use on the nodeMCU’s?

If you have communications already working and its just a matter of modifying it to meet your needs maybe we can help determine where to make the changes.

Like i said in my post, im currently using my NodeMCU’s to monitor our washer and dryer status, i have a light sensor mounted to the board and adhered to the machines status lights, when the light on the washer or dryer comes on, we get notified…

In your case, you can take the data coming from the reed switches and write the code to trigger some LED’s in the house…

what you are asking for is def doable, just need some testing on the communications to make sure that the boards out on the doors are able to send what you want and translate it on the board in the house.

The sketch I have used fro two example senders is this, with the board id changed for the second board.

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-many-to-one-esp8266-nodemcu/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <ESP8266WiFi.h>
#include <espnow.h>

// REPLACE WITH RECEIVER MAC Address
uint8_t broadcastAddress[] = {0x84, 0xCC, 0xA8, 0x83, 0x10, 0xA2};

// Set your Board ID (ESP8266 Sender #1 = BOARD_ID 1, ESP8266 Sender #2 = BOARD_ID 2, etc)
#define BOARD_ID 2

// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
    int id =1;
    int x=random(0,50);
    int y=random(0,50);
} struct_message;

// Create a struct_message called test to store variables to be sent
struct_message myData;

unsigned long lastTime = 0;
unsigned long timerDelay = 10000;

// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("\r\nLast Packet Send Status: ");
  if (sendStatus == 0){
    Serial.println("Delivery success");
  }
  else{
    Serial.println("Delivery fail");
  }
}
 
void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
 
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  } 
  // Set ESP-NOW role
  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);

  // Once ESPNow is successfully init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);
  
  // Register peer
  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);

}
 
void loop() {
  if ((millis() - lastTime) > timerDelay) {
    // Set values to send
    myData.id = BOARD_ID;
    myData.x = random(1, 50);
    myData.y = random(1, 50);

    // Send message via ESP-NOW
    esp_now_send(0, (uint8_t *) &myData, sizeof(myData));
    lastTime = millis();
  }
}

And the sketch for the receiver is:

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-many-to-one-esp8266-nodemcu/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <ESP8266WiFi.h>
#include <espnow.h>

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    int id;
    int x;
    int y;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;

// Create an array with all the structures
struct_message boardsStruct[2] = {board1, board2};

// Callback function that will be executed when data is received
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) {
  char macStr[18];
  Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id-1].x = myData.x;
  boardsStruct[myData.id-1].y = myData.y;
  Serial.printf("x value: %d \n", boardsStruct[myData.id-1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id-1].y);
  Serial.println();
}
 
void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);
}

void loop(){
  // Access the variables for each board
  /*int board1X = boardsStruct[0].x;
  int board1Y = boardsStruct[0].y;
  int board2X = boardsStruct[1].x;
  int board2Y = boardsStruct[1].y;
  */
}

The sends a random number from the sender to the receiver, but it requires the serial monitor to view the exchange.
I would like to be able to send the on or off state of a switch to the receiver where it would control the switching of LED’s.

So for the section in the sender where you define the structure, you can change that to send the datatypes you want

// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
int id =1;
int x=random(0,50);
int y=random(0,50);
} struct_message;

Currently sending int values, but you can change that or leave it and just replace the random portion with your sensor values.

Down in the loop section, you would pass in your sensor values here
// Set values to send
myData.id = BOARD_ID;
myData.x = random(1, 50);
myData.y = random(1, 50);

Since you are working with sample code, easiest thing would be to make small changes to the code to work with your sensors and values..

Do you currently have the sensors you want already setup? I ask because i don't see anything that would be getting values from any other device/sensor.

You don't have to make the changes in this sketch yet, I would take your sensor and get it working on a separate board or sketch. Determine what values it sends and how you want to handle those values, once you have that portion then you can add that logic to this code.

(really simple example, not what yours will do, but...)

If you sensors were to send out a "0" for closed and a "1" for open, then you could write your If condition to handle the LED on and off based on those 2 values.

Im at work and dont have sample sketches in front of me, but i think if you can take the bigger picture of what you are trying to accomplish and get smaller sections working then it can all be combined into your sketches above to get it working as you want..

Do you already have the LED's, the setup you want in your home to display the lights/status?

ill help as much as i can..

That's probably 90% of what you need. Rui Santos has done the heavy lifting for you. I suggest that you change his struct and add a boolean called DoorOpen (or what you will). Print it on the receiver. Later you can set the boolean depending on a switch on the door and then you can light a LED on the receiver.

Thank you for your interest and help.I have never programmed anything in my life. This all started with the basic desire to have a simple and obvious indication in the house of whether I had left a garage door open.
I have currently got 4 nodeMCU's, a number of reed switches some red and green LED's, a selection of resistors and a couple of breadboards.
I have been working through example circuits from the internet and have demonstrated a sketch that monitors a reed switch and controls a pair of LED's, but it is all on one nodeMCU.
I would like to be able to create an example installation with 2 senders and a receiver on the bench before installing any of it.
Modifying the code is still a black art to me, but I am trying to understand it bit by bit.

This kind of thing is best done in small steps.

An easy one would be to take your code that monitors the reed switch and add it to the transmit program.

wildbill:
This kind of thing is best done in small steps.

An easy one would be to take your code that monitors the reed switch and add it to the transmit program.

Agreed, take those small steps and get each portion of the project working independently, then add each of those into the transmit sketch and test…

The way i deal with working with multiple things is incorporate one functionality into the overall sketch at a time, easier to ensure that the new logic works with the overall sketch.

Any progress on this yet?

I have discovered that my next door neighbour was involved in programming during his employment, although not with C or C++, but he has written a programme that so far signals 1's or 0's when installed with a couple of contact switches. The programme will accommodate switch inputs from 1, 2, 3 or 4 doors which gives me options depending on whether I can get a cable to each door.
He is currently working on the output programme for the receiver board.
I am installing wiring and contact switches and have designed the way I think I will construct the permanent soldered board.
Just ordered a list of components with the object of having a go at building the components into a permanent installation.
I have yet to work out how to build and where to site the panel with the LED's, but I'll get to that soon.
Thank you for your advice and encouragement. I will post my progress as it goes on.

theoldengineer:
I have discovered that my next door neighbour was involved in programming during his employment

Very convenient. As my grandad was prone to say: "It's not what you know, it's who you know".

I’m late to the party as usual…
I had exactly the same problem. I only have one garage door & it’s also very near which makes life easier.
I looked at using a ESP8266 but ditched it because of the power requirements.
I looked at reed switches & was quite surprised by how expensive these are!

My door is of the ‘up & over’ variety.

Ultimately I used a mercury tilt switch & 433MHz Tx attached to a ATTiny85. This was used to ring a very cheap 433MHz doorbell using the RCSwitch library. The sensor parts & battery were stuck to the inside of the door.
This worked fine but had a limitation - I tended to leave the door half open & making the tilt switch idiot proof didn’t work.

The next iteration used an accelerometer to measure the angle of the door - unless it was near to vertical it was deemed open. Accelerometers are cheap, amazingly they compare well with reed switches & magnets with none of the installation issues.

I never implemented the accelerometer version but I did use it as a case study with some Engineering Design students I was teaching at the time.

Ironically I don’t use this at all now. I spent so much time checking that everything worked I developed a habit of checking the door!!

Ian

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.