Smart Light Controller based on the ESP8266
Simple Smart Light Controller
Adding a bit of automation to a certain area of the house can definitely help with saving energy. With this Simple Smart Light Controller, I aimed to do just that… Let me give you a tiny bit of context… Houses in SE Asia are built to some “questionable” standards and designs, and electrical installations are usually even more suspect… Our house is no exception. Being a rental, I do not want to go and make changes unless things are outright dangerous… Kitchens are usually a mixture of inside/outside areas, and this is where my device fits in…
The light in the outside kitchen consists of a simple bulb that the owner has routed into the house via an electrical flex cord, at least that was standard… But, due to laziness or just whatever, that cord was never terminated into a proper switch… He just added a plug. This is thus my opportunity to make life a bit easier for myself in that area. I could have opted for a standard switch, but then, automating this can take care of another problem… We constantly forget to switch that light off, as the plug is in a “strange place” that is not usually associated with the kitchen lights…
What I have thus come up with is a simple ESP8266-based solution with a single relay ( optically isolated from the board), as well as a few additional GPIO pins, just in case I want to hang some additional sensors onto this in the future.
The device should also be powered directly from the mains, as adding another external AC to DC adapter would definitely NOT do at all!
What is on the PCB
Lets look at the empty PCB, in order to understand better what is where on the board.
Starting on the Left Side, at the bottom corner, we have our mains voltage input, 220V or 110V, depending on where you live. That goes directly into U1, which is a AC-to-DC converter, providing 3.3v at 1A to the board. Note that I did not place a fuse directly on the board. I prefer to have an inline fuse on the line, which is also accessible from the enclosure.
A series of cutouts on the PCB provides additional mains isolation and also prevents mains voltage tracking towards other tracks in the event of a fault.
The Mains area also does not have a copper pour.
In the top left corner, towards the center, is a WAKE jumper. This is connected to GPIO16 and can be used to wake the ESP8266 from “deep sleep” if configured in the firmware.
Relay K1, and its screw terminal connector is in the bottom center of the board, with the relay contacts clearly labelled.
On the right of the PCB, we have the programming header, complete with Auto Flash and Reset circuitry, as well as manual Flash and Reset Buttons below that.
A 3×3 header connector follows, with access to 3.3v, Ground as well as 3 additional GPIO pins for other applications.
Finally, we have the relay control switch, with a few options to connect external switches, either on the 2.54mm header, or via wires soldered to the pads marked SW-A and SW-B
The populated PCB will thus make more sense if we look at the picture above now since we had a detailed look at it above…
Schematic_ESP8266-Smart-light-switch_2023-07-03Download
The Schematic is made available at the link above.
Configuration and Software
This build was designed with ESPHome in mind, so we will focus on that there.
You can however very easily use standard Arduino/ESP8266 code to control this as well…
The YAML configuration for the device will be as follows: (note that this is quite simplified, as I am still fine-tuning the actual features that I require)
esphome:
name: smart-switch-01
friendly_name: SMART-SWITCH-01
esp8266:
board: nodemcuv2
restore_from_flash: true
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "hfYNn8KSbVq26rGkPOJo4yLj/d/WY7Hk0H3TmxlWZAU="
ota:
password: "85ed2a8afcd61d0f4c65db7b92bdacc5"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Smart-Switch-01 Fallback Hotspot"
password: "XovAx4n1H1qT"
captive_portal:
text_sensor:
- platform: wifi_info
ip_address:
name: IP Address
ssid:
name: SSID
bssid:
name: BSSID
mac_address:
name: Wifi MAC
scan_results:
name: WiFi Scan Results
sensor:
- platform: adc
pin: VCC
name: "ESP8266 Chip Voltage"
id: mcu_voltage
unit_of_measurement: "V"
device_class: "voltage"
accuracy_decimals: 2
update_interval: 60s
entity_category: "diagnostic"
- platform: wifi_signal
name: "WiFi Signal Sensor"
id: wifi_strength
device_class: "signal_strength"
unit_of_measurement: "dBm"
update_interval: 240s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_strength
name: "WiFi Signal Strength"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
light:
# - platform: status_led
# pin: GPIO13
# id: status_indicator
# name: "ID Light"
- platform: binary
name: "Kitchen Outside Light"
output: relay_01
id: kitchen_light
on_turn_on:
- light.turn_on:
id: slow_light
effect: "Slow Pulse"
on_turn_off:
- light.turn_off: slow_light
- platform: monochromatic
id: slow_light
output: light_status
restore_mode: RESTORE_AND_OFF
effects:
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
binary_sensor:
- platform: gpio
pin:
number: GPIO5
mode:
input: true
pullup: true
id: kitchen_light_toggle
filters:
- delayed_on: 200ms
- delayed_off: 200ms
on_press:
then:
- light.toggle: kitchen_light
- platform: status
name: "Kitchen Light Controller"
switch:
- platform: restart
name: "Restart Device"
# Relay output
output:
- platform: gpio
id: relay_01
pin: GPIO4
inverted: true
- platform: esp8266_pwm
id: light_status
pin: GPIO12
Assembly and Testing
This device does not need a stencil for assembly, but using one will definitely speed up things. I chose to do this build all by hand, from applying solder-paste, up to placing components.
Soldering was done on a hotplate, as usual, to reflow everything at the same time. TH components were then placed and hand-soldered.
Uploading the initial firmware, after adding the device to ESPHome was done with an external USB-to-UART converter. All further firmware changes were made via OTA.
Enclosure and some of the wiring
It is important to mention here that this PCB is powered by mains voltage. I chose to use an inline fuse, BEFORE the connector on the PCB. It is also notable that the relay common is connected to the live wire, BEFORE the fuse, as the lightbulb acts as its own fuse – it blows when a fault occurs.
The Lightbulb neutral will be connected to the circuit breaker, together with the device live and neutral.
This way, the fuse only acts on the actual device, and I can use a lower-rating fuse, since I do not have to accommodate the current from the lightbulb as well…
Summary
The device works as planned, with no problems…
Below is some pictures from it in Home Assistant
esphome:
name: smart-switch-01
friendly_name: SMART-SWITCH-01
esp8266:
board: nodemcuv2
restore_from_flash: true
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "hfYNn8KSbVq26rGkPOJo4yLj/d/WY7Hk0H3TmxlWZAU="
ota:
password: "85ed2a8afcd61d0f4c65db7b92bdacc5"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Smart-Switch-01 Fallback Hotspot"
password: "XovAx4n1H1qT"
captive_portal:
text_sensor:
- platform: wifi_info
ip_address:
name: IP Address
ssid:
name: SSID
bssid:
name: BSSID
mac_address:
name: Wifi MAC
scan_results:
name: WiFi Scan Results
sensor:
- platform: adc
pin: VCC
name: "ESP8266 Chip Voltage"
id: mcu_voltage
unit_of_measurement: "V"
device_class: "voltage"
accuracy_decimals: 2
update_interval: 60s
entity_category: "diagnostic"
- platform: wifi_signal
name: "WiFi Signal Sensor"
id: wifi_strength
device_class: "signal_strength"
unit_of_measurement: "dBm"
update_interval: 240s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_strength
name: "WiFi Signal Strength"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
light:
# - platform: status_led
# pin: GPIO13
# id: status_indicator
# name: "ID Light"
- platform: binary
name: "Kitchen Outside Light"
output: relay_01
id: kitchen_light
on_turn_on:
- light.turn_on:
id: slow_light
effect: "Slow Pulse"
on_turn_off:
- light.turn_off: slow_light
- platform: monochromatic
id: slow_light
output: light_status
restore_mode: RESTORE_AND_OFF
effects:
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
binary_sensor:
- platform: gpio
pin:
number: GPIO5
mode:
input: true
pullup: true
id: kitchen_light_toggle
filters:
- delayed_on: 200ms
- delayed_off: 200ms
on_press:
then:
- light.toggle: kitchen_light
- platform: status
name: "Kitchen Light Controller"
switch:
- platform: restart
name: "Restart Device"
# Relay output
output:
- platform: gpio
id: relay_01
pin: GPIO4
inverted: true
- platform: esp8266_pwm
id: light_status
pin: GPIO12
Smart Light Controller based on the ESP8266
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(1)
- Engineer Dec 30,2023
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Jean Redelinghuys MakerIoT2020
- PCB_MCP23008_2023-10-08 MCP23008 BreakoutI designed this breakout to assist me during prototyping my next version of the “RP...
- PCB_XiaoRP2040-Mouse-REV2 Xiao RP2040 Joystick Mouse – revision 2.00Revision 1.0 of the ProjectOver the last few months, I hav...
- Multi Purpose IO Card Multi-Purpose IO CardWhen we are working on a prototype, we always need access to pushbuttons, encod...
- Variable Voltage Power Module Variable Voltage Power ModulePowering electronics projects are always challenging. This Variable vol...
- I2C Matrix Keypad An I2C Matrix KeypadThe completed I2C Matrix KeypadIn a previous post this month I introduced my 4×4...
- ESP32-S Development Board, in "Arduino Uno" form factor UPDATE 24/06/2023:This board now has a Hardware Revision 2.0 available. It is the same board but wit...
- W307186ASC94_Gerber_PCB_USB-Ports USB Power Supply ModuleUSB Ports are quite handy to power all our day-to-day electronic devices, but...
- Atmega 328P based PWM controller Card ATMega 328P Based PWM controller CardAs part of my recent ESP-12E I2C Base Board project, I designed...
- W307186ASC71_Gerber_PCB_ESP-Now Remote Today we will look at the remote control unit for the Robotic Toy Car – Part 6.The project is close ...
- W307186ASV69_Gerber_PCB_Robot-Car-MCU-Board Prototype In our last project, we started working on repurposing an old toy car. In this part, Robot Toy Car –...
- W307186ASV62_Gerber_PCB_DUAL-H-Bridge by makeriot2020 on May 27, 2022Many of us have old toys laying around the house, they belong to ou...
- CAN-BUS Breakout Breadboard Compatible CAN-BUS Breakout ModuleWhat is this:Some of us have already used the commonly ...
- RA-02 Breakout with Level converters Breadboard and beginner-friendly RA-02 Breakout ModuleMost Makers and electronics enthusiasts may al...
- ATMEGA328P Module with integrated LoRa and CAN Bus ATMEGA328P Module with integrated LoRa and CAN-BUSINTRODUCTIONIn my quest to perfect my LoRa telemet...
- Sx127x-Ra-02-Test-Module with ATMEGA328P-AU SX127x LoRa/FSK/OOK Prototype Radio BoardI recently had a requirement to do some automation/telemetr...
- USB-ASP Programmer ATMEGA8 Build your own USB-ASP Programmer CloneBymakeriot2020 FEB 21, 2022 Arduino, ASP programmerUsing mor...
- ATTiny1616-LIGHT-Controller-with-CAN_B_PCB_ATTiny1616-LIGHT-Controller-with-C_2024-09-11 Assembly of the ATTiny1616 Can bus controller PCBThe Assembly of the ATTiny1616 Can Bus Controller P...
- ATTiny1616QFN-CAN-Remote-Neopixel-Ligh_PCB_ATTiny1616QFN-CAN-Remote-Neopixel-2024-09-11_2024-09-11 NeoPixel CAN-Bus Module with local controlAs part of my current project to add NeoPixels to the cabi...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
121 0 0 -
DIY Laser Power Meter with Arduino
171 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
162 0 2 -