This chapter introduces the configuration methods and practical steps for integrating the Unit 4Relay relay into Home Assistant.
external_components are required to implement I2C communication control.The I²C component needs to be enabled in the ESPHome configuration:
# Example configuration entry for ESP32
i2c:
sda: GPIOXX
scl: GPIOXX
scan: true The GPIO pins here vary depending on the main controller device used. For example, using Atom Lite as the main controller:
# I2C Bus on Grove Port (HY2.0-4P)
i2c:
sda: GPIO26
scl: GPIO32 Unit 4Relay configuration example:
external_components:
- source: github://m5stack/esphome-yaml/components@main
components: unit4relay
refresh: 0s
unit4relay:
switch:
- platform: unit4relay
relay_1:
name: "Relay Channel 1"
restore_mode: RESTORE_DEFAULT_OFF
relay_2:
name: "Relay Channel 2"
restore_mode: RESTORE_DEFAULT_OFF
relay_3:
name: "Relay Channel 3"
restore_mode: RESTORE_DEFAULT_OFF
relay_4:
name: "Relay Channel 4"
restore_mode: RESTORE_DEFAULT_OFF
Default light control is used here: when the switch for the corresponding channel is turned on, the corresponding LED will light up.
# Example configuration entry
unit4relay: relay_1 (Optional): Relay switch for channel 1. Default is false (off), and all other configuration options supported by Switch.
relay_2 (Optional): Relay switch for channel 2. Default is false (off), and all other configuration options supported by Switch.
relay_3 (Optional): Relay switch for channel 3. Default is false (off), and all other configuration options supported by Switch.
relay_4 (Optional): Relay switch for channel 4. Default is false (off), and all other configuration options supported by Switch.
After adding the device to the Dashboard, you can control the relay on/off actions in Home Assistant.