ESPHome Push Button Hub
Obliczymy ostateczną cenę na podstawie wybranego pliku. Sprawdzisz ją i zaakceptujesz przed płatnością.
Zapisane na tym urządzeniu.
Informacje o modelu
- Źródło
- Printables
- Kategoria
- Electronics
- Licencja
- Creative Commons — Attribution — Noncommercial
THE PROJECT:
I've always wanted a central control hub for my lights, allowing me to easily turn them on and off while also receiving feedback on their status. This was also a wish because my parents struggle a lot to turn lights on or off using a cellphone. So I created this 16 push button Hub with 16 LEDs that interfaces with Home Assistant.
Software Requirements:
- Have Home Assistant running;
- Know how to setup ESPHome on your PC;
- Some ESPHome and HomeAssistant knowledge;
Hardware Requirements:
- ESP32-S3-DEVKITC1 + Expansion board (for better attaching cables);
- Any USB C cable to power the ESP32 board;
- 16 momentary push buttons with a diameter of 16mm and height of 18 mm;
- 16 3.3V LEDs (Optional);
- AWG 22 Wire to make the connections (or any other suitable cable)
- 9 x 3mm x 10mm allen screws (To fix the top part of the box)
- 5 x 3mm x 3mm allen screws to fix the ESP Board (you may use longer and just cut them to lenght or use with nuts and washers so the board attaches properly)
You may use other hardware compatible with ESPHome that supports 32 GPIOs or 16 if you don’t want to use LEDs. You may have to tweak the code when using only the push buttons. You will also need a soldering Iron to solder cables to the LEDs and push buttons.
PARTS USED:
So here are links to the parts I used (those are affiliate links and I earn a small commission from them, but feel free to buy the parts from wherever you like :) )
Products I bought and tested:
- ESP32-devkitC1 (buy with the expansion board)
- Wires
- Push buttons
- Heated Inserts
- USB C cable
Products I Havent bought because I had some laying around:
PRINTING:
There are 3 parts that you have to print:
- Box (Where the ESP will be attached)
- Box Panel (Where the buttons and LED will be attached)
- Cable Holder (hold the usb C cable)
I printed everything with a 0.6mm nozzle.
Please enable ironing on top surfaces for the box Panel. After printing, I put 3mm heated inserts in all holes.
You may note that in the photos there is a hole for a screw in the middle. I removed this hole from the final version because It wasn't necessary.
LABELS:
For each rectangle on the side of a button I made a Label to indicate what the button does. For that I created the labels in power point. Each Rectangle has a size of 20mm x 50mm.
I Printed all labels using Adhesive Fotographic Paper and sprayed a UV protection over it.
ASSEMBLY:
- Put all push buttons in the 3d Printed Parts;
- Put the LEDs in the Holes and Use Hot glue to keep them in place;
WIRING:
This may be time consuming because of all the soldering that you have to do, but it is really straight foward:
- Each LED should have one leg conected to 3.3v and the the other to a GPIO PIN;
- Each Button Should have one leg conected to GND and the other to a GPIO PIN;
- You should not conect a LED And Button to the same GPIO;
- In total You will connect 32 GPIOS.
- Be careful to not short anything when soldering (you may use eletrical tape or hot glue to prevent shorts when closing the box);
- Leave enough lenght for the wire, so you can open and close the enclosure (remember that there is space to accomodate extra wire lenght inside the box)
Below is a table with the GPIOs I used (Here you may use any GPIOs, but please keep track of the GPIOs that you are using):
| LED | GPIO Pin | Switch | GPIO Pin |
|---|---|---|---|
| LED_1 | 20 | SW_1 | 19 |
| LED_2 | 47 | SW_2 | 21 |
| LED_3 | 45 | SW_3 | 48 |
| LED_4 | 35 | SW_4 | 0 |
| LED_5 | 37 | SW_5 | 36 |
| LED_6 | 39 | SW_6 | 38 |
| LED_7 | 41 | SW_7 | 40 |
| LED_8 | 2 | SW_8 | 42 |
| LED_9 | 13 | SW_9 | 14 |
| LED_10 | 11 | SW_10 | 12 |
| LED_11 | 9 | SW_11 | 10 |
| LED_12 | 3 | SW_12 | 46 |
| LED_13 | 18 | SW_13 | 8 |
| LED_14 | 16 | SW_14 | 17 |
| LED_15 | 7 | SW_15 | 15 |
| LED_16 | 5 | SW_16 | 6 |
WIRING TEST CODE:
So, to test if all wiring is correct I wrote some arduino code that will make each LED turn on when pressing the button next to the LED. If Everything Lights Up, you should be good to go to the ESPHome code. This video helped me to setup the arduino IDE for the board.
#define LED_1 20
#define LED_2 47
#define LED_3 45
#define LED_4 35
#define LED_5 37
#define LED_6 39
#define LED_7 41
#define LED_8 2#define LED_9 13
#define LED_10 11
#define LED_11 9
#define LED_12 3
#define LED_13 18
#define LED_14 16
#define LED_15 7
#define LED_16 5
#define SW_1 19
#define SW_2 21
#define SW_3 48
#define SW_4 0
#define SW_5 36
#define SW_6 38
#define SW_7 40
#define SW_8 42
#define SW_9 14
#define SW_10 12
#define SW_11 10
#define SW_12 46
#define SW_13 8
#define SW_14 17
#define SW_15 15
#define SW_16 6
// Arrays for LEDs
const int leds[] = {
LED_1, LED_2, LED_3, LED_4, LED_5, LED_6, LED_7, LED_8,
LED_9, LED_10, LED_11, LED_12, LED_13, LED_14, LED_15, LED_16
};
// Arrays for switches
const int sw[] = {
SW_1, SW_2, SW_3, SW_4, SW_5, SW_6, SW_7, SW_8,
SW_9, SW_10, SW_11, SW_12, SW_13, SW_14, SW_15, SW_16
};
bool state[16] = {false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false};
void setup()
{
rgbLedWrite(RGB_BUILTIN, 0, 0, 0); // Off / black
for(int i=0;i<16;i++)
{
pinMode(leds[i],OUTPUT);
pinMode(sw[i],INPUT_PULLUP);
digitalWrite(leds[i], HIGH);
}
}
void loop()
{
for(int i=0;i<16;i++)
{
state[i]=digitalRead(sw[i]);
if(state[i]==1)
{
digitalWrite(leds[i], HIGH);
}
else
{
digitalWrite(leds[i], LOW);
}
}
delay(10);
}
CODE:
if you don't know how to setup ESPHome on your pc, this video may help you ( I used PC because for some unknown reason I couldn’t flash ESPHome via my Rasberry PI Running Home Assistant).
For ESPhome use the YAML code below (You may have to tweak the 30 first lines of Code with your credentias, like wifi SSID and password, home assistant API)
esphome:
name: esp_button_box
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
Enable logging
logger:
Enable Home Assistant API
api:
encryption:
key:
ota:
- platform: esphome
password:
wifi:
ssid:
password:
Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp Button Box Fallback Hotspot"
password:
captive_portal:
LEDS as OUTPUTS
output:
- platform: gpio
pin: 20
id: led_1
inverted: true
- platform: gpio
pin: 47
id: led_2
inverted: true
- platform: gpio
pin: 45
id: led_3
inverted: true
- platform: gpio
pin: 35
id: led_4
inverted: true
- platform: gpio
pin: 37
id: led_5
inverted: true
- platform: gpio
pin: 39
id: led_6
inverted: true
- platform: gpio
pin: 41
id: led_7
inverted: true
- platform: gpio
pin: 2
id: led_8
inverted: true
- platform: gpio
pin: 13
id: led_9
inverted: true
- platform: gpio
pin: 11
id: led_10
inverted: true
- platform: gpio
pin: 9
id: led_11
inverted: true
- platform: gpio
pin: 3
id: led_12
inverted: true
- platform: gpio
pin: 18
id: led_13
inverted: true
- platform: gpio
pin: 16
id: led_14
inverted: true
- platform: gpio
pin: 7
id: led_15
inverted: true
- platform: gpio
pin: 5
id: led_16
inverted: true
LEDS
light:
- platform: binary
name: "LED 01"
output: led_1
- platform: binary
name: "LED 02"
output: led_2
- platform: binary
name: "LED 03"
output: led_3
- platform: binary
name: "LED 04"
output: led_4
- platform: binary
name: "LED 05"
output: led_5
- platform: binary
name: "LED 06"
output: led_6
- platform: binary
name: "LED 07"
output: led_7
- platform: binary
name: "LED 08"
output: led_8
- platform: binary
name: "LED 09"
output: led_9
- platform: binary
name: "LED 10"
output: led_10
- platform: binary
name: "LED 11"
output: led_11
- platform: binary
name: "LED 12"
output: led_12
- platform: binary
name: "LED 13"
output: led_13
- platform: binary
name: "LED 14"
output: led_14
- platform: binary
name: "LED 15"
output: led_15
- platform: binary
name: "LED 16"
output: led_16
#PUSH BUTTONS
binary_sensor:
platform: gpio
pin:
number: 19
mode: INPUT_PULLUP
inverted: true
name: "Button 01"
id: button_1
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 21
mode: INPUT_PULLUP
inverted: true
name: "Button 02"
id: button_2
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 48
mode: INPUT_PULLUP
inverted: true
name: "Button 03"
id: button_3
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 0
mode: INPUT_PULLUP
inverted: true
name: "Button 04"
id: button_4
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 36
mode: INPUT_PULLUP
inverted: true
name: "Button 05"
id: button_5
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 38
mode: INPUT_PULLUP
inverted: true
name: "Button 06"
id: button_6
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 40
mode: INPUT_PULLUP
inverted: true
name: "Button 07"
id: button_7
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 42
mode: INPUT_PULLUP
inverted: true
name: "Button 08"
id: button_8
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 14
mode: INPUT_PULLUP
inverted: true
name: "Button 09"
id: button_9
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 12
mode: INPUT_PULLUP
inverted: true
name: "Button 10"
id: button_10
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 10
mode: INPUT_PULLUP
inverted: true
name: "Button 11"
id: button_11
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 46
mode: INPUT_PULLUP
inverted: true
name: "Button 12"
id: button_12
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 8
mode: INPUT_PULLUP
inverted: true
name: "Button 13"
id: button_13
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 17
mode: INPUT_PULLUP
inverted: true
name: "Button 14"
id: button_14
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 15
mode: INPUT_PULLUP
inverted: true
name: "Button 15"
id: button_15
filters:
- delayed_on: 50ms
- delayed_off: 50ms
platform: gpio
pin:
number: 6
mode: INPUT_PULLUP
inverted: true
name: "Button 16"
id: button_16
filters:
- delayed_on: 50ms
- delayed_off: 50ms