{
 "name": "n8n of the week #1: n8n workflow #1: the website watcher that only speaks up when something changes",
 "nodes": [
  {
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "minutes",
       "minutesInterval": 5
      }
     ]
    }
   },
   "id": "f9d7e47c-96ca-591c-8eac-f3d075a27313",
   "name": "Every 5 minutes",
   "position": [
    0,
    0
   ],
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2
  },
  {
   "parameters": {
    "url": "https://example.com",
    "sendHeaders": true,
    "headerParameters": {
     "parameters": [
      {
       "name": "User-Agent",
       "value": "n8n workflow (+https://daniele-michelin.com/n8n-workflows/)"
      }
     ]
    },
    "options": {
     "timeout": 20000,
     "response": {
      "response": {
       "fullResponse": true,
       "neverError": true
      }
     }
    }
   },
   "id": "eb54b24a-f1b8-5474-8ee7-418209cefe98",
   "name": "Check website",
   "position": [
    240,
    0
   ],
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "onError": "continueRegularOutput"
  },
  {
   "parameters": {
    "mode": "runOnceForAllItems",
    "jsCode": "const url = 'https://example.com';            // ← your website\nconst r = $input.first().json;\nconst up = !r.error && r.statusCode >= 200 && r.statusCode < 400;\nconst mem = $getWorkflowStaticData('global'); // survives between runs (active workflows only)\nconst was = mem.up !== false;                 // the first run counts as \"up\"\nmem.up = up;\nif (up === was) return [];                    // nothing changed: stay quiet\nreturn [{ json: {\n  title: up ? 'Website is back' : 'Website is down',\n  message: up ? `${url} answers again (HTTP ${r.statusCode}).`\n              : `${url} does not answer: ${r.error ? (r.error.message || 'no connection') : 'HTTP ' + r.statusCode}`,\n  click: url, tags: [up ? 'white_check_mark' : 'rotating_light'] } }];"
   },
   "id": "10d34651-038a-515a-8c43-53a1e90d16f2",
   "name": "Status changed?",
   "position": [
    480,
    0
   ],
   "type": "n8n-nodes-base.code",
   "typeVersion": 2
  },
  {
   "parameters": {
    "method": "POST",
    "url": "https://ntfy.sh",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify({ topic: 'your-secret-topic', title: $json.title, message: $json.message, click: $json.click, tags: $json.tags, attach: $json.attach }) }}",
    "options": {
     "timeout": 15000
    }
   },
   "id": "080fef1c-c6a0-5a83-85ea-7fcbc32a5cab",
   "name": "Push to phone",
   "position": [
    720,
    0
   ],
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2
  }
 ],
 "connections": {
  "Every 5 minutes": {
   "main": [
    [
     {
      "node": "Check website",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Check website": {
   "main": [
    [
     {
      "node": "Status changed?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Status changed?": {
   "main": [
    [
     {
      "node": "Push to phone",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "pinData": {},
 "meta": {
  "source": "https://daniele-michelin.com/n8n-workflows/"
 }
}