The 'entity_id' option is deprecated, please remove it from your configuration

I am using the entity_id for several of my template sensors. After some reading on the new sensor template approach, I am still wondering if it is safe to just remove the entity id from my sensors or if I need to do some additional changes to make sure it keeps working.
Some of the template sensors are using the “states” function, therefore the actual entities are on a string passed to the parameter of the function. I’m not sure if this may prevent the parser from figuring out which entities it should monitor for updating the template sensors.

Here are some examples of my sensors:

A sensor for keeping daily energy totals (energy splitted by 3 different moments of the day):

energy_daily_total:
      friendly_name: 'Energia diária total'
      entity_id:
        - sensor.daily_energy_vazio
        - sensor.daily_energy_cheias
        - sensor.daily_energy_ponta
      value_template: " {{ (states('sensor.daily_energy_vazio') |float +
                           states('sensor.daily_energy_cheias') |float +
                           states('sensor.daily_energy_ponta') |float) | round(3)
                      }}"
      unit_of_measurement: "kWh"

Energy hourly history (uses a sensor that is zeroed every hour):

    energy_hourly_history:
      friendly_name: 'Energia por hora'
      entity_id:
        - input_number.hourly_energy_val
      value_template: " {{ (states('input_number.hourly_energy_val') |float) | round(3) }}"
      unit_of_measurement: "kWh"

And finally a couple of sensors to determine if on daylight saving time and if on last day of the month:

- platform: template
  sensors:
    daylight_saving_time:
      entity_id: sensor.time
      value_template: "{{now().timetuple().tm_isdst | int > 0 }}"

    last_day_of_the_month:
      friendly_name: 'Last Day of the Month'
      entity_id: sensor.date
      icon_template: "mdi:calendar"
      value_template: "{{ (as_timestamp(now()) + 86400)|timestamp_custom('%d', true) == 01 }}"

What do you make of this? Can I simply remove the entity_id from my sensors? In these last two sensor templates I’m not even using the referred entities directly on the template itself.

Just remove the entity_id field for all 4 templates. The only behavior change you will have is in your last template. It will now be updated once a minute, where as before it would update once a day. now() inside templates will always update once a minute if there hasn’t been an update in the past minute. And it should update on the minute.

1 Like

There was some back and forth but it ended up that now() updates every minute on the minute, regardless of other updates.

For the template entities, it is generally safe to just remove entity_id. There were a couple of releases where workarounds were needed in some situations but that is now being handled for all but the most special cases (I didn’t see one yet).

1 Like

Good to know! Thanks

1 Like

might I invite you to a thread on the template editor itself? It seems to behave unexpectedly in certain cases, making it hard to debug incorrect templates…
this being one of them

also, editing correct templates to include errors, leave the previous correct output there, so one might be tricked into believing a template is correct, while it isnt at all.

it’s not unexpected… it’s a byproduct of typing. We all knew this would happen.

The resolver (my name) trys to type the output of a template. You can see the resulting type in the template editor. If you have more than 1 output {{ }}, it will almost always resolve as a string. A single output will resolve as whatever it deems the type to be. It does not resolve on a line by line template. It resolves the entire output. It does not parse anything. It straight takes the output and applies a type to it. So if your output is 4.0, it will resolve to a number, in this case an int and return 4.

well, not exactly. we didnt know editing this template:

       {%- set ns = namespace(not_off=[]) %}
          {%- for s in expand('group.switches_sensors_actueel')
            if  s.object_id.split('_actueel')[0] not in
                  ['inductieplaat','patchboard_zolder'] and
                states(s.entity_id) not in ['0','0.0'] and
                states('switch.' + s.object_id.split('_actueel')[0]) == 'off' %}
          {% set ns.not_off = ns.not_off + [s] %}
          {% endfor %}
          {{ns.not_off|count}}
        attribute_templates:
          List: >
            {%- set ns = namespace(not_off=[]) %}
            {%- for s in expand('group.switches_sensors_actueel')
              if  s.object_id.split('_actueel')[0] not in
                    ['inductieplaat','patchboard_zolder'] and
                  states(s.entity_id) not in ['0','0.0'] and
                  states('switch.' + s.object_id.split('_actueel')[0]) == 'off' %}

            {%- set ns.not_off = ns.not_off + [s.name+ ': ' + s.state + ' watt'] %}
            {%- endfor %}
            {% set count_not_off = ns.not_off|count %}
            {% set list = ns.not_off %}
            {% if count_not_off == 0 %} All fine
            {%- elif count_not_off == 1 %}
                {{list[0]}} is still using power!
            {%- elif count_not_off == 2 %}
                {{list|join(' and ')}} are still using power!
              {%- else %}
                {{list[:-1]|join(', ')}}, and {{list[-1]}} are still using power!
              {%- endif %}

which result is:

to in incorrect template (I edit the group name to a non existing one)

         {%- set ns = namespace(not_off=[]) %}
          {%- for s in expand('group.switches_sensors_doesnt_exist')
            if  s.object_id.split('_actueel')[0] not in
                  ['inductieplaat','patchboard_zolder'] and
                states(s.entity_id) not in ['0','0.0'] and
                states('switch.' + s.object_id.split('_actueel')[0]) == 'off' %}
          {% set ns.not_off = ns.not_off + [s] %}
          {% endfor %}
          {{ns.not_off|count}}
        attribute_templates:
          List: >
            {%- set ns = namespace(not_off=[]) %}
            {%- for s in expand('group.switches_sensors_doesnt_exist')
              if  s.object_id.split('_actueel')[0] not in
                    ['inductieplaat','patchboard_zolder'] and
                  states(s.entity_id) not in ['0','0.0'] and
                  states('switch.' + s.object_id.split('_actueel')[0]) == 'off' %}

            {%- set ns.not_off = ns.not_off + [s.name+ ': ' + s.state + ' watt'] %}
            {%- endfor %}
            {% set count_not_off = ns.not_off|count %}
            {% set list = ns.not_off %}
            {% if count_not_off == 0 %} All fine
            {%- elif count_not_off == 1 %}
                {{list[0]}} is still using power!
            {%- elif count_not_off == 2 %}
                {{list|join(' and ')}} are still using power!
              {%- else %}
                {{list[:-1]|join(', ')}}, and {{list[-1]}} are still using power!
              {%- endif %}

shows the same output (doesn’t change it), only shows which entities is listens to correctly:

I guess it shows the guard clause, but would have still expected it to have an indication I am using a non existing entity

Thank you for the invitation but I have decided to stay out of the native types talk.

Because you still don’t understand the change. Remove the yaml and it will produce the correct result. Only use the template, no extra text. Please spend 5 minutes reading my explanation.

Also, “All fine” is expected with the wrong entity_id because your iteration always returns zero when expand returns an empty list. 100% unrelated to the topic at hand.

well, I do (understand), and I did (read). And I still don’t like it. I’ll stop fighting it, and learn to live with it, but it certainly feels like a step back. sorry.

yep agree on that too. As I has already concluded myself.

maybe to the OP topic, but not in response to the 'sub discussion which had developed, being the template editor behaving unexpectedly.

But the template isn’t working any different for the “unexpected” error that you just posted. The old editor would have done the same thing.

Hello
i tried to automate my switch with template, it can run if i hit manually but cant run auto. kindly pls how solve it.

platform: template
value_template: >-
{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) ==
as_timestamp(strptime(states(“sensor.asr_prayer”), “%Y-%m-%dT%H:%M:%S”)) - 300
}}

service: switch.turn_on
entity_id: ‘switch.bel_guru, switch.bel_aspura, switch.bel_rusunawa’

i got this error in logs :
The ‘entity_id’ option is deprecated, please remove it from your configuration

Can you surround your yaml with three back-ticks before and after? It’ll format it in a monospace font, and spacing is important in yaml. Eg:

This is monospaced and
      leading spaces will be preserved.

Hi there, my be i have done logic mistake. could you possible to help me? I think my code problem is about entities.
Im trying to do thermostat. How can i do when i use 2 nodemcu? im using one for temperature measurement… other for controlling heater… 2 device is different point of my house. but they are in the same wireless hub… two of them working well know, but I couldnt do thermostat :frowning:

Happy to try to help, but I think you’re best of creating a new post and add information about your system, settings and configuration you tried.

actually i did already :slight_smile

This really isn’t an error. You no longer need the entity_id in your sensor or binary_sensor templates that are in your configuration files. This isn’t keeping your automation from running - there’s likely some other error in the trigger if you can run it from the developer/service tool (assuming that’s what you mean when you state you can run it manually).

To eliminate this error, simply comment them out in your config files templates - HA now figures it out when to update the sensor/binary_sensor without the added overhead of the entity_id.

Please follow @SteveDinn’s instructions by re-posting but with the requested formatting. For example, copying and pasting your provided code in the proper format looks like this:

 platform: template
value_template: >-
{{ as_timestamp(strptime(states(“sensor.time_date”), “%H:%M, %Y-%m-%d”)) ==
as_timestamp(strptime(states(“sensor.asr_prayer”), “%Y-%m-%dT%H:%M:%S”)) - 300
}}

service: switch.turn_on
entity_id: ‘switch.bel_guru, switch.bel_aspura, switch.bel_rusunawa’

Looking at this way shows a problem with spacing (and YAML is VERY sensitive to spacing!). Additionally, this isn’t complete - assuming it is within an automation, you need an action: section and maybe a condition: section depending on what you are trying to do.

Please post the complete automation and then we can help more (starting with the alias line through the action section.

Additionally, you can test the template in the developer/template tool - I use that almost every time…

Hey @petro – I was using the code you recommended for the making a sensor that would tell me which alexa was the last one spoken to…

  - platform: template
    sensors:
      last_alexa:
        entity_id:
          - media_player.exercise_room_echo
          - media_player.garage_dot
          - media_player.kitchen_echo_show
          - media_player.livingroom_dot
          - media_player.master_bedroom_dot
          - media_player.office_dot
      value_template: >
        {{ states.media_player | selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}

How do you recommend removing the entity_id from this code? I know it’s using it as a reference point in the value template. I’m fairly new at this and have tried a couple things and have yet to come up with a viable solution on my own.

Thanks for any info

I don’t think this is needed anymore, the alexa media player now offers the last spoken device as a media_player. Check your states list.

Thanks, I’ll look into that now!