I got 4 relay module with esp01 from aliexpress but it switch relays not through pins.
How I can control this relay module with esphome?
I got 4 relay module with esp01 from aliexpress but it switch relays not through pins.
How I can control this relay module with esphome?
found answer in home assistant community relay control through uart, with some data and need disable logger: here is config in yaml format for esphome 4 relay esp01 module
# 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: 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]
- platform: uart
name: "A3on"
data: [0xA0, 0x03, 0x01, 0xA4]
- platform: uart
name: "A3off"
data: [0xA0, 0x03, 0x00, 0xA3]
- platform: uart
name: "A4on"
data: [0xA0, 0x04, 0x01, 0xA5]
- platform: uart
name: "A4off"
data: [0xA0, 0x04, 0x00, 0xA4]
after this we got 8 switches, that separate on and off each relay (2 on each relay)
# Enable logging
logger:
baud_rate: 0 #need this to free up UART pins
uart:
baud_rate: 9600 # speed to STC15L101EW
tx_pin: 1
rx_pin: 3
globals:
- id: on_flag_1
type: int
restore_value: no
initial_value: '0'
- id: on_flag_2
type: int
restore_value: no
initial_value: '0'
- id: on_flag_3
type: int
restore_value: no
initial_value: '0'
- id: on_flag_4
type: int
restore_value: no
initial_value: '0'
switch:
- platform: template
id: relay1
name: "Relay #1"
lambda:
return id(on_flag_1);
turn_on_action:
- uart.write: [0xA0, 0x01, 0x01, 0xA2]
- globals.set:
id: on_flag_1
value: '1'
turn_off_action:
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
- globals.set:
id: on_flag_1
value: '0'
- platform: template
id: relay2
name: "Relay #2"
lambda:
return id(on_flag_2);
turn_on_action:
- uart.write: [0xA0, 0x02, 0x01, 0xA3]
- globals.set:
id: on_flag_2
value: '1'
turn_off_action:
- uart.write: [0xA0, 0x02, 0x00, 0xA2]
- globals.set:
id: on_flag_2
value: '0'
- platform: template
id: relay3
name: "Relay #3"
lambda:
return id(on_flag_3);
turn_on_action:
- uart.write: [0xA0, 0x03, 0x01, 0xA4]
- globals.set:
id: on_flag_3
value: '1'
turn_off_action:
- uart.write: [0xA0, 0x03, 0x00, 0xA3]
- globals.set:
id: on_flag_3
value: '0'
- platform: template
id: relay4
name: "Relay #4"
lambda:
return id(on_flag_4);
turn_on_action:
- uart.write: [0xA0, 0x04, 0x01, 0xA5]
- globals.set:
id: on_flag_4
value: '1'
turn_off_action:
- uart.write: [0xA0, 0x04, 0x00, 0xA4]
- globals.set:
id: on_flag_4
value: '0'
I have a single but extended it based on what worked on my single this will produce 4 switches that can be toggled on/off.