WTH Template variable warning without pinpointing to the source of the problem

Why after years, logs still don’t contain information helping to figure out which component or entity is responsible for raising an error/warning?

2024-12-23 11:58:39.877 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'system_mode' when rendering '{{ value_json.system_mode }}'

That’s coming from MQTT discovery, it won’t have a pinpoint because you aren’t creating it. Some custom integration is

OK, at least we know it’s from discovery. It could be mentioned in the log.
But if it comes from mqtt, then mentioning the mqtt topic should be possible which would improve debugging in 100%. Maybe even the entity which this template is created for.

The topic wouldn’t tell you anything because it would be the discovery topic, not the entity topic.

then this topic contains references to the entity topic, isn’t it?
Often those topics have something in common (ie named with the use of mac address etc). at least something.

Anyways, I’m sure something could be done with template entities and configured entities but in regards to MQTT discovery, there’s nothing that could be done because you wouldn’t be able to correct it. You’re at the mercy of whoever is creating the discovery, and it likely requires code changes.

It depends on the integration. If it’s a poor custom integration, it could have no information.

I understand. And that’s OK. I would at least report it to responsible party. Right now I have nothing.

1 Like

Well it’s not a simple change, and it would require code changes all across integrations that use Templates. I don’t think this will happen anytime soon. If it does happen, it would slowly roll out to integrations one at a time.

The problem is the template is registered before the entity is fully created. So we have nothing to reference when registering the template.

It has to be true if you say so.
I imagined, that it’s the HA that picks data from mqtt and then complains about their quality. So it seemed to be easy to add an mqtt topic name the data comes from to the log.

The template errors when the topic updates. The template isn’t checked immediately when it’s discovered. But during discovery, all we have at that point is the discovery info, not the entity info because the entity hasn’t been created. I’ll see if something can be added to MQTT, I’m pretty sure template entities already provide the entity_id in these types of errors. MQTT would likely fix the majority of these phantom template errors