Logger: homeassistant.helpers.template
Source: helpers/template.py:2758
First occurred: 11:01:35 (82 occurrences)
Last logged: 11:42:05
Template variable error: 'value_json' is undefined when rendering '{% set messages = value_json.messages | default([]) %} {% for message in messages[-5:] %} - {{ message.message }} (from: {{ message.sender }}) {% endfor %}'
I have no idea where it comes from.
I have a few “Template” Helpers in helper, but I don’t see how I could find any code there. Especially not code which would be 2758 lines long or more.
This thing is occurring constantly.
I even looked thought the files and the only template.py I could find was in the HACS config for repositories, and this doesn’t have that many lines or any lines related to the error.
Can somebody help me out here?
Maybe with a way how to deal with those errors in the future too.
When it comes to template code throwing errors, ignore everything except the last bit which shows the code causing the issue (HA doesn’t currently report where the error came from such as automation/helper/etc or any stack info).
In your template helpers, click the settings gear icon, then click Template options to find possible code. If your code matches that error, that’s the helper throwing the error (and now its time to debug, namely referencing value_json improperly).
If it’s not in a helper, it might be a blueprint you used which would have created an automation or something - so check there too (three dots, edit in YAML to see all the code).
If it’s not that, go to Developer tools and Template - make sure you don’t have some code you were playing with sitting there causing errors either (wipe clean or reset to default).
If I click on a Template and try the gear there, it either shows me:
This entity (‘sensor.somethingsomething’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.
or I get the usual overview where you can add a friendly name, icon, etc.
I can’t find the template options.
I checked all automatations for the code.
Nothing.
There is just the example (?) in the Template tab in Developer tools.
Almost all. Now that you’ve asked, I’ve found 2 for that Windows App I’ve been using quite some time ago.
Going to throw them out since I don’t need it anymore.
whatever it is, it looks like something that would output a message. It doesn’t really make sense to come from MQTT discovery unless it was going into an attribute template.
Do you have any entities that attempt to output a message as the main state or attribute?
value_json is used in many places, so it could be any one of these places. It will typically not be in an automation. It will be in a configuration of an entity.
SQL entity
Rest Entity
MQTT discovery (you can’t do anything about this, it’s a bug in whatever’s creating the discovery information incorrectly).
MQTT manual entity
You need to figure out what one it is… I’ve been asking you questions but you aren’t answering in a way where I can help. Sorry. This is something you’ll have to look through or share your entire configuration.
I have addressed all of your questions and provided clarifications where you requested them.
Your second-to-last comment expanded the scope of the discussion beyond what it was when I initially started this thread.
I apologize if the information I provided was not as comprehensive as expected, but my responses were guided by the questions you asked.
Regarding your question about the term “entire configuration,”: could you please clarify what you mean by this?
Is there a specific file or location where I can review the actual code to identify the issue? This was, in fact, part of my original question as well.
I’m sorry, but I’ve been asking about MQTT and you can’t give a solid answer on what addons ↔ integrations go through this. 99% of the time, these errors come from MQTT discovery which is provided by either the addon or an integration that talks to an addon though MQTT.
E.g. Zigbee2MQTT is an addon that creates MQTT discovery for Home Assistant. That situation, it’s just an addon, no integration.
E.g. Frigate, the addon does not create MQTT discovery. However the integration does.
If you’ve searched your files for value_json in configuration.yaml using a tool like VSCode to “Find in files”, and none of the hits came up, it’s likely that you’re back to MQTT discovery.