Assign PIN NUMBER based on board type

I want to set ON/OFF the status LED.
Currently I am using substitution to assign the pin number for a specific board. Example "build_in_led_pin: GPIO02 ".
I am also using a substitution for the board type of the D1mini, ESP6288 and ESP32.
I wish to determine the pin number based on the board type.
Here is my code, I assign the pin number base on substitution ${esp_id}_BuildInLED

  platform: gpio
  id: ${esp_id}_BuildInLED
    number: ${build_in_led_pin}
    #number: |-
    #  if ( ${board_type} == esp32doit-devkit-v1) return 'GPI02'; 
     # else return (ERROR);

My assignment in substitution : board_type: esp32doit-devkit-v1
I try to assign the pin number base on board type example esp32doit-devkit-v1 would be pin number GPIO2 while board type nodemcuv2 would be D4.
I think that I can do it with lambda, but I don’t know how.
Can someone with programming knowledge help me please.

You can only use a lamda in a field if they are marked with “templatable” in the docs. The one’s you’re looking at funny have that flag. So I don’t think that will be an option for you.

Maybe look through here and around. Perhaps something with compound substitutions?

I resolved my problem using the ESPhome documentation "Packages as Templates vars ".

1 Like