I’d like to be able to manually toggle the onboard blue LED for a ESP32 board. I believe it is under GPIO2. Anyone have an example of how to do this? I found some stuff related to ESP8266 boards, but not ESP32.
I have tried the following but it does not work:
light:
- platform: monochromatic
id: onboard_led_light
output: onboard_led
output:
- platform: ledc
id: onboard_led
pin:
number: GPIO2
…
...
- lambda: |-
id(onboard_led_light).turn_on();
...
1 Like
micque
(micque)
July 4, 2020, 5:43pm
2
If you’re just trying to turn it off/on here’s an example
output:
- platform: gpio
id: gpio_3V3
pin: 2
on_boot:
- priority: 700
then:
lambda: |-
// power for the dhts and keys (gpio)
id(gpio_3V3).turn_on();
1 Like
@micque
For some reason, this doesn’t seem to work for me. I am using board type esp32doit-devkit-v1
micque
(micque)
July 4, 2020, 6:27pm
4
I’m not using that particular ESP32 board but from what I see the led should be hooked up to pin 2 like mine. Have you ever seen the led light up? Is it possible it is not functioning?
Yes, there is the main red LED for power and another blue led. I want to manually control the blue led. I can turn on the following for the standard status_led
in esphome and the blue LED works for that purpose:
status_led:
pin: GPIO2
micque
(micque)
July 4, 2020, 8:40pm
6
Okay. And you defined the output platform as gpio, not ledc, right?
MarkB1
(Mark Booth)
July 4, 2020, 8:54pm
7
My own.
esphome:
name: esp32_luanode_1
platform: ESP32
board: esp32doit-devkit-v1
status_led:
pin:
number: GPIO2
inverted: TRUE
board type luanode esp32
micque
(micque)
July 4, 2020, 9:05pm
8
I meant that you changed ledc to gpio here
output:
- platform: gpio # not ledc
id: gpio_led
pin: 2
and then called the lambda somewhere like this
lambda: |-
id(gpio_led).turn_on();
Or if you inverted the signal like your status_led shows did you try turn_off() instead?
MarkB1
(Mark Booth)
July 4, 2020, 9:47pm
9
like
switch:
- platform: gpio
id: blue_led
pin:
number: GPIO2
inverted: true
should work
cyn
July 4, 2020, 9:55pm
10
this works on my lolin 32
binary_sensor:
- platform: gpio
name: "Keys Missing"
id: "keys_missing"
filters:
- delayed_on_off: 1s
pin:
number: GPIO12
mode: INPUT_PULLUP
on_state:
then:
- if:
condition:
lambda: 'return id(keys_missing).state;'
then:
- switch.turn_off: onboardLED
else:
- switch.turn_on: onboardLED
switch:
- platform: gpio
name: "onboardLED"
id: onboardLED
pin:
number: GPIO22
inverted: True
mode: OUTPUT
restore_mode: ALWAYS_OFF
Yes, I tried the answer that you posted.
nickrout
(Nick Rout)
July 5, 2020, 7:47am
12
The first and most obvious thing would be to find a schematic for that board and look at it.
If you cannot find the schematic, trace the wiring to find out which gpio the led is connected to.
Isn’t it obviously on GPIO2 if the status_led works with:
status_led:
pin: GPIO2
??
Here is the latest that I have tried and it is not turning on still.
switch:
- platform: gpio
id: onboard_led
pin:
number: GPIO2
inverted: True
mode: OUTPUT
restore_mode: ALWAYS_OFF
binary_sensor:
- platform: gpio
name: "Test Button"
pin:
number: GPIO22
mode: INPUT_PULLUP
inverted: True
on_click:
then:
- switch.turn_on: onboard_led
[13:18:24][D][binary_sensor:036]: 'Test Button': Sending state ON
[13:18:24][D][binary_sensor:036]: 'Test Button': Sending state OFF
[13:18:24][D][switch:021]: 'onboard_led' Turning ON.
[13:18:25][D][binary_sensor:036]: 'Test Button': Sending state ON
[13:18:25][D][binary_sensor:036]: 'Test Button': Sending state OFF
[13:18:25][D][switch:021]: 'onboard_led' Turning ON.
1 Like
micque
(micque)
July 5, 2020, 4:35pm
15
I see you turning gpio2 on have you ever explicitly tried turn_off? Just wondering since you have inverted the output.
Hah, that was it. Looks like it works with this final configuration.
switch:
- platform: gpio
id: onboard_led
pin:
number: GPIO2
mode: OUTPUT
restore_mode: ALWAYS_OFF
binary_sensor:
- platform: gpio
name: "Test Button"
pin:
number: GPIO22
mode: INPUT_PULLUP
inverted: True
on_click:
then:
- switch.toggle: onboard_led
Thanks for the help.
5 Likes
jacotech
(Jaco)
August 14, 2022, 6:17am
18
This works for me.
Any way to also control the red led ?
1 Like
amrut
October 5, 2023, 8:04pm
19
It could be GPIO1 or GPIO2.
For mine apparently it was GPIO1. I am using a 38 pin USB C, ESP32-WROOM-32
sri4iot
(Sri R)
September 12, 2024, 6:38pm
20
Sorry for opening this old thread. Below given worked for me in esp32 devkit v1 board.
switch:
- platform: gpio
id: blue_led
pin:
number: GPIO2
mode: OUTPUT
name: "Blue LED"
restore_mode: ALWAYS_OFF
1 Like