Skip to content

Instantly share code, notes, and snippets.

@SamKirsch10
Created February 7, 2021 18:59
Show Gist options
  • Save SamKirsch10/96a82640d1baa0a40e6b6bfc7bb7d2e8 to your computer and use it in GitHub Desktop.
Save SamKirsch10/96a82640d1baa0a40e6b6bfc7bb7d2e8 to your computer and use it in GitHub Desktop.
Backup/Restore Z-Wave Devices Node-Red
[{"id":"b1dae23f.4c1df8","type":"tab","label":"Backup ZWave","disabled":false,"info":""},{"id":"c63c702d.146638","type":"ha-get-entities","z":"b1dae23f.4c1df8","server":"2c7b8494.4b702c","name":"Get initial zwave entities","rules":[{"property":"entity_id","logic":"starts_with","value":"zwave.","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":140,"y":220,"wires":[["b6ed1793.1fb048"]]},{"id":"9a58517a.10adb8","type":"inject","z":"b1dae23f.4c1df8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":120,"wires":[["c63c702d.146638"]]},{"id":"13a2784c.82a29","type":"file","z":"b1dae23f.4c1df8","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":810,"y":320,"wires":[[]]},{"id":"b6ed1793.1fb048","type":"split","z":"b1dae23f.4c1df8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":380,"y":220,"wires":[["54c77810.189ed"]]},{"id":"54c77810.189ed","type":"ha-get-entities","z":"b1dae23f.4c1df8","server":"2c7b8494.4b702c","name":"","rules":[{"property":"attributes.node_id","logic":"is","value":"payload.attributes.node_id","valueType":"msg"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":290,"y":320,"wires":[["18b3b95.1063f47"]]},{"id":"18b3b95.1063f47","type":"split","z":"b1dae23f.4c1df8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":320,"wires":[["746b21ad.227ee8"]]},{"id":"746b21ad.227ee8","type":"function","z":"b1dae23f.4c1df8","name":"","func":"var filename = \"/data/zwaveBackup/\" + msg.payload.attributes.node_id + \"/\" + msg.payload.entity_id + \".json\"\n\nmsg.filename = filename\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":320,"wires":[["13a2784c.82a29"]]},{"id":"2c7b8494.4b702c","type":"server","name":"Home Assistant","addon":true}]
[{"disabled":false,"id":"11b64989.a002f6","info":"","label":"Restore ZWave Namings","type":"tab"},{"id":"b9521b80.ebaf88","name":"","output_empty_results":false,"output_location":"found","output_location_type":"msg","output_results_count":1,"output_type":"array","rules":[{"logic":"is","property":"attributes.node_id","value":"payload.attributes.node_id","valueType":"msg"},{"logic":"is","property":"attributes.value_id","value":"payload.attributes.value_id","valueType":"msg"}],"server":"2c7b8494.4b702c","type":"ha-get-entities","wires":[["66f32a4f.0c3fe4"]],"x":270,"y":260,"z":"11b64989.a002f6"},{"crontab":"","id":"1697c7a0.b3c02","name":"","once":false,"onceDelay":0.1,"payload":"","payloadType":"date","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","topic":"","type":"inject","wires":[["8e4229a0.53d88"]],"x":200,"y":60,"z":"11b64989.a002f6"},{"depth":"2","folders":"*","hidden":false,"id":"8e4229a0.53d88","lstype":"files","name":"Get Backup Files","path":true,"pattern":"*.json","showWarnings":false,"single":true,"start":"/data/zwaveBackup/","stat":false,"type":"fs-file-lister","wires":[["9a466f59.f86cc"]],"x":170,"y":160,"z":"11b64989.a002f6"},{"addname":"","arraySplt":1,"arraySpltType":"len","id":"9a466f59.f86cc","name":"","splt":"\\n","spltType":"str","stream":false,"type":"split","wires":[["7cac41b3.7ec888"]],"x":390,"y":160,"z":"11b64989.a002f6"},{"action":"","from":"","id":"7cac41b3.7ec888","name":"","property":"","reg":false,"rules":[{"p":"payload","pt":"msg","t":"move","to":"filename","tot":"msg"}],"to":"","type":"change","wires":[["526ca80.9ee5f58"]],"x":550,"y":160,"z":"11b64989.a002f6"},{"chunk":false,"encoding":"none","filename":"","format":"utf8","id":"526ca80.9ee5f58","name":"","sendError":false,"type":"file in","wires":[["ee0cf3d1.40027"]],"x":750,"y":160,"z":"11b64989.a002f6"},{"action":"","id":"ee0cf3d1.40027","name":"","pretty":false,"property":"payload","type":"json","wires":[["b9521b80.ebaf88"]],"x":900,"y":160,"z":"11b64989.a002f6"},{"finalize":"","func":"var backUP_entity_id = msg.payload.entity_id\nvar backUP_friendly_name = msg.payload.attributes.friendly_name\nvar current_entity_id = msg.found[0].entity_id\nvar current_friendly_name = msg.found[0].attributes.friendly_name\n\nif ( current_entity_id == backUP_entity_id ) {\n if ( current_friendly_name == backUP_friendly_name ) {\n return null;\n } \n}\n\n\nreturn msg;","id":"66f32a4f.0c3fe4","initialize":"","name":"","noerr":0,"outputs":1,"type":"function","wires":[["f1b35916.156fb"]],"x":480,"y":260,"z":"11b64989.a002f6"},{"action":"","from":"","id":"f1b35916.156fb","name":"","property":"","reg":false,"rules":[{"p":"found[0].entity_id","pt":"msg","t":"move","to":"payload.original_entity_id","tot":"msg"}],"to":"","type":"change","wires":[["27331a3b.d2638e"]],"x":720,"y":260,"z":"11b64989.a002f6"},{"finalize":"","func":"return { \n \"payload\": {\n \"type\": \"config/entity_registry/update\",\n \"entity_id\": msg.payload.original_entity_id,\n \"name\": msg.payload.attributes.friendly_name,\n \"new_entity_id\": msg.payload.entity_id,\n \"icon\": null,\n \"area_id\": null,\n \"id\": Math.floor(Math.random() * 30) + 40\n }\n}","id":"27331a3b.d2638e","initialize":"// Code added here will be run once\n// whenever the node is deployed.\nnode.send({ \"payload\": {\n \"type\": \"auth\",\n \"access_token\": \"ACCESS_TOKEN_HERE\"\n }\n })","name":"","noerr":0,"outputs":1,"type":"function","wires":[["7ac94d7d.1a6944","312d7c6d.83486c"]],"x":940,"y":260,"z":"11b64989.a002f6"},{"active":true,"complete":"true","console":false,"id":"7ac94d7d.1a6944","name":"","statusType":"auto","statusVal":"","targetType":"full","tosidebar":true,"tostatus":false,"type":"debug","wires":[],"x":1070,"y":400,"z":"11b64989.a002f6"},{"client":"7a34784d.ca4c","id":"312d7c6d.83486c","name":"","server":"","type":"websocket out","wires":[],"x":1240,"y":260,"z":"11b64989.a002f6"},{"addon":true,"id":"2c7b8494.4b702c","name":"Home Assistant","type":"server"},{"id":"7a34784d.ca4c","path":"wss://HA_ENDPOINT/api/websocket","tls":"6c2c1c33.8d5fcc","type":"websocket-client","wholemsg":"false"},{"ca":"","caname":"","cert":"","certname":"","id":"6c2c1c33.8d5fcc","key":"","keyname":"","name":"","servername":"","type":"tls-config","verifyservercert":false}]
@SamKirsch10
Copy link
Author

SamKirsch10 commented Feb 7, 2021

Just update the restore file with your values for

ACCESS_TOKEN_HERE
HA_ENDPOINT
  • add node-red-contrib-fs do node red

@tlykken
Copy link

tlykken commented Feb 7, 2021

Great idea! I get this error when importing the restore flow. unknown: fs-file-lister Is there something else I need to import first?

@SamKirsch10
Copy link
Author

Sorry, updated previous comment. You will need node-red-contrib-fs for it to read back the files and restore

@tlykken
Copy link

tlykken commented Feb 7, 2021

Great, thank you!

@joaldes
Copy link

joaldes commented Jun 6, 2021

I'm also on the original zwave integration and will be migrating soon. Do these flows back up the original info so the original zwave integration can be re-loaded just in case there are problems with JS?

Or is this to help rename all the entities once JS is going?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment