Home automation lights controller - ESPHome & Home Assistant compatible
This circuit controls home lights following these rules:
- Safe: Safety is first and is not traded in any decision
- Fail safe: If this device fails, the ligts are still controllable using the mechanical switches
- Follows standard instalation: This device does not require you to wire your house for it
-
It can be installed centrally
Following those rules and using as a reference a multi-switch light controlled with a mechanical latching relay, this is the wiring idea:
![alt text](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v19-jlcpcb/readme-media/relay-wiring.png)
A normal circuit sends all push buttons to the latching relay, which controlls the lights.
This circuit (ESPHome) is a side-car to the latching relay acting as an standard push button, but also sensing the output of the latching relay to detect if the lights are on or off.
This device is extensible:
- Expose I2C pins
- Expose Serial pins
- Expose many GPIOs
- 3.3V jumper: Allows to disconnect the internal ESP32, and replace it by any other microcontroller
- Relays pins: Relays can be controlled with an external microcontroller or device directly
- Current sensing pins: Current sensing information is exposed through those pins. This can be used to connect any external microcontroller or any other device
- Provides 3.3V and 5V
- ESPHome compatible - It's very easy to integrate to Home Assistant
This device has several security measurements:
- Input fast-blown fuse
- Input MOV
- Slow fuses in every relay output
- Slow fuses in every mains detection input
- 4kv insulated PS for low voltage
- Comformal coating with 90kV/mm2 insulation
- High precision temperature sensor
There are two versions of the board, one with four channels and another with eight channels.
Latest versions use ESP32-S3, which is a very powerful microcontroller with a lot of features.
Version 24: Eight channels
Compared to version 22:
- Using TCAL6416A instead of MCP23108 due to having push-pull instead of open-drain ouputs
- Adjust the border cut-outs to fit the middle mounting hole
Version 23: Eight channels
Compared to version 22:
- Eight channels controlled via I2C for relays and mains sensing
- Added RGB Led controller
- Capacitor for 5v line
- Compatible with case: RS PRO Modular Enclosure for DIN rail Stock number: 1862291 (https://uk.rs-online.com/web/p/din-rail-enclosures/1862291/)
- Added MCP23018 as IO expander and TXB0108PW to shift the output of the darlington (~2.5V) to the logical high (3.3V)
Bugs
- MCP23018 is open drain and not a direct replace from MCP23017: Outputs are GND or disconnected, not Vcc
- Mid-PCB mounting hole in the cuted version is not properly placed
![board-pcb](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v23.8-jlcpcb/readme-media/3d_board_4.png)
Version 22: Four channels
Detailed information
Since Version 17:
- Cut-out ESP32 Antena area
- Move silkscreen for readability
- Improved schematic readability
- Add leds to indicate when relays are ON
![board-real-image](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v22-jlcpcb/readme-media/board-real-4.jpg)
How does it work?
Section under development.
Mains sensing
Section under development.
In here there will be a detailed description on how Mains is sensed.
Few teaser pictures that show how optocouplers with darlington behave. This allows the board to use very large resistors, very little current, and hence small fuses. All that improves safety and lowers the board consumption:
![oscilloscope-sensing-mains-3](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v22-jlcpcb/readme-media/osc-sens-switch-off.jpg)
Relays
Section under development. In here there will be a detailed description on why SSR with snubber relay was selected
This picture shows standard relays. Those have very large spikes
![oscilloscope-relays-mechanical](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/relay-analysis/Mechanical-PCN-105D.png)
This picture shows SSR relays with snubber. Spikes still exist, but they are much smaller and more isolated, reducing noise-related issues
![oscilloscope-relays-ssr](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/relay-analysis/SSR-AQG12105.png)
Simulate mains sensing cirquit
The mains sensing circuit can be simulated online at lushprojects.
$ 1 0.000005 30.13683688681966 70 5 50 5e-11
v -96 368 -96 80 0 1 50 230 0 0 0.5
w 48 80 48 144 0
d 48 144 112 208 2 default
d 48 272 112 208 2 default
d -16 208 48 144 2 default
d -16 208 48 272 2 default
w 48 272 48 368 0
w 48 368 -96 368 0
w -16 208 -16 304 0
w 112 208 160 208 0
w -16 304 224 304 0
r -96 80 48 80 0 300000
x 633 351 750 354 4 20 ESP32\sGPIO
407 448 208 528 208 1
w 224 240 224 304 0
v 752 272 752 208 0 0 40 3.3 0 0 0.5
w 624 208 544 208 0
r 624 272 752 272 0 50000
w 544 240 544 272 0
c 624 208 624 272 0 0.0000049999999999999996 0.08913507182464649 0.001
w 544 272 624 272 0
w 624 208 752 208 0
s 272 208 336 208 0 0 false
r 624 320 752 320 0 1000000
w 624 272 624 320 0
w 752 272 752 320 0
x 209 185 404 188 4 20 Mains\sSensing\sSwitch
w 448 208 336 208 0
w 272 208 160 208 0
w 448 240 224 240 0
o 0 64 0 4099 320 0.00078125 0 2 0 3
o 17 64 0 4099 5 0.00009765625 1 2 17 3
o 23 64 0 4099 5 0.00009765625 2 2 23 3
How to order from JLCPCB:
![how-to-order-from-jlcpcb](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/jlcpcb-how-to-order.gif)
Development notes
Generating fabrication files for JLCPCB
-
Plot PCB Gerber + Drill + Map:
![screenshot](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/tutorial/plot-2.png)
-
Bom files
![screenshot](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/tutorial/bom-2.png)
Command: python3 "C:\Program Files\KiCad\bin\scripting\plugins/bom_csv_jlcpcb.py" "%I" "%O.csv"
![screenshot](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/tutorial/bom-3.png)
-
Drill files
run the python script to rotate the components
![screenshot](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/tutorial/pos-3.png)
PS C:\...\smt-assembly> python3 .\kicad-to-jlcpcb-pos.py .\hamodule-top-pos.csv .\hamodule-top-pos-jlcpcb.csv
Generate documents
schematics:
![screenshot](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/readme-media/tutorial/gen-images-1.png)
PCB:
Print to PDF, and use a high-resolution PDF to JPG converting website like: https://pdf2jpg.net/
Older versions: 21
- Using the new ESP32-S3
- Replace CP2102 by ESP integrated USB support
- Replace USB protection diodes with an IC
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v21-esp32s3-pcbway/readme-media/board-pcb-3d-2.png)
Older versions: 20
Detailed information
Since Version 17:
- Mains sensing is inverted, to make better use of rectifier capacitors and have constant reading
- Removed low-v fuse. Having only one fuse is enough since PS has overcurrent protection and >4kV insulation
- Moved screwes. Now it has one extra holding point
- Expose GPIO12 and GPIO33, for better board extenisbility
- Moved to SSR with integrated snubber instead of mechanical relays. The kickback of the inductive load (latching relays) was creating spikes and restarting the ESP32
- Adding SMD caps to the 3.3v and 5V lines in case they are needed in noisy conditions
- Separate GND for relays and ULN from the digital signal plane, to reduce noise
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v20-pcbway/readme-media/board-pcb-3d-2.png)
Older versions: Version 19
Detailed information
Since Version 17:
- Adding fuses to every relay output. This is to protect in case two relays are closed at the same time, and one of them is accidentally wired to N. Current could flow from one to the other
- Moving SHT40 and extending the footprint, to make it easier to solder
- Moving LD11. Now it'seasier to fit in the case
- Tested with both optocouplers: LDA210 and ILD755-D
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v19-jlcpcb/readme-media/board-pcb-3d-2.png)
Older versions: Version 17
Detailed information
Since Version 13 there were many changes:
- Changed optocoupler for another one with less current requirements.
- Change resistors to 150k x 2
- Adding fuses to every sensing channel, and remove fuse in N
- Adding a separate fuse for 5V and 3.3V track
- Littlefuse have a holder, instead of solder directly to PCB
- Adding ESP32 onboard module
- Adding Temperature sensor, to detect if the board gets too hot
- Adding USB-C powered by CP2102N UART chip
- Remove capacitors from 5v->3.3 converter, to avoid inrush current at the USB
- Adding external pull-up resistors for ESP32, some pins do not have internal pull-ups
- Adding mains nets with creepage and clearance
- Replacing mains connectors by Wago with levers. They are super reliable and easy to use!
- Replace analog temperature sensor by SHT40 using I2C protocol.
- Also adding I2C terminal, so we can plug any I2C sensor
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v17-safety-jlcpcb/readme-media/board-pcb-3d.png)
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v17-safety-jlcpcb/readme-media/enclosure.jpg)
The enclosure compared with a DIN relay. Size is perfect :)
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v17-safety-jlcpcb/readme-media/cage-vs-relay.jpg)
Older version: Version 16
Size comparison between V16 and V13:
![board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v16-espinside-jlcpcb/readme-media/V16-v-sV2.jpg)
Older versions: Version 13
This version was minimized by:
- Using SPST-NO 3A smaller relays
- Using SMD 3W 29k resistors instead of THT
- Removed external buttons connector
- Removed external leds connector
- Using SMD ULN2003A instead of THT
- HCPL3700 THT capacitors replaced by Tantalum SMD
Security additions:
- Added fuse at the neutral return from the sensors (F2)
- Resistors are before HCPL3700, to make them work with less than 4V to N, instead of 110V to N
Stability:
- Added filter capacitor to ULN2003A
- Added filter capacitors to LD1117AV33
Others:
- Added led indicator when powered-on
![v2-board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v13-new-relays-jlcpcb/readme-media/PCB.jpg)
Older versions: Version 9
Device schematics (under development)
![v2-board-pcb-3d](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v02/readme-media/PCBs.jpg)
Older versions: Versions 1
I have no clue what I was thinking when I did this. I guess I put it here to show how much I had to learn :)
![v1-board-layouts](https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/raw/main/PCB/schematics-v01/readme-media/pcb-layout.png)