4 channel Relay ESP8266 Wifi board WORKING with esphome

# Enable logging
logger:
baud_rate: 0 #need this to free up UART pins
# Enable Home Assistant API
api:

uart:
baud_rate: 115200 # speed to STC15L101EW
tx_pin: GPIO1
rx_pin: GPIO3

switch:

  • platform: uart
    name: “A1on”
    data: [0xA0, 0x01, 0x01, 0xA2]

  • platform: uart
    name: “A1off”
    data: [0xA0, 0x01, 0x00, 0xA1]

  • platform: uart
    name: “A2on”
    data: [0xA0, 0x02, 0x01, 0xA3]

  • platform: uart
    name: “A2off”
    data: [0xA0, 0x02, 0x00, 0xA2]

[18:33:18][C][uart:140]: UART Bus:
[18:33:18][C][uart:142]: TX Pin: GPIO1
[18:33:18][C][uart:145]: RX Pin: GPIO3
[18:33:18][C][uart:147]: Baud Rate: 115200 baud
[18:33:18][C][uart:148]: Stop bits: 1
[18:33:18][C][uart:150]: Using hardware serial interface.
[18:33:18][C][logger:175]: Logger:
[18:33:18][C][logger:176]: Level: DEBUG
[18:33:18][C][logger:177]: Log Baud Rate: 0
[18:33:18][C][logger:178]: Hardware UART: UART0
[18:33:18][C][uart.switch:020]: UART Switch ‘A1on’
[18:33:18][C][uart.switch:020]: UART Switch ‘A1off’
[18:33:18][C][uart.switch:020]: UART Switch ‘A2on’
[18:33:18][C][uart.switch:020]: UART Switch ‘A2off’
[18:33:18][C][captive_portal:169]: Captive Portal:
[18:33:18][C][api:095]: API Server:
[18:33:23][D][switch:021]: ‘A1on’ Turning ON.
[18:33:23][D][switch:045]: ‘A1on’: Sending state ON
[18:33:23][D][uart.switch:016]: ‘A1on’: Sending data…
[18:33:23][D][switch:045]: ‘A1on’: Sending state OFF

2019-12-28 23:56:00 DEBUG (MainThread) [aioesphomeapi.connection] x.x.x.x: Sending <class ‘api_pb2.SwitchCommandRequest’>: key: 391537630
2019-12-28 23:56:00 DEBUG (MainThread) [aioesphomeapi.connection] x.x.x.x: Got message of type <class ‘api_pb2.SwitchStateResponse’>: key: 391537630
2019-12-28 23:56:03 DEBUG (MainThread) [aioesphomeapi.connection] x.x.x.x: Sending <class ‘api_pb2.SwitchCommandRequest’>: key: 391537630
2019-12-28 23:56:03 DEBUG (MainThread) [aioesphomeapi.connection] x.x.x.x: Got message of type <class ‘api_pb2.SwitchStateResponse’>: key: 391537630

So it works totally for some time and then stops? Or doesn’t ever switch the relays at all?

Can you point us to the exact device you are using?

It did work perfectly and now it won’t trigger the relays at all. I was setting it up to control a garage door.

This is what I got.

So I have no Idea what happened. For giggles I powered off the module and ESP-01, held in S2 (reset) and powered up. Now it is fine.

3 Likes

@dubya You do not need to disable the logger to use UART. ESP-01 has 1 UART modes, read the docs. You could set the Logger on UART 1 if you think you are using the Tx & RX pins for UART 0

Here is what I came up with based on the 4 relay module combining works

esphome:
  name: relay_board
  platform: ESP8266
  board: esp01

wifi:
  ssid: "iot"
  password: "Password"

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

captive_portal:


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

ota:
  password: "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: Relay ESPHome Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: Relay IP
    bssid:
      name: Relay BSSID

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

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

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

uart:
  baud_rate: 115200 # speed to STC15L101EW
  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
  - platform: template
    name: 'Relay 3'
    id: relay3
    turn_on_action:
      - uart.write: [0xA0, 0x03, 0x01, 0xA4]
    turn_off_action:
      - uart.write: [0xA0, 0x03, 0x00, 0xA3]
    optimistic: true
  - platform: template
    name: 'Relay 4'
    id: relay4
    turn_on_action:
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
    turn_off_action:
      - uart.write: [0xA0, 0x04, 0x00, 0xA4]
    optimistic: true
7 Likes

Hey everyone,

First of all I would like to say thank you to everyone who worked on this. Great work by all!!!

I purchased the 12v unit from Banggood and the other hardware mentioned by @via2326 . I followed the instructions and flashed the board which worked like a charm. However I was unable to trigger the relays using Home Assistant. Every time I tried the replay wouldn’t switch. However I got it working in the end, using the configuration supplied by @TheDoC . However I should mention that it was only on my second attempt of using the configuration from @TheDoC did everything start working. The only thing I did differently the second time around was after I uploaded the configuration, I powered down the unit, waited about 10 seconds, held down the S2 button and powered on. I continued to hold down the S2 button for about 10 seconds after I powered on the device and now I can hear the relay click when I click the entry in home assistant. Fantastic!

Now i can interface this with the already existing in ground watering system for the grass, which will compliment (or maybe replace) the vegetable garden watering setup that I have working with a 2 x esp32 and the Orbit B-Hyve system.

I should do a post about how I have it all configured, however in a nutshell I have several Xiaomi Mija Flowers And Plants Grass Detectors that are reporting back to Home Assistant with the nutrient, moisture, temperature and light details of the soil. If the soil moisture drops below 25% (why 25%…dunno, everything seems to be growing sweet) then it will turn on the Orbit B-Hyve for 10 mins in the morning.

Now I’ll be able to use the same trick but turn on the in ground watering system for the lawn. Awesome!

2 Likes

Ok, finally got it working… Should have read comments more carefully and use @TheDoC settings right away. For flashing I used instructions on this link: Flashing_instructions Flashing sw I used, ESPHome-Flasher.

Difference to instructions was that on my case, GPIO0 has to be “low” all time during flashing.
Below the code I used:


captive_portal:

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

uart:
  baud_rate: 115200 # speed to STC15L101EW
  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
  - platform: template
    name: 'Relay 3'
    id: relay3
    turn_on_action:
      - uart.write: [0xA0, 0x03, 0x01, 0xA4]
    turn_off_action:
      - uart.write: [0xA0, 0x03, 0x00, 0xA3]
    optimistic: true
  - platform: template
    name: 'Relay 4'
    id: relay4
    turn_on_action:
      - uart.write: [0xA0, 0x04, 0x01, 0xA5]
    turn_off_action:
      - uart.write: [0xA0, 0x04, 0x00, 0xA4]
    optimistic: true

Its a long time ago, but could you share your final code, that worked for you? I have the exactly same product, but can’t get it to work…
How did you wire your relay? Is this right?

wtf… seems like I hat the same problem with the wrong plug. used a better one, and its working now.

1 Like

@vaughancoke & @TheDoC thanks for the code, suggestions and tips. I believe I can add some small tips for using the 2 Relay version.

First, I recommend using Open-Smart ESP01 for flashing solves lots of headaches.

Secondly, pressing the S2 button is crucial, at least it was for me. I would suggest removing the
ESP from the board, power the board, press the S2 button till the blue light turns red. Then power off and put the ESP with the updated firmware and power on again. You should be able to connect and toggle. Below is the version I used, it is not much different from the original post.

esphome:
  name: dual_relay
  platform: ESP8266
  board: esp01_1m



wifi:
  ssid: "MY-WIFI"
  password: "password"

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

captive_portal:

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


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

ota:
  password: "anotherpass"

  
# 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: Relay ESPHome Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: Relay IP
    bssid:
      name: Relay BSSID

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

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


uart:
  baud_rate: 115200 # speed to STC15L101EW
  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

I had a spare ESP so I updated the firmware on the new one, this was also to be able to revert to the original firmware if I ever need to. After some playing around I can switch between the original firmware and ESPhome firmware
You can press the S1 button, see that the blue led is on and use the stock version, and press the b S2 button see that the red led is on and use the Esp with ESPHome firmware version.

1 Like

Hey! Try changing uart baud rate to 9600. It worked for me. The rest of the code is the same as in petermcandrew’s post

uart:
  baud_rate: 9600 # speed to STC15L101EW
  tx_pin: GPIO1
  rx_pin: GPIO3
1 Like

Hi,

I am totally new at this, so sorry for the “stupid” questions I am about to ask.
How do you create a new device using the esp01_1m profile?
What development software are you using to create these configuration files?

Thanks,

The files are created in the ESPHome Add-on for Home Assistant. Do you have ESPHome installed?

Hi All,
I’ve noticed that the GPIO0 pin is not used, so this gives the opportunity to add for example an extra sensor.
There is no spare connector for it, so you need to solder it on the bottom-side of the module, below the ESP01 connector:

Warning: This GPIO0 pin is directly connected to the ESP01 and therefore the voltage must not exceed 3.3 Volt! (Use a logic level shifter inbetween, for example the “SparkFun Logic Level Converter - Bi-Directional”) Also this pin must be ‘high’ during boottime, otherwise the ESP will start in ‘Program Mode’ instead of ‘Normal mode’!

I added for example this extra water flow sensor: YF-S201
According to this flow sensor specs:

  • Pulses per Liter: 450

Add this config to report the (converted in Liters/Hour) pulses back to Home Assistant every 5 seconds:

sensor:
  - platform: pulse_counter
    pin: GPIO0
    name: "Pulse Counter"
    update_interval: 5s
    filters:
    - lambda: return (x / 450) * 60;
    unit_of_measurement: "L/hr"

With this extra water flow meter I thought I can now (with a single ESP01 4-channel relay-module) toggle my 4 solenoid valves to give water to my garden, and also report the flow back to HA. :slight_smile: Sadly the datapin of this flow meter is active low, and thus also the GPIO0, resulting in an ESP stuck in ‘Program Mode’, so I removed the sensor for now.

2 Likes

Sorry for the late reply, I finally understand how ESP home works. It really is simple! Anyone know if there is a decent 8 relay ESP8266 board which you can buy?

This one works with esp8266. I had it working with a nodemcu esp8266.

https://www.amazon.com/gp/product/B01HCFJC0Y/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Hello, first of all excuse me for my English. I followed your instructions, hassio recognizes my esp, I see my relays but I don’t know how to activate them! However, the restart function works! An idea ??
Thank you

Hi.

I’m assuming that you’ve successfully flashed the relay board with ESPHome and integrated it into Home Assistant.

When you go to the integrations page what do you see?

indeed, I found the solution to my problem by resetting the card with the “S1” button.
Thank you