Ricardo Abrantes
Published © GPL3+

NodeRed video door entry

To prevent the spread of covid-19, WHO recommends to avoid the contact with surfaces or objects.So, I made my main door open with a cellhone

IntermediateFull instructions provided3 hours1,833
NodeRed video door entry

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1
ESP8266 ESP-12E/F CP2102 Nodemcu Lua USB 32M Internet Wifi Adapter Module
×1
L293D WiFi Motor Drive Shield Module For Arduino NodeMCU Lua ESP8266 ESP-12E
×1
DC-DC Step Down Buck Converter Power Supply Module 24V 12V 9V to 5V 5A 25W
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Standard Terminal Block, Lever-Nuts
Standard Terminal Block, Lever-Nuts
×4

Software apps and online services

Arduino IDE
Arduino IDE
Node-RED
Node-RED

Story

Read more

Schematics

Fermax Loft monitor interior assembly

Code

ESP8266 Fermax MQTT

Arduino
ESP8266 Code with MQTT connection and OTA update
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

//NodeMCU Motor Shield I/O
#define KEY   D1
#define VIDEO D2
#define OUTA  D3
#define OUTB  D4

//Wifi
const char* ssid = "----";
const char* wifi_password = "----";
IPAddress ip(192, 168, 1, 2);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// MQTT
const char* mqtt_server = "----";
const char* mqtt_topic = "FermaxDoor";
const char* mqtt_username = "----";
const char* mqtt_password = "----";
const char* clientID = "Fermax";

WiFiClient wifiClient;
PubSubClient client(mqtt_server, 1883, wifiClient);

void ReceivedMessage(char* topic, byte* payload, unsigned int length) {

  if ((char)payload[0] == '1') {

    digitalWrite(OUTA, HIGH);
    digitalWrite(OUTB, HIGH);
    delay(10);

    //"Press" video button to switch on monitor
    digitalWrite(VIDEO, HIGH);
    delay(2000);
    digitalWrite(VIDEO, LOW);
    delay(1000);

    //"Press" key button to oppen the door
    digitalWrite(KEY, HIGH);
    delay(1000);
    digitalWrite(KEY, LOW);
    delay(1000);

    //"Press" video button to switch off monitor
    digitalWrite(VIDEO, HIGH);
    delay(500);
    digitalWrite(VIDEO, LOW);
    delay(100);

    digitalWrite(OUTA, LOW);
    digitalWrite(OUTB, LOW);
    delay(10);
  }
}

bool Connect() {
  // Connect to MQTT Server and subscribe to the topic
  if (client.connect(clientID, mqtt_username, mqtt_password)) {
    client.subscribe(mqtt_topic);
    return true;
  }
  else {
    return false;
  }
}

void setup() {

  pinMode(KEY, OUTPUT);
  pinMode(VIDEO, OUTPUT);
  pinMode(OUTA, OUTPUT);
  pinMode(OUTB, OUTPUT);

  digitalWrite(KEY, LOW);
  digitalWrite(VIDEO, LOW);
  digitalWrite(OUTA, LOW);
  digitalWrite(OUTB, LOW);

  // Connect to WiFi
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, wifi_password);

  // Wait until the connection has been confirmed before continuing
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  ArduinoOTA.setHostname("ESP_Fermax");
  ArduinoOTA.begin();

  client.setCallback(ReceivedMessage);
}

void loop() {
  // If the connection is lost, try to connect again
  if (!client.connected()) {
    Connect();
  }

  client.loop();

  ArduinoOTA.handle();
}

NodeRed Flow

JSON
[
    {
        "id": "70fb7a00.957a24",
        "type": "mqtt out",
        "z": "16f783de.471cdc",
        "name": "",
        "topic": "FermaxDoor",
        "qos": "1",
        "retain": "",
        "broker": "1820173.0315be9",
        "x": 940,
        "y": 1380,
        "wires": []
    },
    {
        "id": "66e769ef.fb9d68",
        "type": "ui_button",
        "z": "16f783de.471cdc",
        "name": "",
        "group": "d0858a86.88d2d8",
        "order": 2,
        "width": "4",
        "height": "1",
        "passthru": false,
        "label": "{{msg.texto}}",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{background}}",
        "icon": "fa-sign-in fa-2x",
        "payload": "1",
        "payloadType": "num",
        "topic": "",
        "x": 630,
        "y": 1380,
        "wires": [
            [
                "eb00410e.9fd95",
                "29f40ada.0332b6"
            ]
        ]
    },
    {
        "id": "38c90c2c.d26804",
        "type": "function",
        "z": "16f783de.471cdc",
        "name": "Door button text",
        "func": "if (msg.payload == '0'){\n    msg.texto = \"Opening...\";\n    msg.background = \"#C0C0C0\";\n    flow.set('OpeningDoor',true);\n}\nelse {\n    msg.payload = '0';\n    msg.texto = \"Open the door\";\n    msg.background = \"#32af3d\";\n    flow.set('OpeningDoor',false);\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 470,
        "y": 1380,
        "wires": [
            [
                "66e769ef.fb9d68"
            ]
        ]
    },
    {
        "id": "eb00410e.9fd95",
        "type": "trigger",
        "z": "16f783de.471cdc",
        "op1": "0",
        "op2": "x",
        "op1type": "str",
        "op2type": "str",
        "duration": "10",
        "extend": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "name": "",
        "x": 530,
        "y": 1300,
        "wires": [
            [
                "38c90c2c.d26804"
            ]
        ]
    },
    {
        "id": "948474fb.4fe0f8",
        "type": "inject",
        "z": "16f783de.471cdc",
        "name": "",
        "topic": "",
        "payload": "x",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "x": 290,
        "y": 1380,
        "wires": [
            [
                "38c90c2c.d26804"
            ]
        ]
    },
    {
        "id": "29f40ada.0332b6",
        "type": "function",
        "z": "16f783de.471cdc",
        "name": "Open the door",
        "func": "if (msg.payload == '1' && flow.get('OpeningDoor')===false){\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 790,
        "y": 1380,
        "wires": [
            [
                "70fb7a00.957a24"
            ]
        ]
    },
    {
        "id": "1820173.0315be9",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "d0858a86.88d2d8",
        "type": "ui_group",
        "z": "",
        "name": "Door entry",
        "tab": "de4212be.7e8d3",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "de4212be.7e8d3",
        "type": "ui_tab",
        "z": "",
        "name": "Home",
        "icon": "home",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Credits

Ricardo Abrantes
1 project • 1 follower
Industrial automation and robotics programmer. Innovator of home automation solutions (in my spare time)
Contact

Comments

Please log in or sign up to comment.