Arduino or ESP8266?

I would like to controll 4-5 relais from homey. I thought do this with shelly prodcuts but then all these Shelly 1 are also added in my Googlehome and it will be a very bullky system. These relais are used for controlling a 24V magnetic lock and some led signal lights. So i know arduino can be used for this or ESP8266? Who could help me what unit i would need and a tutorial how to connect this to homey? I was thinking of this module:

Any tips or step by step tutorial is appriciated.

Found Homeyduino Relay met Google Assistent ondersteuning - Huisvanvandaag.nl gevonden… What is the code for more relays?

Found my idea at: [HOWTO] BUVA Boxstream Mechanical ventilation hack Maybe that is already working for you. (Thanks to Niels De Klerk)

Made some adaptions for this module :slight_smile:

HomeyDuino can only control 1 switch per device, therefore I used an alternative control methode.
Can be easy controlled in a flowcard by:

image

You have to flash new firmware into the ESP8266

Thanks for the info. How do you program this module? You connect it trough the GPIO pins to an anduino? and what firmware do you need to flash? With these webhooks there is no return signal? So Homey does not know of it succeded or what state the relay is in? If the relay state in also visable in homey i can create new flows depending on the on or off state of the relay

For programming the ESP-01, I use a device like this:

Be aware that GPIO-0 has to be grounded while power-up for programming.
The Arduino-IDE can be used for programming this device.

There is no relay-state feed-back, but you can set or reset a boolean-logic-variable at the same time as you set or reset the relay and use that as an index for the relay-state. Or make a Virtual device (switch) for this, to make it visible.

You have to insert your SSID and Password(router) in the code and the preferred IP-address of the relay-board.

File for credentials, named: MyCredentials.h (placed in the same directory as source-file)

/************** 
     My Credentials  // 
#include "MyCredentials.h" 
************/

//my network credentials
const char* ssid     = "your-modem-router-SSID";
const char* password = "your-modem-route-password";

// Static IP address
IPAddress local_IP(192, 168, 2, 80); // change to your wanted device-IP

// Gateway IP address
IPAddress gateway(192, 168, 2, 254); // change to your modem-routerIP
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

source-file for four relay-board X4, named: FourRelay.ino

/* Remote for ESP8266 Relay-X4 module */
/* From origin Niels De Klerk https://community.homey.app/t/howto-buva-boxstream-mechanical-ventilation-hack/7596 */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include "MyCredentials.h"

//#ifndef STASSID
//#define STASSID "MY SSID"
//#define STAPSK  "MY PASSWORD"
//#endif

//const char* ssid = STASSID;     //done by #include "MyCredentials.h"
//const char* password = STAPSK;  //done by #include "MyCredentials.h"

byte rel1ON[] = {0xA0, 0x01, 0x01, 0xA2};  //Hex command to send to serial for open relay-1
byte rel1OFF[] = {0xA0, 0x01, 0x00, 0xA1}; //Hex command to send to serial for close relay-1

byte rel2ON[] = {0xA0, 0x02, 0x01, 0xA3};  //Hex command to send to serial for open relay-2
byte rel2OFF[] = {0xA0, 0x02, 0x00, 0xA2}; //Hex command to send to serial for close relay-2

byte rel3ON[] = {0xA0, 0x03, 0x01, 0xA4};  //Hex command to send to serial for open relay-3
byte rel3OFF[] = {0xA0, 0x03, 0x00, 0xA3}; //Hex command to send to serial for close relay-3

byte rel4ON[] = {0xA0, 0x04, 0x01, 0xA5};  //Hex command to send to serial for open relay-4
byte rel4OFF[] = {0xA0, 0x04, 0x00, 0xA4}; //Hex command to send to serial for close relay-4

//  Flash : GPIO0
//  tx_pin: GPIO1
//  led   : GPIO2
//  rx_pin: GPIO3

ESP8266WebServer server(80);

void httpDefaultResponse() {
  digitalWrite(2, 0);
  server.send(200, "text/html", "<html><head></head><body><b>Relay Control</b><br><br><a href=\"/relay1:on\">Relay-1: ON</a><br><br><a href=\"/relay1:off\">Relay-1: OFF</a><br><br><a href=\"/relay2:on\">Relay-2: ON</a><br><br><a href=\"/relay2:off\">Relay-2: OFF</a><br><br><a href=\"/relay3:on\">Relay-3: ON</a><br><br><a href=\"/relay3:off\">Relay-3: OFF</a><br><br><a href=\"/relay4:on\">Relay-4: ON</a><br><br><a href=\"/relay4:off\">Relay-4: OFF</a></body></html>");

  /*original code Niels De Klerk:  */
  /*server.send(200, "text/html", "<html><head></head><body><b>Control</b><br><br><a href=\"/mode1\">Set Mode: 1</a><br><br><a href=\"/mode2\">Set Mode: 2</a><br><br><a href=\"/mode3\">Set Mode: 3</a><br><br><a href=\"/mode4\">Set Mode: 4</a><br><br><a href=\"/mode5\">Set Mode: 5</a><br><br><a href=\"/mode6\">Set Mode: 6</a></body></html>");
  /*server.send(200, "text/html", "<html><head></head><body><b>Control</b><br><a href=\"/mode1\">Set Mode: 1</a><br><a href=\"/mode2\">Set Mode: 2</a><br><a href=\"/mode3\">Set Mode: 3</a><br><a href=\"/modeT1\">Set Mode: 4 - 1</a><br><a href=\"/modeT2\">Set Mode: 4 -2</a><br><br><br><b>Pairing<b><br>The ventilation motor allows pairing only in the first 10 minutes after getting power.<br>To pair a remote, disconnect the power cable and then reconnect the power cable of the ventilation motor.<br><a href=\"/pairing\">Start pairing.</a></body></html>");
  */
  
  digitalWrite(2, 1);
}

void setup(void) {
  //  pinMode(0, OUTPUT);
  //  digitalWrite(0, 0);
  //  pinMode(1, OUTPUT);
  //  digitalWrite(1, 0);
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
  //  pinMode(3, OUTPUT);
  //  digitalWrite(3, 0);
  //  pinMode(4, OUTPUT);
  //  digitalWrite(4, 1);
  //  pinMode(5, OUTPUT);
  //  digitalWrite(5, 0);
  //  pinMode(6, OUTPUT);
  //  digitalWrite(6, 0);

  Serial.begin(115200);
  // Configures static IP address, defined in [#include "MyCredentials.h"]
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    //Serial.println("STA Failed to configure");
  }
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  //Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    //Serial.print(".");
  }
  //Serial.println("");
  //Serial.print("Connected to ");
  //Serial.println(ssid);
  //Serial.print("IP address: ");
  //Serial.println(WiFi.localIP());
  //digitalWrite(1, 1);
  if (MDNS.begin("esp8266")) {
  //Serial.println("MDNS responder started");
  }

  server.on("/", httpDefaultResponse);

  server.on("/relay1:on", []() {
    httpDefaultResponse();
    Serial.write(rel1ON, sizeof(rel1ON));     // turns the relay ON
  });

  server.on("/relay1:off", []() {
    httpDefaultResponse();
    Serial.write(rel1OFF, sizeof(rel1OFF));     // turns the relay OFF
  });

  server.on("/relay2:on", []() {
    httpDefaultResponse();
    Serial.write(rel2ON, sizeof(rel2ON));     // turns the relay ON
  });

  server.on("/relay2:off", []() {
    httpDefaultResponse();
    Serial.write(rel2OFF, sizeof(rel2OFF));     // turns the relay OFF
  });

  server.on("/relay3:on", []() {
    httpDefaultResponse();
    Serial.write(rel3ON, sizeof(rel3ON));     // turns the relay ON
  });

  server.on("/relay3:off", []() {
    httpDefaultResponse();
    Serial.write(rel3OFF, sizeof(rel3OFF));     // turns the relay OFF
  });

  server.on("/relay4:on", []() {
    httpDefaultResponse();
    Serial.write(rel4ON, sizeof(rel4ON));     // turns the relay ON
  });

  server.on("/relay4:off", []() {
    httpDefaultResponse();
    Serial.write(rel4OFF, sizeof(rel4OFF));     // turns the relay OFF
  });

  server.onNotFound(httpDefaultResponse);

  server.begin();
  //Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  MDNS.update();
} // end loop.

It is also possible to control the relays from a WebBrouwser pointing to the Device-IP
image

Someone should write an ESPHome app for Homey :smiley:

1 Like

How can I control the flashing of the LEDs (D5, D6 and D7) and the pressing of the S1 and S2 buttons?