Skip to content

TemplateError('UndefinedError: 'value_json' is undefined')  #99504

Description

@rgerbranda

The problem

I used the code from the documentation page. The picture variable gives an error. value_json is not recognized as a function.

What version of Home Assistant Core has the issue?

2023.8.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

https://www.home-assistant.io/integrations/sensor.rest/

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

rest:
  - resource: "https://abc.be"
    scan_interval: 3600
    sensor:
    - name: RBFA uit
      value_template: >
         {{ value_json["data"]["teamCalendar"][0]["awayTeam"]["name"] }}
      picture: "{{ value_json['data']['teamCalendar'][0]['awayTeam']['logo'] }}"

Anything in the logs that might be useful for us?

2023-09-02 15:29:11.302 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ value_json['data']['teamCalendar'][0]['awayTeam']['logo'] }}) renders=3>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 563, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2179, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.11/site-packages/jinja2/sandbox.py", line 303, in getitem
    return obj[argument]
           ~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'value_json' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 684, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 565, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'value_json' is undefined
2023-09-02 15:29:11.312 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('UndefinedError: 'value_json' is undefined') while processing template 'Template<template=({{ value_json['data']['teamCalendar'][0]['awayTeam']['logo'] }}) renders=5>' for attribute '_attr_entity_picture' in entity 'sensor.rbfa_uit'

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions