Esp01 relay LC tech esphome issue

Hi I am trying to get ESP01 1ch relay working (marked as LC tech v 2.3. like this one (optically) ) I have tried almost every single example (and its combinations) to get working.

I have integration in home assistant, device is auto-discovered and switch is there. When I switch it a little blue LED on esp01 flashes for a very short time.

I tried to connect uart serial to pins TX RX pins on the relay board and on serial I seen strange characters when i toggle the switch in home assistant.

I found that relay board has nuvoton ms51fb9ae chip.

I have tried several baud_rate settings: 9600, 19200, and 115200 nothing works. Can you please help me, I am lost.

Thank you

This is my esphome config:


esphome:
  name: pc_remote
  platform: ESP8266
  board: esp01_1m

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

# Enable Home Assistant API
api:

captive_portal:

logger:
  baud_rate: 0

ota:

uart:
  baud_rate: 9600
  tx_pin: GPIO1
  rx_pin: GPIO3

switch:
  - platform: template
    name: 'Relay 1'
    id: relay1
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
      - delay: 300ms
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
      - delay: 300ms
      - 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, thanks to the home-assistant community, read a lot of threads and I found my issues.

Firstly, I forgot that my relay board is 12VDC and I was powering it thought USB 5VDC so esp-01 whole whole board was working except relays was not switching.

Another issue was that not pressed S2 button. To do this I turned off relay board, removed esp01, press and hold s2 button then turn board on and hold until blue led comes red. Then I powered off the board and put esp01 back and turned on. (there might be the other manual for that but this worked for me).

This is my working config:

substitutions:
  # Modify variables based on your settings
  hostname: "esprelay-rekuperacia-v2"
  devicename: esprelay-rekuperacia-v2

esphome:
  name: ${devicename}
  platform: ESP8266
  board: esp01_1m

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

captive_portal:

# Enable Home Assistant API
api:
  password: "XXX"

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: 'Rekuperacia heating'
    id: rekuperacia_heating
    turn_on_action:
      # turn on hvac
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
      - delay: 100ms
      - lambda: id(rekuperacia_on).publish_state(true);
      # turn on heating
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
      - delay: 100ms
      - lambda: id(rekuperacia_heating).publish_state(true);
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
      - delay: 100ms
      - lambda: id(rekuperacia_heating).publish_state(false);
    optimistic: false

  - platform: template
    name: 'Rekuperacia boost'
    id: rekuperacia_boost
    turn_on_action:
      # turn on hvac
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
      - delay: 100ms
      - lambda: id(rekuperacia_on).publish_state(true);
      # turn on boost
      - uart.write: [0xA0, 0x02, 0x01, 0xA3]
      - delay: 100ms
      - lambda: id(rekuperacia_boost).publish_state(true);
      # turn of mode 2
      - uart.write: [0xA0, 0x03, 0x00, 0xA3]
      - delay: 100ms
      - lambda: id(rekuperacia_mode2).publish_state(false);
    turn_off_action:
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
      - delay: 100ms
      - lambda: id(rekuperacia_boost).publish_state(false);
    optimistic: false

  - platform: template
    name: 'Rekuperacia mode 2'
    id: rekuperacia_mode2
    turn_on_action:
      # turn on hvac
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
      - delay: 100ms
      - lambda: id(rekuperacia_on).publish_state(true);
      # turn on mode 2
      - uart.write: [0xA0, 0x03, 0x01, 0xA4]
      - delay: 100ms
      - lambda: id(rekuperacia_mode2).publish_state(true);
      # turn off boost
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
      - delay: 100ms
      - lambda: id(rekuperacia_boost).publish_state(false);
    turn_off_action:
      - uart.write: [0xA0, 0x03, 0x00, 0xA3]
      - delay: 100ms
      - lambda: id(rekuperacia_mode2).publish_state(false);
    optimistic: false

  - platform: template
    name: 'Rekuperacia ON'
    id: rekuperacia_on
    turn_on_action:
      # turn on hvac
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
      - delay: 100ms
      - lambda: id(rekuperacia_on).publish_state(true);
    turn_off_action:
      # turn off heating
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
      - delay: 100ms
      - lambda: id(rekuperacia_heating).publish_state(false);
      # turn off boost
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
      - delay: 100ms
      - lambda: id(rekuperacia_boost).publish_state(false);
      # turn off mode 2
      - uart.write: [0xA0, 0x03, 0x00, 0xA3]
      - delay: 100ms
      - lambda: id(rekuperacia_mode2).publish_state(false);
      # turn off hvac
      - uart.write: [0xA0, 0x04, 0x00, 0xA4]
      - delay: 100ms
      - lambda: id(rekuperacia_on).publish_state(false);
    optimistic: false

sensor:
  - platform: wifi_signal
    name: ${devicename} wifi signal
    update_interval: 600s

  # human readable uptime sensor output to the text sensor above
  - platform: uptime
    name: ${devicename} Uptime in Seconds
    id: uptime_sensor_secs
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor_secs).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
              ).c_str();

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

  # human readable update text sensor from sensor:uptime
  - platform: template
    name: Uptime Human Readable
    id: uptime_human
    icon: mdi:clock-start

A couple notes:

  • This is config for 4ch relay, it controls HVAC with preheating, so there are multiple commands for each switch.

  • I am not using
    optimistic: true becuase it told to home-assistant that state was changed before completed which caused a bug. I used - lambda: id(rekuperacia_on).publish_state(false); to control state change manually.

  • Reason why I am sending uart.write instead of switch.turn_on: swichname it is becuase it didn’t worked with lambda publish_state.

  • Delay between commands. Minimum which I used is 100ms, maybe lower number is possible, theoretically a couple ms should be fine, but I didn’t have time to try different settings. Please let me know what was your minimum.

1 Like