Keep receiving error Template variable warning: 'dict object' has no attribute 'Range' when rendering

Logger: homeassistant.helpers.template
Source: helpers/template.py:1850
First occurred: 2:37:10 PM (67 occurrences)
Last logged: 2:48:00 PM

Template variable warning: 'dict object' has no attribute 'Range' when rendering '{{value_json['ANALOG']['Range']}}'
Template variable warning: 'command' is undefined when rendering '{"command":"{{ command }}", "user":"homeassistant"}'

Any ideas of what is causing this and how I can stop this error? It happns thousands of times…

Thanks in advance!

Search for this string value_json['ANALOG']['Range'] and see what file it is in. :slight_smile: If it is a component or intergation, you can’t do a lot, but if it’s in one of your files, post the complete content of that file. :slight_smile:

The JSON dictionary received by the following template sometimes doesn’t contain a Range key. Attempts to reference a non-existent key will produce an error message.

{{value_json['ANALOG']['Range']}}

If the template is part of a Template Sensor, you can use availability to confirm the presence of both the ANALOG and Range keys. If the received payload doesn’t contain both, the payload is simply ignored.

In the following template (which appears to be producing a JSON payload for some purpose), it references a variable you have created called command. I don’t know where you are using this or how you are configuring the variable but sometimes it’s undefined. Referencing an undefined variable in a template will produce an error message.

'{"command":"{{ command }}", "user":"homeassistant"}'

You can guard against having an undefined variable by using the default filter to provide a default value. For example, if command is undefined, this will supply a value of unknown (however you really should determine why the variable isn’t always defined).

'{"command":"{{ command | default("unknown") }}", "user":"homeassistant"}'

I’ve used find in VSCode for the string you mentioned, but it only shows the error logs :confused:
Must be an integration I installed manually. Thanks anyways!

Are you running MQTT?

Quick google search shows tasmota has this path. Maybe look there.

The error message is complaining about a template you have defined somewhere in your configuration (not an integration).

If the templates shown in the error messages are completely unfamiliar to you then they may be part of a package you installed. If you didn’t install any packages then the templates may be part of something you created but forgot about.

I have never installed a package, but I used inumerous integrations, including the early versions of the unsupported tasmota / ewewlink integrations. My yaml files are a mess and I could not find the said string.
Can I leave it as it is? How bad is to have thousands of these errors on my logs?

Are you using mqtt at all? These errors come from specific places templates are used:

  1. Template entities
  2. Templates in actions, automations, scripts
  3. Templates in integrations like rest, command line, mqtt, etc.
  4. Mqtt discovery (the one no one suspects because they don’t realize they use it)
1 Like

That string is likely to be in that YAML mess, not in your integrations because they contain python code (not Jinja2 templates).

If you are absolutely certain you have searched every possible YAML file (using the correct search string) then it may be petro’s fourth suggestion: MQTT Discovery.

Can old / unused appdaemon files from HACS play a part in this error? Or they have nothing to do with the rendering of templates?
And again, should I be worried about my RPI4 be overwhelmed by these erros? I got around 200 errors per hour regarding this?
It’s been like this for more than 6 months…

1 Like

As you said yourself, your files are a mess… Go, clean them up. It will get more and more complicated, to help you, if you can’t share your files, because “they’re a mess”. :slight_smile:

I wouldn’t worry about the log entries, if you had it like that for six months, it should have done any harm it could do right now. The only thing is the life span of your SD-card (if you don’t use a SSD). That will get smaller with every entry, bt other than that, I see no harm in it. I have sometimes more than thousand entries for one error in minutes, and even these don’t bring down my HA (and yes, I’m working on it to delete these entries beforehand) :smiley:

1 Like

@airtonac And, what’s the status? :wink:

Just left it as it is… Tried uninstalling a bunch of stuff. Nothing worked. I’m planing to start an installation from start, so it’s go away eventually. BTW I just posted about this new server. You can have a look at the post here:

Maybe you have some inputs :slight_smile:

Already answered! :smiley: :rofl: