4 channel Relay ESP8266 Wifi board WORKING with esphome

Great, glad you’re sorted.

I have some troubles, have 2 relay version using to control covers with time based cover component, the problem is randomly the relay stay on forever.
Please help me, thanks!

my code:

substitutions:
  devicename: "esp_tappsala"
  relay1: "tappsala_r1"
  relay2: "tappsala_r2"

esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m
  build_path: build/tappcontrol


wifi:
  ssid: "IoT"
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Dual Relay 5V Fallback Hotspot"
    password: ""

captive_portal:

# Enable logging
logger:
  baud_rate: 0 #need this to free up UART pins


# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

  
# Enable Web server.
web_server:
  port: 80
  
time:
  - platform: homeassistant
    id: homeassistant_time

# Text sensors with general information.
text_sensor:
  # Expose ESPHome version as sensor.
  - platform: version
    name: $devicename Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: $devicename IP
    bssid:
      name: $devicename BSSID

# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: $devicename Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: $devicename WiFi Signal
    update_interval: 60s


uart:
  baud_rate: 115200 # speed to Nuvoton MCU
  tx_pin: GPIO1
  rx_pin: GPIO3

cover:
  - platform: time_based
    name: "$devicename Cover"

    open_action:
      - switch.turn_off: $relay2
      - switch.turn_on: $relay1
    open_duration: 1min

    close_action:
      - switch.turn_off: $relay1
      - switch.turn_on: $relay2
    close_duration: 1min

    stop_action:
      - switch.turn_off: $relay1
      - switch.turn_off: $relay2

switch:
  - platform: template
    name: '$devicename 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: '$devicename Relay 2'
    id: $relay2
    turn_on_action:
      - uart.write: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
    optimistic: true

1 Like

Solved by myself

added a delay:

cover:
  - platform: time_based
    name: "$devicename Cover"

    open_action:
      - switch.turn_off: $relay2
      - delay: 100ms
      - switch.turn_on: $relay1
    open_duration: 17s

    close_action:
      - switch.turn_off: $relay1
      - delay: 100ms
      - switch.turn_on: $relay2
    close_duration: 17s

    stop_action:
      - switch.turn_off: $relay1
      - delay: 100ms
      - switch.turn_off: $relay2

3 Likes

Thanks for posting your code. I only have a single relay board with the same uart switch. I wanted an automation to turn off a burglar alarm “bell” at the regulated maximum duration for such alarms. Also wanted to do it in the relay rather than depend on the Home Assistant server connection.
Once the indents in the yaml file were fixed after I copy-pasted ( and edited for my use) your code all was good.
Thanks again

is there anyone that is using or has a compiled script where the 4 channel relay board is using MQTT also ?

Esphome has mqtt support.

1 Like

Thanks Nick,

i have tried espeasy various versions to flash on the but most of them are comin into a bootloop sort of thing when i look at serial monitor.
Then i got wespota thats mentioned here as well but this also comes sometimes in bootloop, when it says connect to NAMESSID and go to 192.168.4.1 to setup.
Most of the times this works and then after changing settings its back to this again.
not sure what im missing here.

I think ive been busy from this morning till now thats about 11 hours in a row and no working version.
Starting to give up for today then.

Edit: https://1drv.ms/u/s!AiCUo623KJBvhIBoRgZdRK7ti5I0Bg?e=GW2D0P
thats a video i made with the out of the box Wespota version.

Many boards look the same but behave differently. Some boards use a uart/serial method to turn the relays on/off. Others use a GPIO per relay.

Trouble is, there are as many implementations as there are electronics manufacturers in China.

1 Like

Well i took the time again to try and see if i get it running.
I have installed the Wespota fork on the esp, after pressing several of the buttons on the relay board it suddenly started working.
So for the people that want to have this fork software, here you can download it :
Wespota with LCrelay support out of the box.

It should stay online, have it on my onedrive account.
If its gone, drop me a message…

Only thing i am trying to figure out is the CMD for controlling the relays by mqtt.

I got the same lctech relay x2, but that configuration does not turn on my relays. Please help, is there any other command maybe? Mine has STM8S103, and I’ve tried both baud rate 9600 and 115200.
Oh, nevermind. I got a faulty board. This config works by the way:

logger:
  baud_rate: 0 #need this to free up UART pins  

uart:
  baud_rate: 115200
  tx_pin: GPIO1
  rx_pin: GPIO3

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

Hi, I have the same problem with a non-functionnal single relay ESP01 board
How did you manage to make it works ?

Awesome! Thanks Nico!
Finally got my LC Tech 1 channel relay module integrated into Home Assistant/ESP Home… working!
All i had to do is change the baud_rate to 9600 to be able to communicate with the onboard STC15F104W processor mounted on the 1 channel versions sold by AZ Delivery.de (btw i recommend this HQ shop on Amazon to everyone in Europe!)
Additionally i 've deleted the unneeded lines for the other (unexciting) relays and renamed the “restart”.
i was even able to do that ‘update’ OTA after initially flashing the ESP8266 with ESPhome-flasher, off course :wink: And previously i 've updated the firmware of the ESP but that’s not mandatory.

i assume the same can be done for the 2 relay module.
Maybe someone can confirm the needed baud-rate for that version.

hi ,
i have some of this x4 relais boards.
i flashed one with esphome, and it works…
and i have one working without flashing it, with the command line and an echo:

#switches
- platform: command_line
  switches:
    switch1:
      command_on: /bin/echo -en "\xA0\x01\x01\xA2" | nc 192.168.1.25 8080
      command_off: /bin/echo -en "\xA0\x01\x00\xA1" | nc 192.168.1.25 8080
    switch2:
      command_on: /bin/echo -en "\xA0\x02\x01\xA3" | nc 192.168.1.25 8080
      command_off: /bin/echo -en "\xA0\x02\x00\xA2" | nc 192.168.1.25 8080
    switch3:
      command_on: /bin/echo -en "\xA0\x03\x01\xA4" | nc 192.168.1.25 8080
      command_off: /bin/echo -en "\xA0\x03\x00\xA3" | nc 192.168.1.25 8080
    switch4:
      command_on: /bin/echo -en "\xA0\x04\x01\xA5" | nc 192.168.1.25 8080
      command_off: /bin/echo -en "\xA0\x04\x00\xA4" | nc 192.168.1.25 8080

hope this can help.

2 Likes

I ask a question concerning uart … with those devices the relays are controlled by uart commands … now if I want to use an esp01 to send uart commands to an arduino nano, I state that I already have the assembled hardware that I used with another firmware, how can I replicate an Arduino sketch that reads those RAW commands … I tried some codes, but sending a single character and not a raw code, but my Arduino sketch doesn’t seem to work well because if the esp01 restarts since it performs a logger of all ESPHOME info, arduindo reads in this data as if I were sending the commands for the relay

Thank you for this hint. Previously my board was in mode 2 (blue led on). After reset, it goes to mode 1 (red led on) and is working with HA.

Thanks a lot @all, my ESP-01 with Dual Relay from LC is working now! (5V ESP8266 ESP 01 2 Kanal WiFi Relais Modul 2 Kanal Relais Modul Für IOT Smart Home|Integrated Circuits| - AliExpress)
I was wondering, if the two buttons can be used to controll the relays, is it somehow possible with ESPHome (or another software, if not)?
Do you have any idea, how it can be realized?

Are you talking about those little yellow buttons? If you can work out what gpio they are connected to, yes. Automations and Templates — ESPHome

Thats the big question, I wasn’t able to figure out how they are connected with gpio.

I am struggeling hard with the DualRelay. Tried everything the UART and the GPIO Solution but i will not work. The Board is in the Red-Light-Mode and Green is flashing. I can use the switches from Home Assistant and i see the Blue-Light flashing while i press the Buttons in HA but the Relays won’t toggle…

I tried both Baudrates. It is the ESP-01 with STM8S103 Board.

esphome:
  name: esprelay
  platform: ESP8266
  board: esp01

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pass

captive_portal:

# Enable Home Assistant API
api:
  password: !secret password

logger:
  baud_rate: 0 #need this to free up UART pins  

uart:
  baud_rate: 115200
  tx_pin: GPIO1
  rx_pin: GPIO3

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
1 Like

Is it necessary to desoildering the R2 and some other hardware tweaks?