Status_led and led output with the same led

Is there a simple way to have the same status_led also be used a general purpose led after the is no longer required as a startup status indicator?

I’ve manage to do this in the following example, but I don’t know if there is an easier way.

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO1                                                                                                                                                                                                
    id: button
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "${short_name} Status"
    id: connect

switch:
  - platform: gpio
    name: ${short_name}
    pin: GPIO14
    id: relay
  - platform: template
    id: relay_mirror
    lambda: |-
      if (id(connect).state > 0 ) {
        if (id(relay).state > 0 )                                                                                                                                                                                            
        {                                                                                                                                                                                                                    
          id(led).turn_off();                                                                                                                                                                                                
        } else {                                                                                                                                                                                                             
          id(led).turn_on();                                                                                                                                                                                                 
        }                                                                                                                                                                                                                    
      }                                                                                                                                                                                                                      
      return id(relay).state;                                                                                                                                                                                                

status_led:
  pin:
    number: GPIO13
    inverted: yes

output:
  - platform: gpio
    id: led
    pin:
      number: GPIO13
      inverted: True

I’ve defined both status_led: and output: to use the same gpio pin. Then a switch that uses this output, locks out it’s desired functionally until the device is connected (binary_senor: status). In this case, the after the device is connected, the led reflects the inverted state of the relay.

One feature request to improve this is to define turn_on(), turn_off() function for the status_led:, this is really all the output: block provides for this code. Then these turn_on(), turn_off() functions could have the lockout build in, then that would eliminate the need for the binary_senor: status, and the out if statement to lockout the switching.

This category is for home assistant feature requests. If you would like to make an ESPHome feature request, do it here:

Moved to ESPHome .

apologies. must have followed the wrong link ( or clearly misunderstood it). Thanks

1 Like