Skip to content

crgarcia12/electronics-homeassistant-lightscontroll

Repository files navigation

Home automation lights controller - ESPHome & Home Assistant compatible

This circuit controls home lights following these rules:

  1. Safe: Safety is first and is not traded in any decision
  2. Fail safe: If this device fails, the ligts are still controllable using the mechanical switches
  3. Follows standard instalation: This device does not require you to wire your house for it
  4. 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

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-schematics board-pcb board-pcb board-pcb board-pcb

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-schematics board-pcb board-pcb-3d board-pcb-3d board-pcb-3d board-pcb-3d board-pcb-3d board-real-image board-real-image board-real-image board-real-image

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-1 oscilloscope-sensing-mains-2 oscilloscope-sensing-mains-3

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

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

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

Development notes

Generating fabrication files for JLCPCB

  1. Plot PCB Gerber + Drill + Map:

    screenshot screenshot

  2. Bom files screenshot screenshot

    Command: python3 "C:\Program Files\KiCad\bin\scripting\plugins/bom_csv_jlcpcb.py" "%I" "%O.csv" screenshot

  3. Drill files screenshot screenshot run the python script to rotate the components screenshot

    PS C:\...\smt-assembly> python3 .\kicad-to-jlcpcb-pos.py .\hamodule-top-pos.csv .\hamodule-top-pos-jlcpcb.csv

Generate documents

schematics: screenshot

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-schematics board-pcb board-pcb-3d board-pcb-3d board-pcb-3d board-pcb-3d

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-schematics board-pcb board-pcb-3d board-pcb-3d board-pcb-3d board-pcb-3d

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-schematics board-pcb board-pcb-3d board-pcb-3d board-pcb-3d board-pcb-3d

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-schematics board-pcb board-pcb-3d

board-pcb-3d

The enclosure compared with a DIN relay. Size is perfect :) board-pcb-3d

Older version: Version 16

Size comparison between V16 and V13:

board-pcb-3d

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-schematics v2-board-pcb v2-board-pcb-3d v2-board-pcb-3d

Older versions: Version 9

Device schematics (under development)

v1-board-schematics v1-board-pcb v1-board-pcb-3d v2-board-pcb-3d

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-schematics v1-board-layouts

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published