Wifi Relay Integrated Chip

Hey,

I just bought a chip on ebay that has a ESP8622 integrated with a relay from a company named Yunshan. It looks like a really good piece of technology to have because you can cheaply automate the lights on your house.

However, I went through the documentation and the internet and I have no clue how to make it work. Does anyone have ever used one of those?

Pic of the back of the board:

Documentation:
http://www.uctronics.com/download/U4648-datasheet.zip

I think I saw this same board over on the ESPeasy website (http://www.esp8266.nu). If you find out what pin the relay is on, and drop ESPeasy on it, it should be pretty easy from there.

i would try the itead sonoffs. there are a few people on here that are using them, and are about USD4 each, simply flash https://github.com/arendst/Sonoff-MQTT-OTA-Arduino onto it and integrate it all via MQTT into HA.

otherwise, these look good if you want a NC or NO contact.

I have got it working. Not tried to reprogramme it but can control the relay from another 8266 over wifi

John

OK now reprogrammed it using Arduino IDE to get my own stuff in to get rid of the Chinese

John,

I have ordered 3 of these so far, and I can’t get them to boot. how did you do it?

I have one of these Modules. I use arendst’s sonnoff-tasmota firmware.
I got it working by modding the template file and adding it in as YUNSHAN_RELAY ( although I added an extra pin definition for a DS18b20). To program it you need to short the boot pins, I found this Blynking an IoT Yunshan ESP8266 250V 10A AC/DC WIFI Network Relay Module Blog post really helpful

Here is the changed 0.4.0.3 sonoff_template.h

/*********************************************************************************************\
 * Template parameters
\*********************************************************************************************/

// User selectable GPIO functionality
enum upins_t {
  GPIO_NONE,           // Not used
  GPIO_DHT11,          // DHT11
  GPIO_DHT21,          // DHT21, AM2301
  GPIO_DHT22,          // DHT22, AM2302, AM2321
  GPIO_DSB,            // Single wire DS18B20 or DS18S20
  GPIO_I2C_SCL,        // I2C SCL
  GPIO_I2C_SDA,        // I2C SDA
  GPIO_WS2812,         // WS2812 Led string
  GPIO_IRSEND,         // IR remote
  GPIO_SWT1,           // User connected external switches
  GPIO_SWT2,
  GPIO_SWT3,
  GPIO_SWT4,
  GPIO_KEY1,           // Button usually connected to GPIO0
  GPIO_KEY2,
  GPIO_KEY3,
  GPIO_KEY4,
  GPIO_REL1,           // Relays
  GPIO_REL2,
  GPIO_REL3,
  GPIO_REL4,
  GPIO_REL1_INV,
  GPIO_REL2_INV,
  GPIO_REL3_INV,
  GPIO_REL4_INV,
  GPIO_LED1,           // Leds
  GPIO_LED2,
  GPIO_LED3,
  GPIO_LED4,
  GPIO_LED1_INV,
  GPIO_LED2_INV,
  GPIO_LED3_INV,
  GPIO_LED4_INV,
  GPIO_SENSOR_END };

// Text in webpage Module Parameters and commands GPIOS and GPIO
const char sensors[GPIO_SENSOR_END][9] PROGMEM = {
  "None",
  "DHT11",
  "AM2301",
  "DHT22",
  "DS18x20",
  "I2C SCL",
  "I2C SDA",
  "WS2812",
  "IRremote",
  "Switch1",
  "Switch2",
  "Switch3",
  "Switch4",
  "Button1",
  "Button2",
  "Button3",
  "Button4",
  "Relay1",
  "Relay2",
  "Relay3",
  "Relay4",
  "Relay1I",
  "Relay2I",
  "Relay3I",
  "Relay4I",
  "Led1",
  "Led2",
  "Led3",
  "Led4",
  "Led1I",
  "Led2I",
  "Led3I",
  "Led4I"
  };

// Programmer selectable GPIO functionality offset by user selectable GPIOs
enum fpins_t {
  GPIO_PWM0 = GPIO_SENSOR_END,  // Cold
  GPIO_PWM1,           // Warm
  GPIO_PWM2,           // Red (swapped with Blue from original)
  GPIO_PWM3,           // Green
  GPIO_PWM4,           // Blue (swapped with Red from original)
  GPIO_RXD,            // Serial interface
  GPIO_TXD,            // Serial interface
  GPIO_HLW_SEL,        // HLW8012 Sel output (Sonoff Pow)
  GPIO_HLW_CF1,        // HLW8012 CF1 voltage / current (Sonoff Pow)
  GPIO_HLW_CF,         // HLW8012 CF power (Sonoff Pow)
  GPIO_USER,           // User configurable
  GPIO_MAX };

/********************************************************************************************/

// Supported hardware modules
enum module_t {
  SONOFF_BASIC,
  SONOFF_RF,
  SONOFF_SV,
  SONOFF_TH,
  SONOFF_DUAL,
  SONOFF_POW,
  SONOFF_4CH,
  S20,
  SLAMPHER,
  SONOFF_TOUCH,
  SONOFF_LED,
  CH1,
  CH4,
  MOTOR,
  ELECTRODRAGON,
  EXS_RELAY,
  WION,
  WEMOS,
  YUNSHAN_RELAY,
  USER_TEST,
  MAXMODULE };

/********************************************************************************************/

#define MAX_GPIO_PIN       17   // Number of supported GPIO

typedef struct MYIO {
  uint8_t      io[MAX_GPIO_PIN];
} myio;

typedef struct MYTMPLT {
  char         name[16];
  myio         gp;
} mytmplt;

// Default module settings
const mytmplt modules[MAXMODULE] PROGMEM = {
  { "Sonoff Basic",    // Sonoff Basic (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     0,                // GPIO02
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     0,                // GPIO05
     0,                // GPIO06 (SD_CLK   Flash)
     0,                // GPIO07 (SD_DATA0 Flash QIO/DIO/DOUT)
     0,                // GPIO08 (SD_DATA1 Flash QIO/DIO)
     0,                // GPIO09 (SD_DATA2 Flash QIO)
     0,                // GPIO10 (SD_DATA3 Flash QIO)
     0,                // GPIO11 (SD_CMD   Flash)
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     GPIO_USER,        // GPIO14 Optional sensor
     0,                // GPIO15
     0                 // GPIO16
  },
  { "Sonoff RF",       // Sonoff RF (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     0,
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     GPIO_USER,        // GPIO14 Optional sensor
     0, 0
  },
  { "Sonoff SV",       // Sonoff SV (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     0,
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     GPIO_USER,        // GPIO05 Optional sensor
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     GPIO_USER,        // GPIO14 Optional sensor
     0, 0
  },
  { "Sonoff TH",       // Sonoff TH10/16 (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     0,
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     GPIO_USER,        // GPIO14 Optional sensor
     0, 0
  },
  { "Sonoff Dual",     // Sonoff Dual (ESP8266)
     0,
     GPIO_TXD,         // GPIO01 Relay control
     0,
     GPIO_RXD,         // GPIO03 Relay control
     GPIO_USER,        // GPIO04 Optional sensor
     0,
     0, 0, 0, 0, 0, 0, // Flash connection
     0,
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "Sonoff Pow",      // Sonoff Pow (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0,
     GPIO_HLW_SEL,     // GPIO05 HLW8012 Sel output
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_HLW_CF1,     // GPIO13 HLW8012 CF1 voltage / current
     GPIO_HLW_CF,      // GPIO14 HLW8012 CF power
     GPIO_LED1,        // GPIO15 Green Led (0 = On, 1 = Off)
     0
  },
  { "Sonoff 4CH",      // Sonoff 4CH (ESP8285)
     GPIO_KEY1,        // GPIO00 Button 1
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     GPIO_USER,        // GPIO02 Optional sensor
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_REL3,        // GPIO04 Sonoff 4CH Red Led and Relay 3 (0 = Off, 1 = On)
     GPIO_REL2,        // GPIO05 Sonoff 4CH Red Led and Relay 2 (0 = Off, 1 = On)
     0, 0, 0,          // Flash connection
     GPIO_KEY2,        // GPIO09 Button 2
     GPIO_KEY3,        // GPIO10 Button 3
     0,
     GPIO_REL1,        // GPIO12 Red Led and Relay 1 (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     GPIO_KEY4,        // GPIO14 Button 4
     GPIO_REL4,        // GPIO15 Red Led and Relay 4 (0 = Off, 1 = On)
     0
  },
  { "S20 Socket",      // S20 Smart Socket (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "Slampher",        // Slampher (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "Sonoff Touch",    // Sonoff Touch (ESP8285)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0, 0,
     0, 0, 0,          // Flash connection
     0, 0, 0,
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "Sonoff LED",      // Sonoff LED (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0,
     GPIO_USER,        // GPIO04 Optional sensor (PWM3 Green)
     GPIO_USER,        // GPIO05 Optional sensor (PWM2 Red)
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_PWM0,        // GPIO12 Cold light
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     GPIO_PWM1,        // GPIO14 Warm light
     GPIO_USER,        // GPIO15 Optional sensor (PWM4 Blue)
     0
  },
  { "1 Channel",       // 1 Channel Inching/Latching Relay using (PSA-B01 - ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "4 Channel",       // 4 Channel Inching/Latching Relays
     0,
     GPIO_TXD,         // GPIO01 Relay control
     0,
     GPIO_RXD,         // GPIO03 Relay control
     0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     0,
     GPIO_LED1_INV,    // GPIO13 Blue Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "Motor C/AC",      // Motor Clockwise / Anti clockwise (PSA-B01 - ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     0, 0, 0
  },
  { "ElectroDragon",   // ElectroDragon IoT Relay Board (ESP8266)
     GPIO_KEY2,        // GPIO00 Button 2
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     GPIO_KEY1,        // GPIO02 Button 1
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL2,        // GPIO12 Red Led and Relay 2 (0 = Off, 1 = On)
     GPIO_REL1,        // GPIO13 Red Led and Relay 1 (0 = Off, 1 = On)
     GPIO_USER,        // GPIO14 Optional sensor
     0,
     GPIO_LED1         // GPIO16 Green/Blue Led (1 = On, 0 = Off)
  },
  { "EXS Relay",       // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
                       //   Module Pin 1 VCC 3V3, Module Pin 6 GND
     GPIO_KEY1,        // GPIO00 Module Pin 8 - Button (firmware flash)
     GPIO_USER,        // GPIO01 Module Pin 2 = UART0_TXD
     GPIO_USER,        // GPIO02 Module Pin 7
     GPIO_USER,        // GPIO03 Module Pin 3 = UART0_RXD
     GPIO_USER,        // GPIO04 Module Pin 10
     GPIO_USER,        // GPIO05 Module Pin 9
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Relay1 ( 1 = Off)
     GPIO_REL2,        // GPIO13 Relay1 ( 1 = On)
     GPIO_USER,        // GPIO14 Module Pin 5
     0,
     GPIO_USER         // GPIO16 Module Pin 4
  },
  { "WiOn",            // Indoor Tap https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w (ESP8266)
     GPIO_USER,        // GPIO00 Optional sensor (pm clock)
     0,
     GPIO_LED1,        // GPIO02 Green Led (1 = On, 0 = Off)
     0, 0, 0,
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_USER,        // GPIO12 Optional sensor (pm data)
     GPIO_KEY1,        // GPIO13 Button
     0,
     GPIO_REL1,        // GPIO15 Relay (0 = Off, 1 = On)
     0
  },
  { "WeMos D1 mini",   // WeMos and NodeMCU hardware (ESP8266)
     GPIO_USER,        // GPIO00 D3 Wemos Button Shield
     GPIO_USER,        // GPIO01 TX Serial RXD
     GPIO_USER,        // GPIO02 D4 Wemos DHT Shield
     GPIO_USER,        // GPIO03 RX Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 D2 Wemos I2C SDA
     GPIO_USER,        // GPIO05 D1 Wemos I2C SCL / Wemos Relay Shield (0 = Off, 1 = On) / Wemos WS2812B RGB led Shield
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_USER,        // GPIO12 D6
     GPIO_USER,        // GPIO13 D7
     GPIO_USER,        // GPIO14 D5
     GPIO_USER,        // GPIO15 D8
     GPIO_USER         // GPIO16 D0 Wemos Wake
  },
  { "Yunshan Relay",       // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31
                       //   Module Pin 1 VCC 3V3, Module Pin 6 GND
     0,        // GPIO00 Module Pin 8 - Button (firmware flash)
     0,                // GPIO01 Module Pin 2 = UART0_TXD
     GPIO_LED1_INV,        // GPIO02 Module Pin 7
     0,        // GPIO03 Module Pin 3 = UART0_RXD
     GPIO_REL1,        // GPIO04 Module Pin 10
     GPIO_KEY1,        // GPIO05 Module Pin 9
     0, 0, 0, 0, 0, 0,
     0,        // GPIO12 Relay1 ( 1 = Off)
     GPIO_USER,        // GPIO13 Relay1 ( 1 = On)
     0,        // GPIO14 Module Pin 5
     0,        // GPIO15
     0         // GPIO16 Module Pin 4
  },
  { "User Test",       // Sonoff Basic User Test (ESP8266)
     GPIO_KEY1,        // GPIO00 Button
     GPIO_USER,        // GPIO01 Serial RXD and Optional sensor
     GPIO_USER,        // GPIO02 Optional sensor
     GPIO_USER,        // GPIO03 Serial TXD and Optional sensor
     GPIO_USER,        // GPIO04 Optional sensor
     GPIO_USER,        // GPIO05 Optional sensor
     0, 0, 0, 0, 0, 0, // Flash connection
     GPIO_REL1,        // GPIO12 Red Led and Relay (0 = Off, 1 = On)
     GPIO_LED1_INV,    // GPIO13 Green Led (0 = On, 1 = Off)
     GPIO_USER,        // GPIO14 Optional sensor
     0, 0
  }
};
1 Like

Thanks a lot. Working great!
One minor change I had to make to my sources:
In platformio.ini I had to comment out the block for Sonoff Touch. For real Sonoffs I could leave it in and had no problems. But with this device it apparently tried to reflash the other firmware and interrupted while doing that. Now with just the usual Sonoff firmware everything is working great.

PS: How about forking Tasmota and creating a PR so that they can support this device out of the box?

hey, i hav bought this wifi-relay module. can anybody help me how to get started with it?? i would also like to know the hardware connections. any help would be highly appreciated.

I bought mint (HW-622) here ~$4 AUD : [DC 5V-26V ESP8266 ESP-12F Wireless Wifi Relay Module 220V 10A Relay Module ESP12F 802.11b/g/n 2.4GHz 12V 24V]((DC 5V 26V ESP8266 ESP 12F Wireless Wifi Relay Module 220V 10A Relay Module ESP12F 802.11b/g/n 2.4GHz 12V 24V|Relays| - AliExpress)

To flash from HomeESP use this connection:


and it should appear in HA.

I used this config:

esphome:
  name: relaysingle2

esp8266:
  board: esp12e

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "83x2bxxxxxxxx87xxxxxx8"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.0.142
    gateway: 192.168.0.254
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Relaysingle Fallback Hotspot"
    password: "4tVxxxxxxxxtSf"

captive_portal:

# Use the blue LED in the device as a status LED, which will blink if there are warnings (slow) or errors (fast)
status_led:
  pin:
    number: GPIO2
    inverted: True

# One  relay outputs, exposed as switches in Home Assistant
switch:
  - platform: gpio
    pin: GPIO4
    name: "relaysingle2_relay"
    id: relay1

# One sensor input
binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO5
      mode:
        input: true
        pullup: true
    name: "relaysingle2_switch"
    device_class: door
type or paste code here

Then remove the “boot” jumper and serial cable
Add the device IP to ESPHome (I use fixed IP’s)

Next, for me, I connected the external ground to the ESP ground pin and so could see the sensor input working in Home assistant.

May I ask here about the same board…
I flashed it with tasmota (latest) firmware and the relay is working with switch in HA, but I want to use also external button which is connected to 0V on the supply and to the 0V on the signal input (like stated here) The external switch is working, but I want to use it like button because I’ll use the relay as a doorbell integrated into HA.

Question: how to configure Tasmota module to get external button? If I select button instead of switch in module configuration of tasmota webserver, I can’t fire the relay. I used template from the link above.
Anyone knows which GPIO to use for button?

Thank you!!!

See my code above where is says GPIO5 for the button/switch/sensor :slight_smile:

Thanks @Andrew123