{
  "name": "09 Website monitor: alert only when status changes",
  "nodes": [
    {
      "id": "f7353acb-f42b-4826-b29d-1d3a45e96714",
      "name": "Every 5 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      }
    },
    {
      "id": "316c72be-1217-40d6-9b38-ac28773a2c87",
      "name": "Address to monitor",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        300
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "u",
              "name": "url",
              "value": "https://example.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "e62f7d52-5e9d-4df7-a431-da43e1aa5a27",
      "name": "Request site",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {
          "timeout": 10000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "id": "302302aa-049d-4a66-ac9d-3b6e2a3f0e5f",
      "name": "Previous status",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        720,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "site_status"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "url",
              "condition": "eq",
              "keyValue": "={{ $('Address to monitor').item.json.url }}"
            }
          ]
        },
        "returnAll": true
      },
      "alwaysOutputData": true
    },
    {
      "id": "1395c875-5a16-4b59-a4e2-f332c42d7c55",
      "name": "Changed?",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "jsCode": "const url = $('Address to monitor').first().json.url;\nconst r = $('Request site').first().json;\nconst now = (r.statusCode >= 200 && r.statusCode < 400) ? 'up' : 'down';\nconst detail = r.statusCode ? `HTTP ${r.statusCode}` : (r.error?.message || 'no response');\nconst prev = $input.first().json.last_status || 'up';\nreturn [{ json: { url, now, prev, detail, changed: now !== prev, row: $input.first().json.id || null } }];"
      }
    },
    {
      "id": "8c6bda0e-5431-464a-9ce2-8958813a26ce",
      "name": "Only on change",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "v",
              "leftValue": "={{ $json.changed }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "c13536ec-286f-4064-9d8e-1fee5799df15",
      "name": "Alert",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1440,
        300
      ],
      "parameters": {
        "fromEmail": "info@example.com",
        "toEmail": "you@example.com",
        "subject": "={{ $json.url }} is {{ $json.now }}",
        "emailFormat": "text",
        "text": "={{ $json.url }} has been {{ $json.now }} since {{ $now.setLocale('en-US').toFormat('h:mm a') }} ({{ $json.detail }}).",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "ba29f951-93cc-480e-9b6b-c1429136654e",
      "name": "Save status",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        1680,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "site_status"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "url",
              "condition": "eq",
              "keyValue": "={{ $('Changed?').item.json.url }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "url": "={{ $('Changed?').item.json.url }}",
            "last_status": "={{ $('Changed?').item.json.now }}",
            "since": "={{ $now.toISO() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "url",
              "displayName": "url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "last_status",
              "displayName": "last_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "since",
              "displayName": "since",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "b0297a4e-2bef-4b4b-8bb2-8e47822dd4d3",
      "name": "Test manually",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        560
      ],
      "parameters": {}
    },
    {
      "id": "c2471d56-6b18-41d1-90e2-cb5811a78b36",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Website monitor\nTested on November 11, 2026, with n8n 2.47.3.\n\n**Fill in:** your URL in 'Address to monitor', an SMTP account, and the *site_status* table (url, last_status, since).\n\nAlerts only when the status changes.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Every 5 minutes": {
      "main": [
        [
          {
            "node": "Address to monitor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Address to monitor": {
      "main": [
        [
          {
            "node": "Request site",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request site": {
      "main": [
        [
          {
            "node": "Previous status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Previous status": {
      "main": [
        [
          {
            "node": "Changed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Changed?": {
      "main": [
        [
          {
            "node": "Only on change",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only on change": {
      "main": [
        [
          {
            "node": "Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert": {
      "main": [
        [
          {
            "node": "Save status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Test manually": {
      "main": [
        [
          {
            "node": "Address to monitor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}