{
 "name": "n8n of the week #21: n8n workflow #21: an aurora radar that rings only for a real solar storm",
 "nodes": [
  {
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "minutes",
       "minutesInterval": 15
      }
     ]
    }
   },
   "id": "e7d0ec63-4a22-59d7-8029-9ce1d72a5028",
   "name": "Every 15 minutes",
   "position": [
    0,
    0
   ],
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2
  },
  {
   "parameters": {
    "url": "https://services.swpc.noaa.gov/json/planetary_k_index_1m.json",
    "sendHeaders": true,
    "headerParameters": {
     "parameters": [
      {
       "name": "User-Agent",
       "value": "n8n workflow (+https://daniele-michelin.com/n8n-workflows/)"
      }
     ]
    },
    "options": {
     "timeout": 20000
    }
   },
   "id": "2c1f3cb2-d121-57a5-ab49-1be133877148",
   "name": "NOAA planetary Kp",
   "position": [
    240,
    0
   ],
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "onError": "continueRegularOutput"
  },
  {
   "parameters": {
    "mode": "runOnceForAllItems",
    "jsCode": "const threshold = 5; // ← Berlin: try 5; farther north can use 4, farther south often needs 6+\nconst rows = $input.first().json;\nif (!Array.isArray(rows) || !rows.length) return [];\nconst latest = rows.slice().reverse().find(r => Number.isFinite(Number(r.kp_index)));\nif (!latest) return [];\nconst kp = Number(latest.kp_index);\nconst mem = $getWorkflowStaticData('global');\nif (kp < threshold) { mem.level = 0; return []; }       // storm faded: arm the radar again\nconst level = Math.floor(kp * 2) / 2;                    // only notify on a new half-step\nif ((mem.level || 0) >= level) return [];\nmem.level = level;\nconst label = kp >= 7 ? 'strong geomagnetic storm' : kp >= 6 ? 'moderate geomagnetic storm' : 'active geomagnetic conditions';\nreturn [{ json: {\n  title: `Aurora radar: Kp ${kp.toFixed(1)}`,\n  message: `${label}. NOAA measurement: ${latest.time_tag || 'just now'}. Look north, away from city lights — cloud cover and darkness still decide what you can see.`,\n  click: 'https://www.swpc.noaa.gov/products/planetary-k-index', tags: ['sun_with_face']\n} }];"
   },
   "id": "1bf04983-ee9b-54b8-a624-cf1daaa91759",
   "name": "Storm worth watching?",
   "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 15 minutes": {
   "main": [
    [
     {
      "node": "NOAA planetary Kp",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "NOAA planetary Kp": {
   "main": [
    [
     {
      "node": "Storm worth watching?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Storm worth watching?": {
   "main": [
    [
     {
      "node": "Push to phone",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "pinData": {},
 "meta": {
  "source": "https://daniele-michelin.com/n8n-workflows/"
 }
}