Creating a Smart LED Dimmer

Creating a Smart LED Dimmer

April 28, 2022

Table of Contents

Introduction

I frequently see cheap battery-operated monochrome string lights on clearance at stores locally such as Walmart. I wanted to be able to take advantage of these deals, but most of the lighting equipment that I own is "smart" and tied into the Home Assistant home automation system. I wanted to be able to bring these lights into my home automation system to control them more easily and tie them into my automations. There is the QuinLED controller, but it was a little overkill for these types of cheap monochrome string lights.

Solution Proposal

I was looking for a device to satisfy the following requirements:

  1. The device should be able to control at least one set of string lights (bonus points for multiple sets).
  2. The device should be able to control the brightness of the lights.
  3. The device should be able to control them via Home Assistant.
  4. Bonus points for extra headers for peripheral devices such as a PIR Motion Sensor.
  5. Bonus points for an onboard temperature sensor. They're cheap and can serve a variety of purposes for automations.

I created the following solution.

Schematic

Smart LED Dimmer Schematic

PCB Layout

Smart LED Dimmer PCB Layout Front
Smart LED Dimmer PCB Layout Back

Parts List

These are the parts I decided to go with for my build. It was purely based on availability and cost. I was not familiar with many of these brands (other than Sensirion) before using them, but I have not had any issues with my device.

NameDesignatorFootprintQuantityManufacturer PartManufacturerSupplierSupplier Part
Header-Male-2.54_1x10H1HDR-TH_10P-P2.54-V-M-11Headers Pins2.54mm1*10PLCSCC57369
ESP32 LeftP1HDR-TH_8P-P2.54-V-F-11Female headerHDR1X8-2.54BOOMELELCSCC27438
ESP32 RightP2HDR-TH_8P-P2.54-V-F-11Female headerHDR1X8-2.54BOOMELELCSCC27438
2N7000Q1,Q2TO-92-3_L4.9-W3.7-P1.27-L22N7000CJLCSCC9114
100KR1,R2R25122RMC2512100K1%NTyohmLCSCC269364
Screw Terminal BlockU1CONN-TH_JL301-50004U011JL301-50004U01JILN(锦凌)LCSCC1509680
100nFU2CAP-TH_L10.5-W5.0-P7.50-D1.21-TongfengLCSCC281835
SHTC3U3SENSORM-SMD_4P-L2.0-W2.0-P1.001SHTC3SensirionLCSCC194656

Other than that, you will also need a WeMos D1 MINI ESP32 or WeMos D1 ESP8266. The device is designed to work with either, but I have found it to work best with the ESP32 as it is more powerful and the ESP32 LEDC Output is a much better solution than the ESP8266 Software PWM Output.

Digital Render

This is a digital render of the board using MeshLab.

Smart LED Dimmer Digital Render

Software

For the software to control the onboard ESP32 (or ESP8266), I decided to go with ESPHome due to its ease of use, especially with Home Assistant. This is an example that I wrote which treats both LED outputs as one controller, that way two sets of lights can be controlled simultaneously. It can also read the value of the onboard SHTC3 and report back to Home Assistant.

substitutions:
  devicename: bld-v2-01
  friendly_name: Hallway Mirror Lights

esphome:
  name: ${devicename}
  platform: ESP32
  board: wemos_d1_mini32

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  ap:
    ssid: ESP-${devicename}
    password: !secret fallback_password

captive_portal:

web_server:
  port: 80
  auth:
    username: !secret web_username
    password: !secret web_password

api:
  password: !secret api_password

ota:
  password: !secret ota_password
  safe_mode: True

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

sensor:
  - platform: shtcx
    temperature:
      name: ${friendly_name} Temperature
      filters:
      - lambda: return x * (9.0/5.0) + 32.0;
      unit_of_measurement: "°F"
    humidity:
      name: ${friendly_name} Humidity
    update_interval: 60s

light:
  - platform: monochromatic
    name: ${friendly_name}
    output: LD1_LD2
    id: main_light
    gamma_correct: false
    restore_mode: RESTORE_DEFAULT_OFF

output:
  - platform: template
    id: LD1_LD2
    type: float
    write_action:
      - output.set_level:
          id: LD1
          level: !lambda return state;
      - output.set_level:
          id: LD2
          level: !lambda return state;
  - platform: ledc
    id: LD1
    pin: GPIO26
    # You may want to configure a maximum power output depending on your particular lights, to ensure they are not damaged by being over-powered.
    # max_power: 0.60
    frequency: 1220Hz
  - platform: ledc
    id: LD2
    pin: GPIO23
    # You may want to configure a maximum power output depending on your particular lights, to ensure they are not damaged by being over-powered.
    # max_power: 0.60
    frequency: 1220Hz

Final Results

I sent the final design files to JLCPCB for production. They are by far the cheapest PCB manufacturer to my knowledge, and I am satisfied with the build quality for these types of projects.

Smart LED Dimmer Physical Device 1
Smart LED Dimmer Physical Device 2
It works great for controlling a variety of lights, with Wi-Fi and dimming support, it works great for my use case. If you have any questions about the design or software, feel free to reach out at [my name]@jeffresc.dev and I'd be happy to help out.
©️ 2020-2024 JeffResc Last built 3 minutes ago