Detect Change
This subflow allows you to periodically monitor a website for any content changes.
It has 3 outputs. Output #1 gets triggered when a website is first fetched. Output #2 is triggered if no content was changed.
Output #3 is the one you most likely will want to hook up. It is triggered when content changes.
[{"id":"f8132144.82ac78","type":"subflow","name":"Detect Change (2)","info":"","category":"","in":[{"x":40,"y":240,"wires":[{"id":"afa1952f.7b562"}]}],"out":[{"x":1100,"y":400,"wires":[{"id":"626a1836.74007","port":0}]},{"x":1260,"y":480,"wires":[{"id":"5fee0fe4.0b584","port":0}]},{"x":1260,"y":640,"wires":[{"id":"251da517.5d034a","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"cc7361c3.842248","type":"switch","z":"f8132144.82ac78","name":"","property":"payload.length","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":670,"y":460,"wires":[["41e133b.c63f44c"],["b556be71.9b0228"]]},{"id":"41e133b.c63f44c","type":"function","z":"f8132144.82ac78","name":"","func":"return {\n payload: {},\n complete: true\n};","outputs":1,"noerr":0,"x":775,"y":420,"wires":[["54cab0bf.887278"]],"icon":"node-red/swap.svg","l":false},{"id":"54cab0bf.887278","type":"join","z":"f8132144.82ac78","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":890,"y":360,"wires":[["7b270791.e05a28"]]},{"id":"b556be71.9b0228","type":"function","z":"f8132144.82ac78","name":"","func":"return {\n payload: {\n old_value: msg.payload[0].content\n },\n complete: true\n};","outputs":1,"noerr":0,"x":775,"y":500,"wires":[["bf06b28a.ab182"]],"icon":"node-red/swap.svg","l":false},{"id":"bf06b28a.ab182","type":"join","z":"f8132144.82ac78","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":890,"y":560,"wires":[["4ff46477.430b24"]]},{"id":"4ff46477.430b24","type":"switch","z":"f8132144.82ac78","name":"","property":"payload.new_value","propertyType":"msg","rules":[{"t":"eq","v":"payload.old_value","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1010,"y":560,"wires":[["382a35eb.f61a72","5fee0fe4.0b584"],["382a35eb.f61a72","251da517.5d034a"]]},{"id":"ec3b1382.57965","type":"function","z":"f8132144.82ac78","name":"","func":"return {\n topic: msg.topic,\n url: msg.url,\n params: {\n $url: msg.url\n },\n payload: {\n new_value: msg.payload\n }\n};","outputs":1,"noerr":0,"x":75,"y":460,"wires":[["54cab0bf.887278","da17ecff.d5d3","adbf2b1b.e0dc18"]],"icon":"node-red/swap.svg","l":false},{"id":"da17ecff.d5d3","type":"sqlite","z":"f8132144.82ac78","mydb":"","sqlquery":"prepared","sql":"SELECT content FROM change_detection WHERE url = $url;","name":"","x":430,"y":460,"wires":[["cc7361c3.842248"]]},{"id":"adc647ef.a25218","type":"actionflows","z":"f8132144.82ac78","info":"","untilproptype":"num","proptype":"msg","name":"parse","prop":"loop","untilprop":0,"until":"gt","loop":"none","scope":"protected","perf":false,"seq":false,"x":370,"y":240,"wires":[["ec3b1382.57965"]]},{"id":"52eea47b.4f13ec","type":"sqlite","z":"f8132144.82ac78","mydb":"","sqlquery":"prepared","sql":"INSERT INTO change_detection (url, content) VALUES ($url, $content);","name":"","x":1070,"y":360,"wires":[[]]},{"id":"bfb43aba.6c6bc8","type":"http request","z":"f8132144.82ac78","name":"","method":"use","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":275,"y":240,"wires":[["adc647ef.a25218"]],"l":false},{"id":"afa1952f.7b562","type":"change","z":"f8132144.82ac78","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"method","pt":"msg","to":"GET","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":95,"y":240,"wires":[["313eec1d.10af74"]],"l":false},{"id":"313eec1d.10af74","type":"actionflows","z":"f8132144.82ac78","info":"","untilproptype":"num","proptype":"msg","name":"http","prop":"loop","untilprop":0,"until":"gt","loop":"none","scope":"protected","perf":false,"seq":false,"x":190,"y":240,"wires":[["bfb43aba.6c6bc8"]]},{"id":"7b270791.e05a28","type":"function","z":"f8132144.82ac78","name":"","func":"msg.params['$content'] = msg.payload.new_value;\nreturn msg;","outputs":1,"noerr":0,"x":975,"y":360,"wires":[["52eea47b.4f13ec","626a1836.74007"]],"icon":"node-red/swap.svg","l":false},{"id":"39483707.0b08d","type":"function","z":"f8132144.82ac78","name":"CREATE TABLE query","func":"return {\n topic:\n 'BEGIN TRANSACTION;' + \n 'CREATE TABLE IF NOT EXISTS change_detection (' + \n 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' +\n 'url TEXT NOT NULL UNIQUE, ' +\n 'content TEXT NOT NULL, ' +\n \"created_at INTEGER(4) NOT NULL DEFAULT (strftime('%s', 'now')), \" +\n 'updated_at INTEGER' +\n ');' +\n 'CREATE UNIQUE INDEX IF NOT EXISTS idx_change_detection_url ON change_detection(url);' +\n 'COMMIT;'\n};","outputs":1,"noerr":0,"x":260,"y":40,"wires":[["83db0684.97804"]]},{"id":"83db0684.97804","type":"sqlite","z":"f8132144.82ac78","mydb":"","sqlquery":"batch","sql":"","name":"","x":430,"y":40,"wires":[[]]},{"id":"cbd745e6.040678","type":"actionflows_in","z":"f8132144.82ac78","name":"#deployed","priority":"50","links":[],"scope":"global","x":80,"y":40,"wires":[["39483707.0b08d","9b03900.cafec7"]]},{"id":"9b03900.cafec7","type":"actionflows_out","z":"f8132144.82ac78","name":"#deployed","links":[],"x":230,"y":80,"wires":[]},{"id":"382a35eb.f61a72","type":"sqlite","z":"f8132144.82ac78","mydb":"","sqlquery":"prepared","sql":"UPDATE change_detection SET updated_at = strftime('%s', 'now'), content = $content WHERE url = $url;","name":"","x":1230,"y":560,"wires":[[]]},{"id":"adbf2b1b.e0dc18","type":"function","z":"f8132144.82ac78","name":"","func":"msg.params['$content'] = msg.payload.new_value;\nreturn msg;","outputs":1,"noerr":0,"x":495,"y":560,"wires":[["bf06b28a.ab182"]],"icon":"node-red/swap.svg","l":false},{"id":"626a1836.74007","type":"change","z":"f8132144.82ac78","name":"","rules":[{"t":"delete","p":"params","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":400,"wires":[[]],"l":false},{"id":"5fee0fe4.0b584","type":"change","z":"f8132144.82ac78","name":"","rules":[{"t":"delete","p":"params","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1195,"y":480,"wires":[[]],"l":false},{"id":"251da517.5d034a","type":"change","z":"f8132144.82ac78","name":"","rules":[{"t":"delete","p":"params","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1195,"y":640,"wires":[[]],"l":false},{"id":"14e93799.01f2a","type":"sqlite","z":"f8132144.82ac78","mydb":"","sqlquery":"fixed","sql":"DELETE FROM change_detection WHERE (updated_at IS NULL AND strftime('%s', 'now') - created_at > 172800) OR (strftime('%s', 'now') - updated_at > 172800);","name":"","x":790,"y":40,"wires":[[]]},{"id":"6c0a23e2.afd9e4","type":"inject","z":"f8132144.82ac78","name":"","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":false,"onceDelay":0.1,"x":695,"y":40,"wires":[["14e93799.01f2a"]],"l":false}]