Caffeine, Code & Chaos

Systems engineer. Robotics geek. Maker of shiny things. Part race car, part glitter. Powered by caffeine and curiosity.

The Problem

Finding reliable landscape lighting control that integrates with Home Assistant isn’t always straightforward. Commercial solutions are expensive, and cheap relay boards from Amazon often lack good documentation or working ESPHome configurations. After purchasing a Eujgoov 4-Channel WiFi Smart Home Relay Module, I had to figure out the UART protocol through trial and error.

The Solution

A fully functional ESPHome configuration for serial-controlled relay boards, enabling reliable landscape lighting automation through Home Assistant. No coding required once configured, just flash and connect.

Hardware: Eujgoov 4-Channel WiFi Smart Home Relay Module
Platform: ESP8266 (ESP-01 1M)
Protocol: UART serial communication (115200 baud)
Integration: ESPHome + Home Assistant API
Enclosure: Custom 3D printed weatherproof case

Hardware Details

Relay Module Specifications

Custom 3D Printed Enclosure

The enclosure was specifically designed for this relay board after not finding a suitable pre-made option. Custom designed in Fusion 360 with proper mounting points for the relay board and heat-press threaded inserts for secure assembly.

UART Command Protocol

The relay board uses a simple hex-based serial protocol:

Turn On Relay:

Turn Off Relay:

Pattern: 0xA0, [channel], [state], [checksum]

Pin Configuration

ESPHome Configuration

The complete working configuration handles all 4 relays with proper UART communication:

Key Configuration Elements

UART Setup:

uart:
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 115200
  debug:
    direction: BOTH
    dummy_receiver: true
    after:
      delimiter: "\n"
      sequence:
        - lambda: UARTDebug::log_hex(direction, bytes, ':');

Logger Configuration:

logger:
  baud_rate: 0  # Disable serial logging (UART used for relay control)

Switch Template (per relay):

switch:
  - platform: template
    name: "Relay 1"
    id: relay_1
    optimistic: true
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
      - delay: 100ms
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
      - delay: 100ms

Important Configuration Notes

  1. Serial Logging Must Be Disabled - The UART pins are used for relay control, so baud_rate: 0 is critical in the logger configuration.

  2. UART Debug for Troubleshooting - The debug section helps reverse-engineer commands by logging hex traffic. Remove after initial setup for cleaner logs.

  3. Optimistic Mode - Since the relay board doesn’t send state confirmation, optimistic: true tells ESPHome to assume commands succeed.

  4. 100ms Delays - Small delays between commands prevent UART buffer overruns and ensure reliable switching.

Features & Capabilities

Home Assistant Integration

Automation Possibilities

Reliability Features

Setup Instructions

1. Hardware Connection

2. ESPHome Configuration

3. Initial Flash

4. Home Assistant Setup

5. Testing & Calibration

Home Assistant Automation Examples

Basic Sunset Automation

automation:
  - alias: "Landscape Lights On at Sunset"
    trigger:
      - platform: sun
        event: sunset
        offset: "-00:30:00"  # 30 minutes before sunset
    action:
      - service: switch.turn_on
        target:
          entity_id:
            - switch.relay_1
            - switch.relay_2
            - switch.relay_3
            - switch.relay_4

Smart Morning Shutoff

automation:
  - alias: "Landscape Lights Off After Sunrise"
    trigger:
      - platform: sun
        event: sunrise
        offset: "00:30:00"  # 30 minutes after sunrise
    action:
      - service: switch.turn_off
        target:
          entity_id: all
          device_id: [your_relay_controller_device_id]

Zone-Based Control

automation:
  - alias: "Front Yard Motion Detection"
    trigger:
      - platform: state
        entity_id: binary_sensor.front_yard_motion
        to: "on"
    condition:
      - condition: sun
        after: sunset
    action:
      - service: switch.turn_on
        target:
          entity_id: switch.relay_1  # Front yard zone
      - delay: "00:05:00"
      - service: switch.turn_off
        target:
          entity_id: switch.relay_1

Troubleshooting

Relays Not Responding

Random Switching or Interference

Home Assistant Integration Issues

OTA Update Failures

Lessons Learned

Serial Protocol Discovery

Finding the right UART commands took experimentation. The UART debug output was essential for reverse-engineering the protocol. The hex pattern (0xA0 prefix, channel byte, state byte, checksum) is simple once you see it in action.

Logger Conflicts

Initial attempts failed because serial logging competed with UART relay control. Setting baud_rate: 0 in the logger was the critical fix.

Optimistic State Management

Without feedback from the relay board, optimistic mode is necessary. This works fine for simple on/off control but means you can’t detect relay failures automatically.

Reliability Through Simplicity

The 100ms delays and straightforward UART commands make this setup very reliable. No complex protocols or timing issues, just simple hex sequences.

Future Enhancements

Planned Improvements

Custom Enclosure Design

The project includes a custom-designed 3D printed enclosure specifically engineered for this relay board. After searching for pre-made options and finding nothing suitable, I designed this enclosure from scratch in Fusion 360.

Design Features

Files & License

The 3D model is freely available on MakerWorld under Creative Commons Attribution-Noncommercial-Share Alike license. This allows anyone to download, print, and modify the design for personal use.

Download: MakerWorld - 4 Channel Relay Enclosure

The design process involved:

  1. Measuring the relay board dimensions precisely
  2. Modeling in Fusion 360 with proper clearances
  3. Test printing and iterating on mounting points
  4. Adding heat-set insert locations for professional assembly
  5. Final print and assembly with actual hardware validation

Bill of Materials

Total Cost: ~$30-50 for complete controller hardware (excluding lighting fixtures)

Why This Approach?

Advantages Over Commercial Solutions

Compared to Other DIY Options

Resources


This project combines custom 3D design, ESPHome configuration, and Home Assistant automation to create a complete landscape lighting solution. Both the enclosure CAD files and ESPHome config are freely available for anyone building a similar system.

No related posts yet.