# \[DIY\] Opening my apartment door remotely with Homey

**URL:** <https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272>\
**Category:** Devices\
**Created:** [November 20, 2018, 1:45pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272 "2018-11-20T13:45:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien\_Moors](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/julien_moors/32/26538_2.png) [@Julien\_Moors](https://community.homey.app/u/Julien_Moors)\
**Post date:** [November 20, 2018, 1:45pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/1 "2018-11-20T13:45:46Z")

</div>

Hello !

I’ve done the DIY from Athom here [opening-apartments-door-remotely-homey](https://blog.athom.com/opening-apartments-door-remotely-homey/)

I’ve followed every single steps but it doesn’t work 😥

 ![46505802_322095828622100_2099977465710510080_n](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/a/a918e8c0b203be24453b1667c9aa2a69ff91237c.jpeg)

Then this code via Arduino:

```
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>

#define RELAY_TIMEOUT 500

int PIN_RELAY = D1;

ESP8266WebServer server(80);
WiFiManager wifiManager;

void setup() {
  
  pinMode(PIN_RELAY, OUTPUT);
  relayOff();

  WiFi.hostname("RelayCtrl");
  wifi_station_set_hostname("RelayCtrl");
  
  wifiManager.setConfigPortalTimeout(180);
  wifiManager.autoConnect("RelayCtrl");
  
  if(WiFi.status() != WL_CONNECTED) {
    ESP.restart();
    return;
  }
  
  ArduinoOTA.setPort(80);
  ArduinoOTA.setHostname("RelayCtrl");
  ArduinoOTA.begin();
  
  if (MDNS.begin("RelayCtrl")) {
    MDNS.addService("http", "tcp", 80);
    MDNS.addService("RelayCtrl", "tcp", 80);
  }

  server.on("/on", HTTP_GET, _onHttpRelayOn);
  server.on("/off", HTTP_GET, _onHttpRelayOff);
  server.on("/toggle", HTTP_GET, _onHttpRelayToggle);
  server.begin();
  
}

void loop() {
  server.handleClient();
  ArduinoOTA.handle();
}

void _onHttpRelayOn() {
  relayOn();
  server.send(200);
}

void _onHttpRelayOff() {
  relayOff();
  server.send(200);
}

void _onHttpRelayToggle() {
  relayToggle();
  server.send(200);
}

void relayToggle() {
  relayOn();
  delay(RELAY_TIMEOUT);
  relayOff();
}

void relayOn() {
  digitalWrite(PIN_RELAY, HIGH);
}

void relayOff() {
  digitalWrite(PIN_RELAY, LOW);
}

```

Then add it to Wifi (everything is ok) but when I go to “[http://relayctrl.local/toggle](http://relayctrl.local/toggle)” I don’t ear anything, not a click or something…

Then I’ve tried different config with my interfone but nothing happened (I removed the green plate on picture to get access to plugs):

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/7/7a868ab3eef97981f80d8a18913e33d38c30ec35.jpeg)

My interfone model is Niko 10-505:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/e/e7be78fa5616d353127f1778ef0400041ceff4f0.png)

I don’t know wich step is wrong and I don’t know how to know if my relay works…

Any idea ?

Thanks,

Julien

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 19, 2020, 11:50am UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/2 "2020-01-19T11:50:51Z")

</div>

Hi @Julien_Moors,  
Dit you manage it after all?  
I am doing this DIY project too. In my case the relay is working fine, but the problem is that my intercom seems to be “active” before I can use the button to open the door.  
That is: someone has to have ringed the bell, or I have to use the button to view the camera before I can use the button to open the door. (I have a Tegui M-72).

Now, I could use 2 Arduino’s and relays to first “press” the button for the video function to make the intercom active, and then use the second to press the button for opening the door.  
But another solution could be more elegant…

Any ideas?

---

<div class="post-metadata">

**Author:** ![Julien\_Moors](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/julien_moors/32/26538_2.png) [@Julien\_Moors](https://community.homey.app/u/Julien_Moors)\
**Post date:** [January 20, 2020, 9:09am UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/3 "2020-01-20T09:09:04Z")

</div>

Sorry @Henk_Renting, I stopped this project after several tries ☹  
BUT I’m now quiet more confortable with arduino, solder,… so I maybe gonna try again !

KIT

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 20, 2020, 6:42pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/4 "2020-01-20T18:42:32Z")

</div>

I have managed it too. It’s very doable!  
(cheap Wemos products are sold here too: [https://opencircuit.be/List/Platformen/Wemos](https://opencircuit.be/List/Platformen/Wemos) great services too, very recommended!).

Parts for a secons Wemos/Arduino will be delivered tomorrow, so that relay can activate the intercom by “pressing” the buttom for screen activating/communication) before “pressing” the dooropener…

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [January 21, 2020, 1:57pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/5 "2020-01-21T13:57:35Z")

</div>

You can easely control 2 relais with the same arduino,  
: set first relay ON  
: delay 200 mSec  
: set first relay OFF  
: delay 100 mSec  
: set second relay ON  
: delay 200 mSec  
: set second relay OFF

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 2:12pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/6 "2020-01-21T14:12:54Z")

</div>

@JPe4619  
Hi Jan,  
Thank you. I can imagine it can. But I am afraid my programming skill are not up to that level…  
Yours?  
Would be very grateful if you could modify the code!

Btw:  
I have 2 of these relays:

> **[WIFI D1 mini - shield contact Relais](https://opencircuit.nl/Product/WIFI-D1-mini-shield-contact-Relais)**
>
> Deze relais module is compatibel met de Wemos D1 Mini en wordt geleverd met 2 1x8 male header, 2 1x8 female header en 2 1x8 female stackable header.

  
And two of these Arduino boards:  
[https://opencircuit.nl/Product/WeMos-D1-mini-V3.1-Wifi-Module](https://opencircuit.nl/Product/WeMos-D1-mini-V3.1-Wifi-Module)

And wanted to solder them on this board:  
[https://opencircuit.nl/Product/WeMos-D1-mini-Dual-base-shield](https://opencircuit.nl/Product/WeMos-D1-mini-Dual-base-shield)

But would be great if I could spare a Arduino board!  
Especially because of heat, etc too…

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [January 21, 2020, 3:02pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/7 "2020-01-21T15:02:49Z")

</div>

Rem: please don’t call these boards “Arduino” boards, but ESP8266 or WEMOS (to prevent confusion)

Something like this should probably work. (not tested, don’t have this boards)  
Only the **Toggle** command will start the 2-relay action (‘Toggle’ is not the right naming, 'Itching is used by Sonoff, but also ‘Pulsed’ is used)  
The second relay can be connected to D2.

```
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>

#define RELAY_TIMEOUT 200

int PIN_RELAY1 = D1;
int PIN_RELAY2 = D2;

ESP8266WebServer server(80);
WiFiManager wifiManager;

void setup() {
  
  pinMode(int PIN_RELAY1, OUTPUT);
  relayOff();

  pinMode(int PIN_RELAY2, OUTPUT);
  relay2Off();

  WiFi.hostname("RelayCtrl");
  wifi_station_set_hostname("RelayCtrl");
  
  wifiManager.setConfigPortalTimeout(180);
  wifiManager.autoConnect("RelayCtrl");
  
  if(WiFi.status() != WL_CONNECTED) {
    ESP.restart();
    return;
  }
  
  ArduinoOTA.setPort(80);
  ArduinoOTA.setHostname("RelayCtrl");
  ArduinoOTA.begin();
  
  if (MDNS.begin("RelayCtrl")) {
    MDNS.addService("http", "tcp", 80);
    MDNS.addService("RelayCtrl", "tcp", 80);
  }

  server.on("/on", HTTP_GET, _onHttpRelayOn);
  server.on("/off", HTTP_GET, _onHttpRelayOff);
  server.on("/toggle", HTTP_GET, _onHttpRelayToggle);
  server.begin();
  
}

void loop() {
  server.handleClient();
  ArduinoOTA.handle();
}

void _onHttpRelayOn() {
  relayOn();
  server.send(200);
}

void _onHttpRelayOff() {
  relayOff();
  server.send(200);
}

void _onHttpRelayToggle() {
  relayToggle();
  server.send(200);
}

void relayToggle() {
  relayOn();
  delay(RELAY_TIMEOUT);
  relayOff();
  delay(RELAY_TIMEOUT);
  relay2On();
  delay(RELAY_TIMEOUT);
  relay2Off();
}

void relayOn() {
  digitalWrite(int PIN_RELAY1, HIGH);
}

void relay2On() {
  digitalWrite(int PIN_RELAY2, HIGH);
}

void relayOff() {
  digitalWrite(int PIN_RELAY1, LOW);
}

void relay2Off() {
  digitalWrite(int PIN_RELAY2, LOW);
}
```

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 3:20pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/8 "2020-01-21T15:20:02Z")

</div>

@JPe4619  
Sorry, I program them with the Arduino programmer, that’s why. 🙂

Thanks for the code!  
There’s just another problem then since I don’t know how to connect the second relay to D2. Since this is a platform where you can stack the components, it seems to having be addressed some way on the “bus”?

See

 ![Wemos 1](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/5/75f6e2c0346d2b1094e0bf2177abdbe8ea60ca26.jpeg) ![Wemos 2](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/f/1fdffd74555a7d2e6b29356865effbc6ae4fef3f.jpeg)

I would very much like this approach though, 'cause it seems very much more failsafe than using two webhooks…

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [January 21, 2020, 3:31pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/9 "2020-01-21T15:31:31Z")

</div>

See the backside of the relay, for the second relay you need to remove the ‘D1’ link and add the D2 link.  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/3/93b39a1dc2f10a378bb108444ec21c81ed963d7f.png)

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 3:35pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/10 "2020-01-21T15:35:33Z")

</div>

Ah, that seems simple!  
Thx, much appreciated! I’ll try and keep you posted! 🙂

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 4:07pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/11 "2020-01-21T16:07:54Z")

</div>

Ok @JPe4619, so this is my relay:

 ![Wemos 3](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/b/6b06fa018e8878dab803bcb10e90917c1fd85594.jpeg)

Am I correct that I have to short circuit the red contacts (D1) for the first relay board and shortcut the yellow contacts (D2) on the second relay board?

You wrote “remove the D1 link”. But there is nothing to remove; it’s not already not connected. Is D1 the default perhaps? If so, is this default override on the second board when connecting D2 together? Or do I have to do something else to determine 1st and 2nd relay?

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [January 21, 2020, 4:19pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/12 "2020-01-21T16:19:42Z")

</div>

Good that you are care-full, but as said, for relay 1 there must be a link on D1 and for relay 2 a link on D2, if there are no links, then you don’t have to remove anything ( it’s so simple, that is is hard to believe 😉  
On the product page of the relay, it says:

> Het relais is standaard verbonden met de D1 poort van de Wemos

but that seems not to be true. (There is also not a tiny copper track between the solder points **?** )  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/d/cdd8ee7b0679e9c4b2e0a598c324b13d056df9f6.png)

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 6:17pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/13 "2020-01-21T18:17:41Z")

</div>

@JPe4619  
Well, in fact it is true. According to my multimeter, D1 is connected to each other. It just cannot be seen because of the color/‘paint’ on the board… 🙂

So; all is ready now for flashing the software. Unfortunately I get errors… ☹  
In short: It said:

_relayctrl-2Relays:11:9: error: two or more data types in declaration of ‘PIN\_RELAY1’_

- int int PIN\_RELAY1 = D1;\*  
_relayctrl-2Relays:12:9: error: two or more data types in declaration of ‘PIN\_RELAY2’_
- int int PIN\_RELAY2 = D2;\*

Then I removed 1 of the 2 “int”-s where you define the relays D1 and D2.  
That seemed to help.

But then I get the errors:

_relayctrl-2Relays:19:11: error: expected primary-expression before ‘int’_

- pinMode(int PIN\_RELAY1, OUTPUT);\*  
_relayctrl-2Relays:22:11: error: expected primary-expression before ‘int’_
- pinMode(int PIN\_RELAY2, OUTPUT);\*

I am stuck there…

I’ll send you the error log as a private message. May be too long (and specific) for here…  
Can you help me out once more please?

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [January 21, 2020, 8:04pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/14 "2020-01-21T20:04:40Z")

</div>

Yessss… It works!  
With much, MUCH thanks to @JPe4619.  
Thx Jan for the big help!

Here’s the right, final code.  
Button activation and delay between is both 500ms seconds here. You might wanna experiment with that…

```
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>

#define RELAY_TIMEOUT 500
int PIN_RELAY1 = D1;
int PIN_RELAY2 = D2;

ESP8266WebServer server(80);
WiFiManager wifiManager;

void setup() {

  pinMode(PIN_RELAY1, OUTPUT);
  relayOff();

  pinMode(PIN_RELAY2, OUTPUT);
  relay2Off();

  WiFi.hostname("RelayCtrl");
  wifi_station_set_hostname("RelayCtrl");

  wifiManager.setConfigPortalTimeout(180);
  wifiManager.autoConnect("RelayCtrl");

  if(WiFi.status() != WL_CONNECTED) {
    ESP.restart();    
return;
  }

  ArduinoOTA.setPort(80);
  ArduinoOTA.setHostname("RelayCtrl");
  ArduinoOTA.begin();

  if (MDNS.begin("RelayCtrl")) {
    MDNS.addService("http", "tcp", 80);
    MDNS.addService("RelayCtrl", "tcp", 80);
  }

  server.on("/on", HTTP_GET, _onHttpRelayOn);
  server.on("/off", HTTP_GET, _onHttpRelayOff);
  server.on("/toggle", HTTP_GET, _onHttpRelayToggle);
  server.begin();

}

void loop() {
  server.handleClient();
  ArduinoOTA.handle();
}

void _onHttpRelayOn() {
  relayOn();
  server.send(200);
}

void _onHttpRelayOff() {
  relayOff();
  server.send(200);
}

void _onHttpRelayToggle() {
  relayToggle();
  server.send(200);
}

void relayToggle() {
  relayOn();
  delay(RELAY_TIMEOUT);
  relayOff();
  delay(RELAY_TIMEOUT);
  relay2On();
  delay(RELAY_TIMEOUT);
  relay2Off();
}

void relayOn() {
  digitalWrite(PIN_RELAY1, HIGH);
}

void relay2On() {
  digitalWrite(PIN_RELAY2, HIGH);
}

void relayOff() {
  digitalWrite(PIN_RELAY1, LOW);
}

void relay2Off() {
  digitalWrite(PIN_RELAY2, LOW);
}
```

---

<div class="post-metadata">

**Author:** ![Henk\_Renting](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_renting/32/87634_2.png) [@Henk\_Renting](https://community.homey.app/u/Henk_Renting)\
**Post date:** [February 4, 2020, 4:38pm UTC](https://community.homey.app/t/diy-opening-my-apartment-door-remotely-with-homey/4272/15 "2020-02-04T16:38:14Z")

</div>

This script is now working flawlessly for a few weeks here.  
One addion would be great, but I suspect it is not possible. Still;

Would it be possible for the Wemos (and therefor Homey via i.e. a webhook? ) to sense if a relay contact has been shortcut externally?  
That way it would sense if someone has pressed the doorbell and therefor getting a notification on my mobile (at home or away)
