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] }}'
1 post - 1 participant