Rest Sensor - JSON parsing

I am exporting data from my google sheet into an json output format which is something like this (see below) using the following yaml sensor below but it’s not working. I’m trying to get the value of c1_value.

Anybody can help me out here?

  - platform: file
    name: EOS_file
    file_path: "/home/homeassistant/.homeassistant/scripts/sort.json"
    value_template: "{{value_json['name']['C1_Value']['value']}}"
    unit_of_measurement: "EUR"

Error:
Error parsing value: 'list object' has no attribute 'name'

JSON output:

[{"name":"C1_Value","value":1465.7083623303001},{"name":"C1_Profit","value":692.7883623303002},{"name":"C1_Change","value":0.8963260910964915},{"name":"C2","value":"REQ"},{"name":"C2_Value","value":1259.3023474},{"name":"C2_Profit","value":-26.31865259999995},{"name":"C2_Change","value":-0.02047154845790474},{"name":"C3","value":"POWR"},]

The problem is you have an array, which you want to get one entry from.

Probably you need a value template more like:

value_template: >-
  {% for state in value_json -%}
    {% if state.name == "C1_Value" %}
    {{ state.value }}
    {% endif %}
  {%- endfor -%}
1 Like

@Tinkerer I’m also trying to get the sensor dynmically from the json string ie. C1_Value

Can this be done?

{“name”:“C1_Value”,“value”:1465.7083623303001},

The example above uses state.name to extract the value of the name field - just use that.