ESPHome variables in entity_id

Hi,

I want to use a variable in entity_id to be able to reuse the yaml file for multiple device via package includes.

It looks like variables are not accepted in entity_id. Is there a way to fix this?

It is used for ESP deep sleep. I have a global prevent deep sleep toggle and device specific ones. I want to use the variable for the device specific toggle, based on the device name.

substitutions:
  device_name: esp-test-batt-az-j2
  friendly_name: ESP Test Battery Shield AZ-Delivery J2

packages:
  wifi: !include common/wifi.yaml

esphome:
  name: ${device_name}
  on_boot:
    then:
      - script.execute: esp_cds  #Consider Deep Sleep Script
      
esp8266:
  board: esp01_1m

# Enable logging
logger:

captive_portal:

#ESP Global Deep sleep

deep_sleep:
  id: deep_sleep_control
  sleep_duration: 30s

binary_sensor:
  - platform: homeassistant
    id: esp_prevent_deep_sleep
    name: "Prevent Deep Sleep"
    entity_id: input_boolean.esp_prevent_deep_sleep
  - platform: homeassistant
    id: esp_pds_device
    name: "Prevent Deep Sleep Local Device"
#    entity_id: input_boolean.esp_pds_esp_test_batt_az_j2
    entity_id: input_boolean.${device_name}

script:
  - id: esp_cds
    mode: queued
    then:
      - delay: 15s
      - if:
          condition:
            or:
              - binary_sensor.is_on: esp_prevent_deep_sleep
              - binary_sensor.is_on: esp_pds_device
          then:
            - logger.log: 'Skipping sleep, per esp_prevent_deep_sleep'
          else:
            - deep_sleep.enter: deep_sleep_control
      - script.execute: esp_cds

Did you ever find a solution to this? I’m also interested in using a variable in the entity field.

missing api:this script?