Rest Sensor not visible (multiple sensors)

I’ve added a new sensor, which uses a third-party scaper API to get values. I know the API is working, as I can call it in from Postman with the same variables etc.

My config is:

logger:
  logs:
    homeassistant.components.rest.sensor: debug
 
rest:
  - resource: "https://api.browse.ai/v2/robots/xxxxxxxxxxxxxxxx/tasks/xxxxxxxxxxxxxxxxxxxxx"
    scan_interval: 43200
    authentication: basic
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    sensor:
      - name: "Tank Balance"
        value_template: "{{ value_json.result.capturedTexts }}"
        
  - resource: "https://www.boilerjuice.com/includes/priceChart.inc.php?a=1&ot=1&c=0&va=1&ex=1&d=2"
    scan_interval: 43200
    sensor: 
      - name: "Oil Price"
        value_template: "{{ value_json.rows[0].c[1].v }}"
    

The Oil Price is showing, correctly and updating, but the Tank Balance isn’t appearing as a device, or entity under Rest. I’ve tried switching the entries in the config file. And each time I’m making a change (tinkering) I reboot HA, not just reload.
Nothing seems to be appearing in the logs either.

The value_template for Tank Balance should reference [‘Tank Account’], but when I include that, I get the following error:

Invalid config for 'rest' at configuration.yaml, line 34: invalid template (TemplateSyntaxError: expected name or number) for dictionary value 'rest->0->sensor->0->value_template', got "{{ value_json.result.capturedTexts.['Tank Account'] }}", please check the docs at https://www.home-assistant.io/integrations/rest

Any thoughts/help gratefully received :slight_smile:

I believe I’ve fixed the second issue. The config should be:

value_template: "{{ value_json.result.capturedTexts['Tank Account'] }}"

(At least, I’m now not getting a config error, just Tank Balance isn’t showing in the devices/entities

It won’t show as a device at all, but it should show as an entity under the RESTful integration and under Developer Tools / States as sensor.tank_balance. If it doesn’t, there should be an error in the logs.

As you’ve discovered, there are two ways to reference items in a dictionary:

# dot notation
{{ value_json.foo.bar }}
# bracket notation
{{ value_json['foo']['bar']

You can mix and match, but you had a dot and a bracket. Bracket notation is always safer, so I’d use:

value_template: "{{ value_json['result']['capturedTexts']['Tank Account'] }}"

What is the JSON returned from the resource? We can’t check your template if we can’t see the input.

You don’t need to restart after the first use of rest: has been loaded, just do Developer Tools / YAML and click the REST ENTITIES link.

Ah - thank you!
Found it in the Developer Tools → States!
All working as expected now :slight_smile:

1 Like