[DIY] Opening my apartment door remotely with Homey

Hello !

I’ve done the DIY from Athom here opening-apartments-door-remotely-homey

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

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” 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):

My interfone model is Niko 10-505:

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

Any idea ?

Thanks,

Julien

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?

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

KIT

I have managed it too. It’s very doable!
(cheap Wemos products are sold here too: 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…

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

@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:


And two of these Arduino boards:
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

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

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);
}

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

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

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

See the backside of the relay, for the second relay you need to remove the ‘D1’ link and add the D2 link.
image

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

1 Like

Ok @JPe4619, so this is my relay:

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?

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 :wink:
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

@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… :slight_smile:

So; all is ready now for flashing the software. Unfortunately I get errors… :frowning:
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?

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);
}
1 Like

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)