Every time this comes up I came never find the latest post I had written. You can use the HA endpoints created by the NR custom component.
Really rough steps.
- Store all the received data
- On connection to HA send all the discovery messages of the stored data.
- When new data arrives send updated values, if the id is not in the discovery cache send discovery payload first
Here’s a function node I use to create sensors for my monthly internet usage. Which is sent to an API node.
[5,4,3,2,1,0].forEach((month, index) => {
const current = new Date();
current.setMonth(current.getUTCMonth()-(month+1));
const name = current.toLocaleString('default', { month: 'long' });
msg.payload = { data: {
type: "nodered/discovery",
server_id: "noderedserver",
node_id: `xfinity_month_usage_${month}`,
component: "sensor",
config: {
name
}
}};
node.send(msg);
msg.payload = { data: {
type: "nodered/entity",
server_id: "noderedserver",
node_id: `xfinity_month_usage_${month}`,
state: msg.usageMonths[index].totalUsage,
}};
node.send(msg);
});
node.done();