Pass Entity_Id name as variable

Hi There,

I have searched through a lot of documents and also posts, and haven’t found anything that I need yet. Was hoping someone that smarter than me knows.

I’d like to pass the actual entity_id name variable to the entity parameters itself and also as a data variable for scripts.

I can’t seem to get it working. I have bolded the spots where it should be bold.

What is the reason? Nothing if not some small laziness and a longer way to go about learning more how YAML works :slight_smile:

fan:
  - platform: template
    fans:
      b3_fan:
        friendly_name: "Bedroom 3 Fan"
        value_template: "{{ states('input_boolean.{{ entity_id }}_state') }}"
        percentage_template: "{{ states('input_select.{{ entity_id }}_speed') }}"
        turn_on:
          service: script.fan_on
          data:
            name: "{{ entity_id }}"
        turn_off:
          service: script.fan_off
          data:
            name: "{{ entity_id }}"
        set_percentage:
          service: script.fan_set_speed
          data:
            name: "{{ entity_id }}"
1 Like

In your example, entity_id is a variable you are attempting to reference that exists outside of the Template Fan configuration. In other words, you are trying to pass a variable to the Template Fan configuration and that’s not currently supported.

The only variables you can reference in a Template Fan are the ones you define within the Template Fan itself (see the first example in the documentation).

That’s a bit of a shame. I can see a lot of benefit for fetching the entity name (I’ll be adding 5 fans).

Obviously I can manually type it in each time, but was just interested if there was a better/more flexible way to do so. Thanks anyway!

1 Like

You’re welcome!

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals that this topic’s question has been answered. This helps other users who may be searching for answers to similar questions.

1 Like