Control over Status_led

Hello,

Today I migratted my first switch from Tasmota to ESPHome. But I can’t find how to control my status_led.
The status_led works, if there is no connection with HA it blinks, when there is connection it’s off.
But when there is connection I want to have the status led enabled when at least one of the output relay’s is on, and have it reverse blink for a short while when one of the buttons is pressed.

my config is like this

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_1
    on_press:
      then:
        - light.toggle: light_1

  - platform: status
    name: "Lamp Badkamer Status"

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

light:
  - platform: binary
    name: "Lamp Badkamer"
    id: light_1
    output: relay_1

status_led:
  pin:
    number: GPIO13
    inverted: yes

but for other switches I use I have up to 3 buttons and 3 relays. So it should work for those configs as well.

Can someone put me in the right direction?

Specific boards use different GPIO for functions (other than ESPxx programming mode) so to give advice, we need to know exactly which platform you are using (e.g. Wemos D1 clone, Sonoff Basic v2, etc).

In general GPIO2 is often used for a status LED:

To check a specific Sonoff device, I’d look at the Tasmota flashing instructions, and their template definitions - these will give the information needed to replicate the GPIO in ESPhome.
https://tasmota.github.io/docs/Pinouts/#finding-relays-and-lights

If this helps, :heart: this post!

Thank you,

But I think It’s GPIO13, as the status led is working.
In this case it’s about a Sonoff T0 no neutral switch

sorry, for the dutch link,
but it’s exactly wired the same as the default t0, t1, t2 and t3

And those templates are ok:

In tasmota I just assing GPIO13 and all works as I whish.
image
But ESPHome by default sees this as a status switch of the device and totally ignores the relay statuses.
At least, with my template.
So I’m looking for a way to look at the relay statuses too.

You can control this led as other outputs. Forget “status_led” function. Define your led as output. So you can define when to light and flash. I use this code for my led: lights if not connected, steady flashing when connected to wifi and short flash when connected to HA. You can easily adopt it to your needs.(note that switch.${device_name}_wifi_api_connected is my led)

> Interval: 
>   - interval: 1s
>     then:
>       if:
>         condition:
>           wifi.connected:
>         then:
>           - switch.turn_off: ${device_name}_wifi_api_connected
>           - if:
>               condition:
>                 api.connected:
>               then:
>                 - lambda: |-
>                     id(stevec) +=1;
>                     if (id(stevec) > 4) {
>                       id(stevec) = 0;
>                       id(${device_name}_wifi_api_connected).turn_on();}
>                 - delay: 50ms
>                 - switch.turn_off: ${device_name}_wifi_api_connected
>               else:
>                 - delay: 500ms
>                 - switch.turn_on: ${device_name}_wifi_api_connected
>         else:
>           - switch.turn_on: ${device_name}_wifi_api_connected

Thanks for your suggestion,
I just made this

light:
  - platform: binary
    name: "Lamp Badkamer"
    id: light_1
    output: relay_1
    on_turn_on:
    - light.turn_on: stat_led
    on_turn_off:
    - light.turn_off: stat_led
  - platform: status_led
    id: stat_led
    name: "Switch state"
    pin:
      number: GPIO13
      inverted: yes

# status_led:
#   pin:
#     number: GPIO13
#     inverted: yes

which is fine with 1 button, I need to add some if conditions when I go for the multi button switches.
I will take a look at your script then.

for as far as I understand using platform status_led, the error has automatically presence over the actual status, something which is great in my case.