I have an endpoint for a smart battery capacity tester device.
Currently it’s outputting the values of the 4 tester slots for 1 unit. I have some control over the endpoint but the code is VERY simplified and just using some array → json conversion. Below is an example of the json data.
[{"CDModuleViewID":"741","CDUnitID":"245","CDModuleID":"1096","CycleState":"7","CycleTime":"6492","BatteryBarcode":"B01987","RestartCycle":"0","MilliOhms":"145","Capacity":"1869","BatteryInitialTemp":"0","BatteryHighestTemp":"0","BatteryCurrentTemp":"0","DischargeAmps":"0","BatteryInitialVoltage":"4.14","BatteryCurrentVoltage":"4.15","BatteryFaultCodeID":"0","LastCommunicationTime":"2022-02-17 14:22:41"},{"CDModuleViewID":"742","CDUnitID":"245","CDModuleID":"1097","CycleState":"7","CycleTime":"6475","BatteryBarcode":"B01985","RestartCycle":"0","MilliOhms":"131","Capacity":"1933","BatteryInitialTemp":"0","BatteryHighestTemp":"0","BatteryCurrentTemp":"0","DischargeAmps":"0","BatteryInitialVoltage":"4.14","BatteryCurrentVoltage":"4.14","BatteryFaultCodeID":"0","LastCommunicationTime":"2022-02-17 14:22:41"},{"CDModuleViewID":"743","CDUnitID":"245","CDModuleID":"1098","CycleState":"7","CycleTime":"7774","BatteryBarcode":"B01991","RestartCycle":"0","MilliOhms":"263","Capacity":"2081","BatteryInitialTemp":"20","BatteryHighestTemp":"26","BatteryCurrentTemp":"16","DischargeAmps":"0","BatteryInitialVoltage":"4.16","BatteryCurrentVoltage":"4.13","BatteryFaultCodeID":"0","LastCommunicationTime":"2022-02-17 14:22:41"},{"CDModuleViewID":"744","CDUnitID":"245","CDModuleID":"1099","CycleState":"7","CycleTime":"6642","BatteryBarcode":"B01989","RestartCycle":"0","MilliOhms":"142","Capacity":"2054","BatteryInitialTemp":"18","BatteryHighestTemp":"25","BatteryCurrentTemp":"17","DischargeAmps":"0","BatteryInitialVoltage":"4.16","BatteryCurrentVoltage":"4.12","BatteryFaultCodeID":"0","LastCommunicationTime":"2022-02-17 14:22:41"}]
What I am trying to do is create 1 “device” for each CDUnitID (in this case it’s 245, the only tester reporting) so I could do 1 device per endpoint or if i could get multiple devices to create if i have more units, i could do that. But for now, lets keep it simple. It’s 1 unit. There are 4 slots on unit 1. I would like to have the various slots be attributes on said device.
So my device → attributes structure would look like.
Unit1
- Slot1 State = the value of cycle state for the json row with CDModuleID 1096 or [0] in the elements.
- Slot2 State = the value of cycle state for the json row with CDModuleID 1097 or [1] in the elements.
- Slot3 State = the value of cycle state for the json row with CDModuleID 1098 or [2] in the elements.
- Slot4 State = the value of cycle state for the json row with CDModuleID 1099 or [3] in the elements.
I have tried to create a rest sensor. Below is my failed attempt.
rest:
- resource: http://<removed>/
sensor:
- name: "Tester 1"
json_attributes_path: "$"
value_template: "OK"
json_attributes:
- "CycleState"
- "BatteryBarcode"
But I get a very odd error in the log.
2022-01-23 05:17:21 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: failed with
no idea what comes after “with” because there isn’t anything.
If i exec into the homeassistant container and run curl it returns data.
Any suggestions? Thanks!