{
  "name": "09 Website-bewaker: alleen melden als de status verandert",
  "nodes": [
    {
      "id": "858a6669-52be-452a-9b2b-d7bde2ec6fab",
      "name": "Elke 5 minuten",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      }
    },
    {
      "id": "c4cc484b-46ba-4545-9128-cc1524ef1007",
      "name": "Te bewaken adres",
      "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": "ad99d6bd-9deb-4cda-bf6e-3bd14f999aa5",
      "name": "Site opvragen",
      "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": "e552c8a4-8c15-4da0-b556-a1a013dc3ade",
      "name": "Vorige 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": "={{ $('Te bewaken adres').item.json.url }}"
            }
          ]
        },
        "returnAll": true
      },
      "alwaysOutputData": true
    },
    {
      "id": "bbdab600-fbee-40d3-9223-85d5157b72ea",
      "name": "Veranderd?",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "jsCode": "const url = $('Te bewaken adres').first().json.url;\nconst r = $('Site opvragen').first().json;\nconst nu = (r.statusCode >= 200 && r.statusCode < 400) ? 'in de lucht' : 'onbereikbaar';\nconst detail = r.statusCode ? `HTTP ${r.statusCode}` : (r.error?.message || 'geen antwoord');\nconst vorig = $input.first().json.laatste_status || 'in de lucht';\nreturn [{ json: { url, nu, vorig, detail, veranderd: nu !== vorig, rij: $input.first().json.id || null } }];"
      }
    },
    {
      "id": "86ac7730-5997-48be-b8ad-a6d9f591c551",
      "name": "Alleen bij verandering",
      "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.veranderd }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "ad39fefa-fc75-41fc-8941-b5400c672cc8",
      "name": "Melding",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1440,
        300
      ],
      "parameters": {
        "fromEmail": "info@example.com",
        "toEmail": "jij@example.com",
        "subject": "={{ $json.url }} is {{ $json.nu }}",
        "emailFormat": "text",
        "text": "={{ $json.url }} is sinds {{ $now.setLocale('nl').toFormat('HH:mm') }} {{ $json.nu }} ({{ $json.detail }}).",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "5f17e20b-307f-4151-9d4c-fdd30131c19b",
      "name": "Status bewaren",
      "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": "={{ $('Veranderd?').item.json.url }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "url": "={{ $('Veranderd?').item.json.url }}",
            "laatste_status": "={{ $('Veranderd?').item.json.nu }}",
            "sinds": "={{ $now.toISO() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "url",
              "displayName": "url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "laatste_status",
              "displayName": "laatste_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "sinds",
              "displayName": "sinds",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "bf827506-2a22-422a-b8a4-11f107d6fbbe",
      "name": "Handmatig testen",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        560
      ],
      "parameters": {}
    },
    {
      "id": "c7a84567-1671-4a13-b3bd-c91a0321ed56",
      "name": "Lees mij",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Website-bewaker\nGetest op 11-11-2026 met n8n 2.47.3.\n\n**Invullen:** je adres in 'Te bewaken adres', SMTP-account, tabel *site_status* (url, laatste_status, sinds).\n\nMeldt alleen als de status verandert.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Elke 5 minuten": {
      "main": [
        [
          {
            "node": "Te bewaken adres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Te bewaken adres": {
      "main": [
        [
          {
            "node": "Site opvragen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Site opvragen": {
      "main": [
        [
          {
            "node": "Vorige status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vorige status": {
      "main": [
        [
          {
            "node": "Veranderd?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Veranderd?": {
      "main": [
        [
          {
            "node": "Alleen bij verandering",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alleen bij verandering": {
      "main": [
        [
          {
            "node": "Melding",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Melding": {
      "main": [
        [
          {
            "node": "Status bewaren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handmatig testen": {
      "main": [
        [
          {
            "node": "Te bewaken adres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}