Templating help (removing 'entity_id')

Hi all,

I am trying to clean up errors and issues identified in my HA logs. One warning I have a lot of is, “WARNING (MainThread) [homeassistant.components.template.binary_sensor] The ‘entity_id’ option is deprecated, please remove it from your configuration” and “WARNING (MainThread) [homeassistant.components.template.sensor] The ‘entity_id’ option is deprecated, please remove it from your configuration”

These are two of the entity templates I have:

binary_sensor:
  - platform: template
    sensors:
      downstairs_lights:
        friendly_name: Downstairs Lights
        device_class: light
        entity_id: group.downstairs_lights
        value_template: "{{ is_state('group.downstairs_lights', 'on') }}"
        icon_template: >-
          {% if is_state('group.downstairs_lights', 'on') %}
            mdi:lightbulb-group
          {% elif is_state('group.downstairs_lights', 'off') %}
            mdi:lightbulb-group-off
          {% else %}
            mdi:alert
          {% endif %}
  - platform: template
    sensors:

## Zooz Switches

      kitchen_light_switch:
        friendly_name: Kitchen Light Switch
        device_class: connectivity
        entity_id: light.kitchen_lights_15
        value_template: "{{ is_state('light.kitchen_lights_15', 'on') }}"
        icon_template: >-
          {% if is_state('light.kitchen_lights_15', 'on') %}
            mdi:toggle-switch
          {% else %}
            mdi:alert
          {% endif %}

If I comment out the ‘entity_id: group.downstairs_lights’ line (for example), then the icon stops working in Lovelace. I tried to figure out how to change the code to work without using ‘entity_id’ from reading the online docs, but I am not seeing what I am doing wrong. Can someone help?

Thanks,

Rick

It should work like this:

binary_sensor:
  - platform: template
    sensors:
      downstairs_lights:
        friendly_name: Downstairs Lights
        device_class: light
        value_template: >
          {{ is_state('group.downstairs_lights', 'on') }}
        icon_template: >-
          {% if is_state('group.downstairs_lights', 'on') %}
            mdi:lightbulb-group
          {% elif is_state('group.downstairs_lights', 'off') %}
            mdi:lightbulb-group-off
          {% else %}
            mdi:alert
          {% endif %}
      kitchen_light_switch:
        friendly_name: Kitchen Light Switch
        device_class: connectivity
        value_template: "{{ is_state('light.kitchen_lights_15', 'on') }}"
        icon_template: >-
          {% if is_state('light.kitchen_lights_15', 'on') %}
            mdi:toggle-switch
          {% else %}
            mdi:alert
          {% endif %}

Thank you! Why do the two types of entities require a different format for the value_template keyword? Also, where can I find these types of examples? I looked through the various online docs on the HA docs page, and in the Jinja2 documentation (which I did not comprehend too well). I feel like some of the instruction docs are not basic enough for inexperienced people like me.

They don’t. I was getting ready to make a multi-line template when I realised I did not have to and forgot to convert it back to single line. This should also work:

binary_sensor:
  - platform: template
    sensors:
      downstairs_lights:
        friendly_name: Downstairs Lights
        device_class: light
        value_template:  "{{ is_state('group.downstairs_lights', 'on') }}"
        icon_template: >-
          {% if is_state('group.downstairs_lights', 'on') %}
            mdi:lightbulb-group
          {% elif is_state('group.downstairs_lights', 'off') %}
            mdi:lightbulb-group-off
          {% else %}
            mdi:alert
          {% endif %}

Templating docs are here:

1 Like

Thanks. I read that page, but maybe I need to read it again more carefully. Thank you.