RESTful Sensor help

Hey everyone,

I am trying to put together a rest sensor to pull in data for my area’s train system, but I cant even seem to get the example code working. When I type (straight from the HA website):

sensor:

  - platform: rest
    resource: http://ip.jsontest.com
    name: External IP
    value_template: '{{ value_json.ip }}'

into the template editor, I get the error “Error rendering template: UndefinedError: ‘value_json’ is Undefined”. This is the same error I would get when trying out my custom code, so I am wondering if there is a problem with the way my HA is handling these requests.

Any thoughts on what I am doing wrong, or how I could troubleshoot through this? For reference I am on hass.io on a Rpi 3 B, running HA 0.97.2.

You can’t put the entire sensor definition into the template editor, it’s only for templates. If you wanted test the value_template you could do something like this in the template editor:

{% set value_json = {"ip": 1234} %}
{{ value_json.ip }}

That will print 1234 in the template editor. Just copy and paste the JSON values you want to use in place of {"ip": 1234} and you can check the results of using value_json.

1 Like