Unknown Error

New today —

Wed Feb 26 2020 13:08:43 GMT-0500 (Eastern Standard Time)
Error handling message: Unknown error
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 221, in async_render
return compiled.render(kwargs).strip()
File “/usr/local/lib/python3.7/site-packages/jinja2/environment.py”, line 1090, in render
self.environment.handle_exception()
File “/usr/local/lib/python3.7/site-packages/jinja2/environment.py”, line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File “/usr/local/lib/python3.7/site-packages/jinja2/_compat.py”, line 28, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
File “/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py”, line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: ‘binary_sensor’ is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/connection.py”, line 95, in async_handle
handler(self.hass, self, schema(msg))
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 254, in handle_render_template
state_listener()
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 242, in state_listener
msg[“id”], {“result”: template.async_render(variables)}
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 223, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: ‘binary_sensor’ is undefined

The error seems associated with a particular Lovelace View.

Any suggestions will be appreciated.

It seems you’re referencing a binary_sensor that doesn’t exist. How is that view defined? Does it reference a binary_sensor, and if so, is there a typo, or is there some reason the binary_sensor you expect to exist doesn’t?

Thanks, Phil.

Yes, seems like a missing binary_sensor.

Unfortunately, I have spent many hours searching for the elusive reference(s) to the missing binary_sensor in my lovelace files but cannot find it. Meanwhile, insteon, espHome, and zwave devices create “hidden” binary_sensor entities. In the process of deleteing some of the lovelace binary_sensor references (for testing) I have actually created even more errors.

What a mess.

Finally found it.
entities:
- entity: sensor.pi4_cpu_temp
name: cpu temp
icon: mdi:chip
style: |
:host { --paper-item-icon-color: {% if states(binary_sensor.pi4_cpu_hot) %} red; {% else %} steelblue; {% endif %} }

changed to:
:host { --paper-item-icon-color: {% if is_state(‘binary_sensor.pi4_cpu_hot’, ‘on’) %} red; {% else %} steelblue; {% endif %} }

states(‘binary_sensor.pi4_cpu_hot’) would also work.

Hours of trial and error might have been avoided if the error messages had included more. Debug level in logs didn’t help either. Oh well.

Thanks again, Phil.

Ah, I see. It was telling you the variable binary_sensor didn’t exist, and that’s because you didn’t have it quoted (to make it a string.)

I guess I didn’t look closely enough to see it wasn’t complaining about a particular binary_sensor entity ID (e.g., 'binary_sensor.blah_blah'. It would help in the future if you properly format error messages. As you posted them they were very difficult to read which made it easier to overlook stuff like this.)