SS4H-GloSwitch: Smart DIY Switch with ESP32 for Home Assistant

Ever wished your regular light switch could do a lot more?

Meet the GloSwitch—a multifunctional device that combines a light switch, night light, sunrise simulator, presence detector, and Home Assistant I/O controller, all wrapped in a sleek and customizable design.

And the best part? It’s open-source, so you can build one yourself. Let’s dive into how it works and how you can create your own!

Video version

Source files

The project is totally open-source, which means you can grab it and tweak it however you please. You can snag my design, the PCB layout, the 3D model, the bill of materials, and firmware – and make it exactly as is. Or, you can use it as a jumping-off point, make changes, and whip up something totally fresh.

If you want to receive all of them put the email below – I’ll send a link to you straight away.

Where can I buy it?

If you’d prefer to skip the PCB fabrication process, you can buy the PCB directly from my shop. It’ll save you some time and get you building faster.

JLCPCB

The sponsor of this project is JLCPCB. They made that beautiful board for this project. For a few bucks, and in a matter of days, you can have a professional PCB on your deck, ready to solder 🙂 Now, for new users, they provide up to $80 sign-up coupons.
And if you don’t feel up to it, they can solder all SMD components for you as well.

Why Build the GloSwitch?

The idea for the GloSwitch came from my son’s room. He needed a night light and a presence detector—because, like most kids, he forgets to turn off the light. Instead of buying separate gadgets, I decided to create a single, multi-functional device. Sure, the R&D phase was costly, but each new unit is now much cheaper than comparable off-the-shelf options.

Key Features

The GloSwitch functions as a traditional light switch. With one tap on the front panel, you can toggle lights on or off—even without a Home Assistant connection.
All the touch detection and relay driving logic is handled inside the device itself

Using a microwave sensor, the GloSwitch detects movement and presence with impressive sensitivity. You can adjust the detection range for movement or presence, so you’ll know if someone’s walking toward or away from the switch. Or just hanging out in one spot.

The Wi-Fi connection means every button press, any reading from the microwave sensor, the RGB LEDs, and the relay status all show up in Home Assistant.
So you can do with all of that whatever automations, scenes, or scripts you like.

RGB LEDs add a glow to help locate the switch in the dark, doubling as a night light for kids’ rooms or a gentle stair or bathroom light.

You can gradually brighten the LEDs to simulate a sunrise.
It really does make mornings suck less 🙂

There’s one more aspect that, a few years back, I wouldn’t have cared about. But now that I’m not living alone, all my DIY gadgets have to pass the “Does It Look Good Enough?” test from my better half.
The front panel is clear acrylic, engraved with designs of your choice. You can easily swap out the background for a fresh look in seconds.

How It’s Made

Let’s dive into the construction details step by step, so you can build it yourself if you decide you’d like to have the GloSwitch in your own home.

Front Panel

The front panel is made from a 3mm acrylic sheet that I cut and engraved using a CO2 laser. In my STORE, you can either pick a ready-made design or create your own custom one—just send me the file, and I’ll engrave it for you.
This way, you’ll have an absolutely one-of-a-kind switch on a global scale! 😉

Electronics

I split the device into a low and a high-voltage side, which you should treat with caution!
The main PCB is basically five boards merged into one, so you can solder everything at once using a single stencil.
The side boards (with LEDs) are attached to the main board that holds the ESP32, the LD2410 microwave module, the touch button, and the rest of the components.

The second PCB is the Relay Board.
Depending on the components you solder, you can run it on low voltage (from 8 to 28VDC) or straight from mains.
This board It has extra safety measures like a varistor and a fuse to protect against potential failures.
Additionally the AC-DC converter I selected is equipped with built-in protections, including overload, overvoltage, and short-circuit safeguards.


Enclosure

The visible enclosure is resin-printed for a sleek finish, while the hidden parts are FDM-printed using PETG V0.

What’s special about it compared to normal PETG?
V0 is self-extinguishing, so if it catches fire, it’ll put itself out. That’s a nice extra layer of safety.
It’s a bit more expensive, but I think it’s worth it if you’re dealing with mains voltage.

Software

The final step is integrating the GloSwitch with a smart system. Since the device is built on an ESP32, I’m confident that any open system like Domoticz, OpenHAB, or Home Assistant would be able to handle it seamlessly.
However, I’m a big fan and advocate of Home Assistant, so I’ll show you how I set it up in my own system using exactly that platform.

I used the ESPHome plugin as the intermediary. This makes programming the microcontroller as simple as writing (or copying and tweaking) a straightforward configuration file. Another huge advantage of ESPHome is that a whole team of people works on maintaining compatibility with every new version of Home Assistant, so you don’t have to worry about that at all.

The configuration file I used is included with the rest of the files. So, let’s move on to explaining what’s in there and why.

esphome:
  name: gloswitch
  friendly_name: GloSwitch

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: XXX

ota:
  - platform: esphome
    password: XXX

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:

This is a standard section of the file that ESPHome will generate automatically. When adding a new device, you’ll give it a name, which will be configured here by default. You don’t need to change anything in this part.

globals:
  - id: prev_red
    type: float
    restore_value: no
    initial_value: '1.0'
  - id: prev_green
    type: float
    restore_value: no
    initial_value: '1.0'
  - id: prev_blue
    type: float
    restore_value: no
    initial_value: '1.0'
  - id: prev_brightness
    type: float
    restore_value: no
    initial_value: '1.0'

Here, we declare global variables that I used to “remember” the previous state of the RGB LEDs. I did this because I want the LED brightness to increase by 20% when the touch button is pressed. So, I need to store the current state to be able to return to it later.

esp32_touch:

binary_sensor:
  - platform: esp32_touch
    name: "GloSwitch_Touch"
    pin: 27
    threshold: 1300
    on_press:
      then:
        # First, store the current state of the LED 
        - lambda: |-
            auto state = id(glogwitch_backlight).current_values;
            id(prev_red) = state.get_red();
            id(prev_green) = state.get_green();
            id(prev_blue) = state.get_blue();
            id(prev_brightness) = state.get_brightness();

        # Switch the state of the relay
        - switch.toggle: gloswitch_relay

        - light.turn_on:
            id: glogwitch_backlight

            brightness: !lambda |-
              float new_brightness = id(prev_brightness) + 0.2;
              if (new_brightness > 1.0) {
                new_brightness = 1.0; 
              }
              return new_brightness;
            red: !lambda 'return id(prev_red);'
            green: !lambda 'return id(prev_green);'
            blue: !lambda 'return id(prev_blue);'
            transition_length: 1ms

Here, we configure the capacitive touch button. We specify which pin the pad is connected to, set the threshold value that determines whether a touch is detected or not, and define what actions should occur when a touch is registered.

In my case, I set the threshold to 1300, which should be a good starting value. However, you might need to tweak it slightly if you end up using a thicker piece of paper for the background, or if your acrylic panel has different properties or is a bit thicker.

Next, we define what should happen when a touch is detected. This is where we ensure independence from Home Assistant and make the response faster.
As soon as a touch is registered, I increase the LED brightness by 20% and toggle the relay to turn the light on or off. This way, I don’t have to wait for HA to respond.

switch:
  - platform: gpio
    pin: GPIO21
    name: "GloSwitch_Relay"
    id: gloswitch_relay
    
output:
  - platform: ledc
    id: output_blue
    pin: 17
  - platform: ledc
    id: output_green
    pin: 18
  - platform: ledc
    id: output_red
    pin: 19

Here, we declare which specific pin controls each color of the LEDs. This step is essential to make use of the “light” component.

light:
  - platform: rgb
    name: "GloSwitch_backlight"
    id: glogwitch_backlight
    red: output_red
    green: output_green
    blue: output_blue
    effects:
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%
      - pulse:
          name: "Slow Pulse"
          transition_length: 500ms
          update_interval: 2s
      - random:
          name: Random Effect
          transition_length: 5s
          update_interval: 7s

The Light component is what appears in Home Assistant as an RGB lamp. This allows you to control the brightness and color directly from HA.

You can also predefine various effects here, which will be available for selection from a dropdown list.

ld2410:

uart:
  tx_pin: GPIO3
  rx_pin: GPIO1
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
  
binary_sensor:
  - platform: ld2410
    has_target:
      name: "Presence"
    has_moving_target:
      name: "Moving Target"
    has_still_target:
      name: "Still Target"

The last element I’ll discuss here is the configuration of the microwave sensor. The way I set it up is absolutely the simplest approach, but there’s so much more cool stuff you can do with it. I recommend checking out the article on the ESPHome website for more ideas.

In my setup, it works as three binary sensors tasked with detecting presence, a stationary target, and a moving target.

Conclusion

And that’s it! If you have any questions, doubts, or ideas for a cool upgrade, feel free to email me at contact@smartsolutions4home.com.

Thanks for reading till the end, and good luck if you’re planning to build your own GloSwitch!

Related Articles

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close