Servo Light Switch ESP32 ESPHome / HomeAssitant
Obliczymy ostateczną cenę na podstawie wybranego pliku. Sprawdzisz ją i zaakceptujesz przed płatnością.
Zapisane na tym urządzeniu.
DIY Smart light switch using a Standard Servo and an ESP32 dev board.
- Ocena
- 0 / 5
- Polubienia
- 13
- Pobrania
- 38
- Wydruki
- 0
- Wyświetlenia
- 726
- Oceny
- 0
Aktualizacja u źródła:
Informacje o modelu
- Źródło
- Printables
- Kategoria
- Other House Equipment
- Licencja
- Creative Commons — Attribution
DIY Smart switch that is controlled by a ESP32. Example code for ESPHome and Home Assistant
If you haven't used ESPHome with home assistant before check out the getting started page for more info: https://esphome.io/guides/getting_started_hassio.html
The light switch can be operated manually as long as the sliding part of the print is left in the position shown in the images. The included code will flip the switch up and then return to center or flip the switch down and return to center so the light switch can be used manually/normally as well.
The space for a Microwave Radar Sensor Module LD2410 in the lid, but I never got it to work reliably, so I don't have any example code for it.
The screws that come with most servos should be all that is needed to mount the servo to the gear. The lid is attached with a 3mm x 5~15mm screw
Parts
- 1x ESP32 Dev Board. Any should work. The ones I used are this USB-C type
- 1x Standard Size Servo. The ones I used are this model
- 1~2x 3mm x 5~15mm screws to attach the lid. You could also glue the lid shut.
- (Optionl) Microwave Radar Sensor Module LD2410 - To use a motion sensor. I would look elsewhere for it since it can be found for user $5 in may places.
Wiring Things UP
The servo needs to be connected to 5V power and Ground on the ESP32. The pinout will depend on the ESP32 board you use. The example code below has the PWM pin of the servo connect to GPIO25 This can be changed if needed. The power for the ESP32 and Servo comes from the USB port on the ESP32 (in the version I built). As long as 5V is provided to the ESP32 it should all work. The Servo does use a fair bit of power (when moving), so you do need to use a 1.5 to 2amp 5v power source.
ESPHome Example Code
You will need to update and change the below as needed.
The servo position for on and off may need to be adjusted for -50 and 50. Or flipped. There is a manual servo control exposed in the device info in Home Assistant when using the bellow code. This can be used to find the positions the servo needs to be in for the light switch to be off and on, and then the values can be edited in the ESPHome yaml file to make the on/off toggle in Home Assistant work correctly.
esphome:
name: servo-light-switch
friendly_name: Servo Light Switchesp32:
board: nodemcu-32s
framework:
type: arduino
Enable logging
logger:
Enable Home Assistant API
api:
encryption:
key: "{ ADD YOU OWN HERE }"
ota:
- platform: esphome
password:"{ ADD YOU OWN HERE }"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Servo-Light-Switch"
password: "{ ADD YOU OWN HERE }"
captive_portal:
Setting up Servo to use pwm_output defined bellow
servo:
- id: my_servo
output: pwm_output
output:
- platform: ledc #ESP32 doesn't have a PWM servo option so LEDC is used instead
id: pwm_output
pin: GPIO25 #Pin the Servo is connected to
frequency: 50 Hz
- id: onboard_led #Built In LED on the Dev Board
platform: gpio
pin: GPIO2
number:
- platform: template
name: Servo Control
min_value: -100
initial_value: 0
max_value: 100
step: 1
optimistic: true
set_action:
then:
- servo.write:
id: my_servo
level: !lambda 'return x / 100.0;'
light:
- platform: binary
id: "servo_light_switch" #Change to what you want to call the light switch
name: "Servo Light Switch" #Change to what you want to call the light switch
output: onboard_led
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- servo.write:
id: my_servo
level: !lambda 'return 50 / 100.0;' #Edit as needed with the servo postion needed for the light switch to be on
- delay: 250ms
- servo.write:
id: my_servo
level: !lambda 'return 0 / 100.0;'
on_turn_off:
- servo.write:
id: my_servo
level: !lambda 'return -50 / 100.0;' #Edit as needed with the servo postion needed for the light switch to be off
- delay: 250ms
- servo.write:
id: my_servo
level: !lambda 'return 0 / 100.0;'
icon: mdi:lightbulb-fluorescent-tube #Change to the icon you want the light switch to have by default