Template variable warning: 'None' has no attribute 'state' when rendering '

Hi, I’ve been having these warnings for some time (attached below), I would like to be able to eliminate them, but I can’t figure out how to do it… can someone kindly give me a hand? thank you in advance.

mdi:database-remove
{% endif %}
{% else %}
mdi:database-remove
{% endif %}’
2022-11-19 11:53:15.021 WARNING (MainThread) [homeassistant.helpers.entity_component] Forced update failed. Entity sensor.home_assistant_v2_db not found.
2022-11-19 11:53:15.026 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘None’ has no attribute ‘state’ when rendering ‘{% if states.sensor.home_assistant_v2_db.state %}
{% if states.sensor.home_assistant_v2_db.state | float >= 0 %}
{{ ( states.sensor.home_assistant_v2_db.state | float / 1000 ) | round(2)}}
{% else %}
Errore
{% endif %}
{% else %}
Errore
{% endif %}’

use the states() method instead of the state machine.

states('sensor.home_assistant_v2_db')

also the error is saying sensor.home_assistant_v2_db doesn’t exist.

I’m sorry but I’ve only recently been using home assistant, and I’m not very practical, could you tell me what I should do?

at some point (more recently than not if you are new to HA) you added a template to your configuration that referenced the “sensor.home_assistant_v2_db”. You need to find where that template is located and either - 1. fix the template or 2. post the template here so someone can help you fix it.

make sure you properly format the code using backticks ``` on the line before and after the code block that you post.

The big warning in the templating documentation:

If you are new at HA templating I would strongly suggest reading this page. It tells you all sorts of helpful things and links to the relevant Jinja doc as well to learn the basics.

ok, I made the changes you suggested, and indeed it seems to me that there are merro warnings, but now I have this repeating several times:
‘Forced update failed. Entity sensor.home_assistant_v2_db not found.’

Indeed I have only this entity : sensor.home_assistant_v2_db_size
How is it possible!!!

I don’t understand how you’re even remotely exasperated with this. Change the entity_id in the template sensor to match the sensor you have, that should be pretty obvious without anyone having to tell you that.