Read json values in nested arrays?

I have a local electricity meter from which i can read the following json:

{"elapsedtime":535572852,"rssi":-68,"header":{"frameformat":3,"segmentation":0,"datalength":579,"client":65,"server":2179,"control":19,"hcs":"0xEB85","fcs":"0xE332","llc":"0xE6E700"},"apdu":{"tag":15,"liiap":"0x40000000","time":"00 "},"payload":[[["0000010000FF","07E5010B01113014FF8000FF"],["0100010700FF",1767,[0,"W"]],["0100020700FF",0,[0,"W"]],["0100030700FF",0,[0,"var"]],["0100040700FF",613,[0,"var"]],["01001F0700FF",17,[-1,"A"]],["0100330700FF",21,[-1,"A"]],["0100470700FF",47,[-1,"A"]],["0100200700FF",2327,[-1,"V"]],["0100340700FF",2354,[-1,"V"]],["0100480700FF",2346,[-1,"V"]],["0100150700FF",303,[0,"W"]],["0100160700FF",0,[0,"W"]],["0100170700FF",0,[0,"var"]],["0100180700FF",299,[0,"var"]],["0100290700FF",463,[0,"W"]],["01002A0700FF",0,[0,"W"]],["01002B0700FF",158,[0,"var"]],["01002C0700FF",0,[0,"var"]],["01003D0700FF",988,[0,"W"]],["01003E0700FF",0,[0,"W"]],["01003F0700FF",0,[0,"var"]],["0100400700FF",439,[0,"var"]],["0100010800FF",2444091,[0,"Wh"]],["0100020800FF",0,[0,"Wh"]],["0100030800FF",311,[0,"varh"]],["0100040800FF",807756,[0,"varh"]]]]}

I managed to read a single value like this:

 sensor:
   - platform: rest
     resource: http://emeter/data.json
     name: P3 Voltage
     scan_interval: 10
     value_template: '{{ value_json.payload[0][10][1] | float/10 }}'

But how do I read multiple values? I tried to understand the restful documentation but either it’s me or the docs that are lousy. This is my best try so far, it passes the configuration check but I get no data. I get: This entity does not have a unique ID, therefore its settings cannot be managed from the UI

sensor:
  - platform: rest
    name: electricity_meter
    scan_interval: 10
    json_attributes:
      - payload
    resource: http://emeter/data.json
    value_template: '{{ value_json.states }}'
  - platform: template
    sensors:
      p1_voltage:
        friendly_name: 'P1 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][8][1] }}'
      p2_voltage:
        friendly_name: 'P2 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][9][1] }}'
      p3_voltage:
        friendly_name: 'P3 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][10][1] }}'

Which is nothing to worry about.

It’s only letting you know that because you created the sensors manually in YAML you can’t edit them from the UI. Which, as you can use YAML, is no great loss.

EDIT: as to why you are getting no data, I’m not sure. Your paths look correct. Try this in the template editor:

{{ state_attr('sensor.electricity_meter', 'payload') }}
{{ state_attr('sensor.electricity_meter', 'payload')[0][8][1] }}

The first template result in nothing, the second template yields: UndefinedError: None has no element 0

Checkin my logs I get:

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 462, in async_render_to_info
    render_info._result = self.async_render(variables, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 355, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'attributes'
2021-01-11 17:52:25 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ states.sensor.electricity_meter.attributes["payload"][0][8][1] }}")' for attribute '_state' in entity 'sensor.p1_voltage'
2021-01-11 17:52:25 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ states.sensor.electricity_meter.attributes["payload"][0][9][1] }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 384, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'None' has no attribute 'attributes'

I’ll try to remove the attributes

Seems like i fixed myself…

sensor:
  - platform: rest
    resource: http://192.168.1.233/data.json
    name: electricity_meter
    scan_interval: 10
    value_template: 'OK'
    json_attributes:
      - payload
  - platform: template
    sensors:
      p1_voltage:
        friendly_name: 'P1 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][8][1] | float/10 }}'
      p2_voltage:
        friendly_name: 'P2 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][9][1] | float/10 }}'
      p3_voltage:
        friendly_name: 'P3 Voltage'
        value_template: '{{ states.sensor.electricity_meter.attributes["payload"][0][10][1] | float/10 }}'

It might be the mDNS service provided on http://emeter/data.json that Home assistant didn’t like:

2021-01-12 07:39:29 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:39:29 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:42:34 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:42:34 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:45:43 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:45:43 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:48:48 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:48:48 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:51:53 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:51:53 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:54:58 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:54:58 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 07:58:03 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 07:58:03 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 08:01:08 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 08:01:08 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 08:04:13 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 08:04:13 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.
2021-01-12 08:07:18 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://emeter/data.json failed with [Errno -3] Try again
2021-01-12 08:07:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet. Retrying in 180 seconds.

Using ip-address with numbers or http://emeter.local/data.json seems to have fixed the issue.