Local Settings Persistance Subflow
Adds a simple persistent storage mechanism in the form of a subflow, usage is simple and explained in the subflow description.
[{"id":"4b8dcadd.1afa44","type":"subflow","name":"Settings","info":"Persist settings in a flat file.\n\nIf msg.clearAll is set to true, the settings are truncated.\n\nSending a topic of \"get\" will return the property you've named in the payload.\n\nAny other topic will be treated as a property and the payload will be saved to the settings file.","in":[{"x":40,"y":220,"wires":[{"id":"fd773621.54f638"}]}],"out":[{"x":380,"y":160,"wires":[{"id":"fd773621.54f638","port":0}]}]},{"id":"da4b9b0.096e468","type":"file in","z":"4b8dcadd.1afa44","name":"Load File","filename":"persist/settings.json","format":"utf8","chunk":false,"sendError":true,"x":240,"y":40,"wires":[["3dbc537d.eabbac"]]},{"id":"3dbc537d.eabbac","type":"switch","z":"4b8dcadd.1afa44","name":"","property":"error","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":60,"wires":[["c6fa089c.c66448"],["a70ce91e.334e88"]]},{"id":"9b5416a4.2e6ba8","type":"file","z":"4b8dcadd.1afa44","name":"Create File","filename":"persist/settings.json","appendNewline":false,"createDir":true,"overwriteFile":"false","x":910,"y":20,"wires":[]},{"id":"e8d03084.ecada","type":"json","z":"4b8dcadd.1afa44","name":"JSON Encode","property":"payload","action":"str","pretty":false,"x":380,"y":260,"wires":[["b8af204c.779fd"]]},{"id":"9eecb642.afe988","type":"inject","z":"4b8dcadd.1afa44","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":90,"y":40,"wires":[["da4b9b0.096e468"]]},{"id":"f144822b.17fe7","type":"change","z":"4b8dcadd.1afa44","name":"","rules":[{"t":"set","p":"persistant_settings","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":120,"wires":[[]]},{"id":"a70ce91e.334e88","type":"json","z":"4b8dcadd.1afa44","name":"JSON Decode","property":"payload","action":"","pretty":false,"x":660,"y":120,"wires":[["f144822b.17fe7"]]},{"id":"fd773621.54f638","type":"function","z":"4b8dcadd.1afa44","name":"","func":"if(msg.clearAll === true){\n flow.set('persistant_settings', {});\n return [msg, {payload: {}}];\n}\n\nvar settings = flow.get('persistant_settings') || {};\n\nif(msg.topic == 'get'){\n msg.payload = settings[msg.payload] || null;\n return [msg, null]\n}else{\n settings[msg.topic] = msg.payload;\n flow.set('persistant_settings', settings);\n return [msg, {payload: settings}];\n}","outputs":2,"noerr":0,"x":170,"y":220,"wires":[[],["e8d03084.ecada"]]},{"id":"b8af204c.779fd","type":"file","z":"4b8dcadd.1afa44","name":"Update File","filename":"persist/settings.json","appendNewline":false,"createDir":true,"overwriteFile":"true","x":590,"y":260,"wires":[]},{"id":"c6fa089c.c66448","type":"change","z":"4b8dcadd.1afa44","name":"Initialize Settings Object","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":20,"wires":[["9b5416a4.2e6ba8","a70ce91e.334e88"]]}]