Using an ESP8266 Dual Relay Combo Board with Home Assistant

Maybe a little late this answer but maybe somewone is in your situation… You need to feed 12v on green port! You have powered the board with 5V but your relays are feeded from green port with 12V! Good luck!

I used a similar relay to modify a doorbell with 2 chimes so that I could disable the chimes. (And also prevent the doorbell from being hammered over and over). Since I found this post I’ll share the code here.

the problem I ran into was sending both commands at the same time would fail one of the commands. So I found a 20ms delay was the sweet spot of both commands actually firing.

The code allows you to press the doorbell once, and then not again for 15 seconds. It also allows you to turn one or both chimes off.

# Enable logging
logger:
  baud_rate: 0 # disable hardware logging due to uart gpio collision

globals:
  - id: chime1_enabled
    type: bool
    restore_value: true
    initial_value: 'true'
  - id: chime2_enabled
    type: bool
    restore_value: true
    initial_value: 'true'
  - id: button_can_activate
    type: bool
    restore_value: false
    initial_value: 'true'

uart:
  id: uart_bus
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 115200

switch:
  - platform: restart
    name: Doorbell Restart

  - platform: template
    name: "Doorbell Chime Relay 1"
    id: relay1
    turn_on_action:
      - uart.write: 
          id: uart_bus
          data: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
      - uart.write: 
          id: uart_bus
          data: [0xA0, 0x01, 0x00, 0xA1]

  - platform: template
    name: "Doorbell Chime Relay 2"
    id: relay2
    turn_on_action:
      - uart.write: 
          id: uart_bus
          data: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
      - uart.write: 
          id: uart_bus
          data: [0xA0, 0x02, 0x00, 0xA2]

  - platform: template
    name: "Enable Chime 1"
    id: enable_chime1
    restore_mode: RESTORE_DEFAULT_ON
    turn_on_action:
      - globals.set:
          id: chime1_enabled
          value: 'true'
    turn_off_action:
      - globals.set:
          id: chime1_enabled
          value: 'false'
    lambda: |-
      return id(chime1_enabled);

  - platform: template
    name: "Enable Chime 2"
    id: enable_chime2
    restore_mode: RESTORE_DEFAULT_ON
    turn_on_action:
      - globals.set:
          id: chime2_enabled
          value: 'true'
    turn_off_action:
      - globals.set:
          id: chime2_enabled
          value: 'false'
    lambda: |-
      return id(chime2_enabled);

binary_sensor:
  - platform: gpio
    id: button
    name: Doorbell Button
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      then:
        - if:
            condition:
              - lambda: 'return id(button_can_activate);'
            then:
              - globals.set:
                  id: button_can_activate
                  value: 'false'
              - if:
                  condition:
                    - lambda: 'return id(chime1_enabled);'
                  then:
                    - switch.turn_on: relay1
              - delay: 20ms # only one will turn on if you send the commands too quickly
              - if:
                  condition:
                    - lambda: 'return id(chime2_enabled);'
                  then:
                    - switch.turn_on: relay2
              - delay: 500ms  # Both relays stay on for this duration
              - switch.turn_off: relay1
              - delay: 20ms # only one will turn off if you send the commands too quickly
              - switch.turn_off: relay2
              - delay: 15s
              - globals.set:
                  id: button_can_activate
                  value: 'true'
1 Like

Read my final post at the end: this board has a problem

Is there a way you guys figure out to debug this.

I have added the pre-amble, with or without the pre-amble the device will turn the relay on, but it wont turn my relay off.

I have another one that is working just fine with no pre-amble, but a new 3 dual channels I set up, I cannot get them to turn the relay off.

They are showing the red light, so they appear to be in the right mode by observation, and that they will turn the relay on.

If I turn the relay 1 on, I can still turn relay 2 on, so it also appears all is fine with the comms. But no matter when I send the turn off command, it doesnt do it. I even tried adding a delay action to turn it off, but the relay light never goes off. Only a full restart of the whole board does it.

I was hoping to try understand why my turn off command is not working.

esphome:
  name: pool-motor-relay1
  friendly_name: Pool Motor Relay1

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "removed"

ota:
  password: "removed"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pool-Motor-Relay1"
    password: "removed"

captive_portal:


uart:
  baud_rate: 115200
  tx_pin: GPIO1
  rx_pin: GPIO3

switch:
  - platform: template
    id: relay1
    name: 'Relay 1'
    turn_on_action:
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x01, 0x01, 0xA2]
      - delay: 10s
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x01, 0x00, 0xA1]
      - switch.turn_off: relay1
    turn_off_action:
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x01, 0x00, 0xA1]
    optimistic: true
    

  - platform: template
    name: 'Relay 2'
    id: relay2
    turn_on_action:
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x02, 0x01, 0xA3]
      - delay: 10s
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x02, 0x00, 0xA2]
      - switch.turn_off: relay2
    turn_off_action:
      - uart.write: [0x0D, 0x0A, 0x2B, 0x49, 0x50, 0x44, 0x2C, 0x30, 0x2C, 0x34, 0x3A, 0xA0, 0x02, 0x00, 0xA2]
    optimistic: true

Here is an upclose of the chip thats on it

Is this a nuvotron?
If so is this the correct manual?

DS_N76E003_EN_Rev1.09.pdf (nuvoton.com)

If so how did you figure out the pre-amble.

Any help welcome

1 Like

I enabled debug on the UART using
uart:
id: uart_bus
baud_rate: 115200
tx_pin: GPIO1
rx_pin: GPIO3
debug:
direction: BOTH
dummy_receiver: true
after:
bytes: 150
sequence:
- lambda: UARTDebug::log_string(direction, bytes);

when i enable dummy receiver, the logs of full of AT+RST.
Whether something else is making that or the chip attached, I am nto sure.

See below for an example

[20:28:07][D][switch:055]: 'Relay 1': Sending state OFF
[20:28:07][D][uart_debug:158]: >>> "\xA0\x01\x00\xA1"
[20:28:07][D][switch:012]: 'Relay 1' Turning ON.
[20:28:07][D][switch:055]: 'Relay 1': Sending state ON
[20:28:07][D][uart_debug:158]: >>> "\xA0\x01\x01\xA2"
[20:28:07][D][switch:016]: 'Relay 1' Turning OFF.
[20:28:07][D][switch:055]: 'Relay 1': Sending state OFF
[20:28:07][D][uart_debug:158]: >>> "\xA0\x01\x00\xA1"
[20:28:08][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:09][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:10][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:11][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:12][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:13][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:14][D][uart_debug:158]: <<< "AT+RST\r\n"
[20:28:15][D][uart_debug:158]: <<< "AT+RST\r\n"

So in the end, after looking at some working boards of mine (after removing them from service) and comparing this to the non working board. It seems the same supplier had sent me two different kinds. Some of them are labelled besstep exaclt where you see “LC” on the top picture of the first poster.

I ordered from another supplier, and all sorted. So much time wasted on what appears to be cheap nonsense. But now at least I have a few ESP-01 spares

Maybe a little late, but this one also works pretty well with ESPHome

I have also a relay board like this and it is working already .
I can control the two relays on the board(thx to this forum) , but what about the LEDs and switches (S1 and S2) on the board . Is it possible to intergrate them also in the programm ?
So when pushing the buttons, i can switch the relays manually

Hi,

I might be having the same issue: I can turn both relays on, but I cannot turn them off. What gave you the clue of searching for another board? And if you did so, which board did you eventually purchase?

Thanks in advance,
Erwin

Edit:
Hah, my new boards arrived, but it again was from the “bestep” brand. I gave it a second try and hooray :slight_smile:

This is my working config:

esphome:
  name: verlichtinggarage
  platform: ESP8266
  board: esp01_1m

uart:
  baud_rate: 115200
  tx_pin: GPIO1
  rx_pin: GPIO3

# Enable logging
logger:
  level: DEBUG 
  baud_rate: 0

status_led:
  pin: GPIO2

switch:
  - platform: template
    name: "relay1"
    optimistic: true
    turn_on_action:
     - uart.write: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
     - uart.write: [0xA0, 0x01, 0x00, 0xA1]

  - platform: template
    name: "relay2"
    optimistic: true
    turn_on_action:
     - uart.write: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
     - uart.write: [0xA0, 0x02, 0x00, 0xA2]

Btw, I found some mixed documentation on how to flash the ESP-01. For those that are looking on more info on how to flash the ESP-01, these are my notes:

# RX to TX
# TX to RX
# Gnd to Gnd en D0. D0 is on the same row as GND, but there is 1 pin in between the two.
# 3V VCC to 3V
# 3V VCC to EN

Thanks for being such a great resource :slight_smile:
Erwin

I had the same problems with my cheap clone of this relay, in my case with LPC803AT20 chip.

I could turn relays on by A00101A2 res. A00201A3, but I could not turn them off.
The baud rate and the coms were correct, since I was able to turn on both relays in sequence.
After a lot of time spending on the net without any result I desperately started brute force attack - started typing different commands. And I had luck (or hunch) and it did not took too long.
For reasons beyond my understanding, this chip is not using 0x00 for OFF value but 0x02 !!!

So to properly control the relays one has to use:

Relay 1 ON - 0xA0 0x01 0x01 0xA2
Relay 1 OFF - 0xA0 0x01 0x02 0xA3
Relay 2 ON - 0xA0 0x02 0x01 0xA3
Relay 2 OFF - 0xA0 0x02 0x02 0xA4

1 Like

HI ! I have chip labeled F0010A1T

Please note, board is working in Mode 1 ( RED led is on )

uart:
  baud_rate: 115200
  tx_pin: GPIO1
  rx_pin: GPIO3

binary_sensor:
  - platform: status
    name: "Remote ESP Status"

status_led:
  pin: GPIO2  

switch:
  - platform: template
    name: 'Relay 1'
    id: relay1
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
    optimistic: true
  - platform: template
    name: 'Relay 2'
    id: relay2
    turn_on_action:
      - uart.write: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
    optimistic: true

Thank you for the solution. I spent 6 hours trying to connect the ESP_Relay_x2_V1.2 to ESP-Home. I tried dozens of sketches, but none of them worked. I didn’t want to throw it away since the module is very compact. I’m glad I found a working solution here.

Do you know how to prevent relays from triggering on boot after a power loss?