Hi there,
I am trying to get some data from an API (brewfather) and pass that to sensors on home assistant. The API gives a response like this.
The array changes size depending on the number of batches in that state in Brewfather (API)
[{"_id":"bklHukGNhaFUOzWgJ24bDWx9gcz3S4","name":"Batch","batchNo":2,"status":"Completed","brewer":null,"brewDate":1607172885991,"recipe":{"name":"Vienna Lager - 17l"},"fermentationStartDate":1607172885991},{"_id":"15fuw3HnEcKoXOlcGHjn8wtCEaalLW","name":"Batch","batchNo":1,"status":"Completed","brewer":null,"brewDate":1606003200000,"recipe":{"name":"DH - American Pale 17l"},"fermentationStartDate":1606003200000}]
I am trying to pull the name from the batch and pass it to home assistant, using the HA addon.
now this would be all fine, but there is no guarantee there will be 3 elements in the array so i get errors when the array doesn’t have 3 elements.
So I have tried to build a function that iterates through the array, but passes “empty” if that index in the array is empty
I think i have something wrong with my function
var outarr = ["Empty","Empty","Empty"];
for (var i = 0; i < msg.payload.length; i++) {
// var newMsg = {};
// newMsg.payload = msg.payload[i];
outarr [i] = msg.payload[i];
//node.send(newMsg);
}
return [outarr [1], outarr[2], outarr[3]];
Can anyone point me in the right direction.