Save & reload context data for node-red-contrib-google-smarthome
If the node-red-contrib-google-smarthome
server is restarted, because a full node-RED deploy/restart flows/system reboot has been made, the nodes will revert back to their default state.
To overcome this, this subflow saves their current states to context, and again injects them to regain their former state if the smarthome server restarts.
After importing the flow, the subflow can be found at the bottom of the Google Smarthome
palette category (left sidebar).
- Drag the node onto the workspace, and connect this node's output to the input of the Smarthome Management node. Then connect the output from the Smarthome Management node to the input of this node.
In the Smarthome Management node, in the section
set_state message delay (s)
, enter 2, so that 2 seconds after a verbal command, the node will send a state message which will be then saved by the subflow.The subflow is currently set to save the context to Memory, which of course would not survive a system reboot. It can however be changed to the Filesystem, by opening the subflow and making the change to both of the 'change' nodes.
[{"id":"7a338e422c069c30","type":"subflow","name":"Smarthome context","info":"Restores the state of Smarthome nodes, whenever the server or system is restarted.\r\n\r\nTo use, connect the output from the Smarthome Management node to the input of this node, and this node's output to the input of the Management node.","category":"Google_SmartHome-function","in":[{"x":95,"y":100,"wires":[{"id":"31fb7d45ee0a3b30"}]}],"out":[{"x":740,"y":135,"wires":[{"id":"1d78146411a07660","port":0}]}],"env":[],"meta":{},"color":"#C0DEED","icon":"node-red-contrib-google-smarthome/google-smarthome.png"},{"id":"70348fb8a6f132ce","type":"switch","z":"7a338e422c069c30","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"set_state","vt":"str"},{"t":"eq","v":"get_state","vt":"str"},{"t":"eq","v":"management","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":315,"y":100,"wires":[["c4b688524f225228"],["c4b688524f225228"],["4903704874eab7d0"]]},{"id":"4903704874eab7d0","type":"switch","z":"7a338e422c069c30","name":"","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":135,"wires":[["1d78146411a07660"],[]]},{"id":"1d78146411a07660","type":"change","z":"7a338e422c069c30","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"smarthome","tot":"global","dc":true},{"t":"set","p":"topic","pt":"msg","to":"set_state","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":605,"y":135,"wires":[[]]},{"id":"c4b688524f225228","type":"change","z":"7a338e422c069c30","name":"Save context","rules":[{"t":"set","p":"smarthome","pt":"global","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":95,"wires":[[]]},{"id":"31fb7d45ee0a3b30","type":"rbe","z":"7a338e422c069c30","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":190,"y":100,"wires":[["70348fb8a6f132ce"]]},{"id":"b3ba4f16f30255b7","type":"subflow:7a338e422c069c30","z":"217df193.d774ce","name":"","x":690,"y":680,"wires":[[]]}]