# Homie/ESP8266 with Relay Modul

**URL:** <https://community.openhab.org/t/homie-esp8266-with-relay-modul/136029>\
**Category:** Development\
**Tags:** openhab2, homie\
**Created:** [May 19, 2022, 11:21am UTC](https://community.openhab.org/t/homie-esp8266-with-relay-modul/136029 "2022-05-19T11:21:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lltodoll](https://community.openhab.org/user_avatar/community.openhab.org/lltodoll/32/89927_2.png) [@lltodoll](https://community.openhab.org/u/lltodoll)\
**Post date:** [May 19, 2022, 11:21am UTC](https://community.openhab.org/t/homie-esp8266-with-relay-modul/136029/1 "2022-05-19T11:21:29Z")

</div>

Hi,

i don’t find a working example. I have flashed the ESP8266 1MB (black version) with Homie via PlatformIO.

I have this relay modul and want to trigger the relay via Openhab. But … i think i use the wrong PIN\_Relay Value?! I must trigger the GPIO0 from ESP.

My Code:

```auto
#include <Homie.h>

static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
static const uint8_t D7 = 13;
static const uint8_t D8 = 15;
static const uint8_t RX = 3;
static const uint8_t TX = 1;

#define firmwareVersion "1.0.0"

static const uint8_t PIN_RELAY = D0;

HomieNode lightNode("light", "Light", "switch");

bool lightOnHandler(const HomieRange& range, const String& value) {
  if (value != "true" && value != "false") return false;

    bool on = (value == "true");
    digitalWrite(PIN_RELAY, on ? HIGH : LOW);
    lightNode.setProperty("on").send(value);
    Homie.getLogger() << "Light is " << (on ? "on" : "off") << endl;

    return true;
}

void setup() {
  Serial.begin(115200);
  Serial << endl << endl;

  pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_RELAY, LOW);

  Homie_setFirmware("awesome-relay", firmwareVersion);

  lightNode.advertise("on").setName("On").setDatatype("boolean").settable(lightOnHandler);

  Homie.setup();
}

void loop() {
  Homie.loop();
}

```

Can anyone help me?

 ![WIFI-Relay-Module-B-2](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/1/f/1fb86a3d4d18819f2772f16a00dfc65e3196d838.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/6/6a52f2ac5d00e4c7b50471a354b3a9221188be90.png) [@system](https://community.openhab.org/u/system)\
**Post date:** [June 30, 2022, 4:55am UTC](https://community.openhab.org/t/homie-esp8266-with-relay-modul/136029/3 "2022-06-30T04:55:32Z")

</div>

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