I've been using this approach, below, for managing the attributes of my various sensors from within a function block. It has associated nodes to read from and write to disk. Each device definition can be converted to MQTT topics. I have a variety of devices including old X-10s and xbee radios.
Whenever I create a new device, I update this list (in a function block) and push the write-to-disk node. Then when node-red restarts, it reads from that disk file.
var devices = {
payload : [
{
"building": "home",
"room": "bedroom",
"device": "light",
"tech": "X10",
"id": "M5",
"type": "actuator",
"adc": "",
"feed": "",
"desc": "x10 device and lamp"
},
{
"building": "home",
"room": "stairwell",
"device": "light",
"tech": "LIFX",
"id": "lifx1",
"type": "actuator",
"adc": "",
"feed": "",
"desc": "Wifi LED light bulb"
},
{
"building": "home",
"room": "livingroom",
"device": "shelf-light",
"tech": "LIFX",
"id": "lifx2",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "Wifi LED light bulb"
},
{
"building": "home",
"room": "livingroom",
"device": "cieling-light",
"tech": "LIFX",
"id": "lifx3",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "Wifi LED light bulb"
},
{
"building": "home",
"room": "office",
"device": "light",
"tech": "X10",
"id": "M8",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "x10 device and lamp"
},
{
"building": "home",
"room": "guestroom",
"device": "light",
"tech": "X10",
"id": "M7",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "x10 device and lamp"
},
{
"building": "home",
"room": "livingroom",
"device": "light",
"tech": "X10",
"id": "M1",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "x10 device and lamp"
},
{
"building": "home",
"room": "kitchen",
"device": "light",
"tech": "X10",
"id": "C4",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "x10 device and lamp"
},
{
"building": "home",
"room": "garage",
"device": "light",
"tech": "wemo",
"id": "we4",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "wemo wifi switch and lamp"
},
{
"building": "home",
"room": "garage",
"device": "relay",
"tech": "ESP",
"id": "E43",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "Wemos ESP device and 120VAC relay"
},
{
"building": "home",
"room": "kitchen",
"device": "switch",
"tech": "HZ",
"id": "H1",
"adc": "",
"feed": "",
"type": "sensor",
"desc": "Capacitive switch on ESP Huzzah"
},
{
"building": "home",
"room": "backporch",
"device": "tl-ms-0",
"tech": "XB",
"id": "2",
"adc": "0,1,4,R",
"feed": "",
"adjust": "1,1,1,1",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "kitchen",
"device": "tl-ms-1",
"tech": "XB",
"id": "13",
"adc": "0,1,2,3,R",
"feed": "",
"adjust": "1,1,1,1",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "garage",
"device": "tl-ms-1",
"tech": "XB",
"id": "29",
"adc": "0,1,2,3,R",
"feed": "",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "bedroom",
"device": "tl-ms-1",
"tech": "XB",
"id": "12",
"adc": "0,1,2,3,R",
"feed": "",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "bathroom",
"device": "tl-ms-1",
"tech": "XB",
"id": "15",
"adc": "0,1,2,3,R",
"feed": "",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "office",
"device": "tl-ms-1",
"tech": "XB",
"id": "23",
"adc": "0,1,2,3,R",
"feed": "",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "guestroom",
"device": "tl-ms-1",
"tech": "XB",
"id": "9",
"adc": "0,1,2,3,R",
"feed": "25133",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "bedroom",
"device": "tl-ms-1",
"tech": "XB",
"id": "8",
"adc": "0,1,2,3,R",
"feed": "25131",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "office",
"device": "tl-ms-1",
"tech": "XB",
"id": "7",
"adc": "0,1,2,3,R",
"feed": "24660",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "dining",
"device": "tl-gas",
"tech": "XB",
"id": "5",
"adc": "0,1,2,3,R",
"feed": "10267",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "diningroom",
"device": "light",
"tech": "X10",
"id": "M14",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "x10 wall switch"
},
{
"building": "home",
"room": "porch",
"device": "tl-temp",
"tech": "XB",
"id": "2",
"adc": "0,1,R",
"feed": "9709",
"type": "sensor",
"desc": "xbee based sensor board"
},
{
"building": "home",
"room": "laundry",
"device": "switch",
"tech": "ESP",
"id": "E42",
"adc": "",
"feed": "",
"type": "actuator",
"desc": "Wemos ESP device and 120VAC relay"
}
]
};
// set a global context to retrieve later
global.set("devices",devices.payload)
var s = JSON.stringify(devices.payload);
msg.payload=s;
return msg;