{
  "id": "xJ07Z5jW0ZtOFRRn",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Solar Energy Production Monitoring Alert Workflow",
  "tags": [],
  "nodes": [
    {
      "id": "39adba14-16e8-4a0d-bf52-5fa72a2db102",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -240
      ],
      "parameters": {
        "width": 1440,
        "height": 440,
        "content": "## Solar Energy Production Monitoring Alert Workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "6a3798bc-bcd7-4b63-baad-be18c170d2de",
      "name": "Trigger: Every 2 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -640,
        -60
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 2
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fee7d77b-1e95-4b93-9251-a9e4f1136b57",
      "name": "Fetch Solar Production Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -420,
        -60
      ],
      "parameters": {
        "url": "",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "0e2e4a6e-e4cf-4987-85e0-ac34aa69ca76",
      "name": "Filter Low Production Entries",
      "type": "n8n-nodes-base.code",
      "position": [
        -200,
        -60
      ],
      "parameters": {
        "jsCode": "const inputArray = $input.first().json.records;\n\nconst alerts = [];\n\nfor (const data of inputArray) {\n  if (data.TotalCon &lt; 1000) {\n    alerts.push({\n      json: {\n        ...data,\n        alert: `\u26a0\ufe0f TotalCon too low: ${data.TotalCon}`\n      }\n    });\n  }\n}\n\nreturn alerts;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "3163b670-6b90-4c67-8e6b-f027010c9c8d",
      "name": "Check for Low Production",
      "type": "n8n-nodes-base.if",
      "position": [
        20,
        -60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6c5b6428-1b08-45d7-8ee8-9fb17f47e89a",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.TotalCon }}",
              "rightValue": 1000
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "86160f80-56e9-4049-ba79-5301fe042e47",
      "name": "Send Email Alert (Low Production)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        240,
        -160
      ],
      "parameters": {
        "sendTo": "",
        "message": "=Dear Team,  This is to inform you that the emergency power production has dropped below the acceptable threshold as of {{ $json.HourUTC }}.  Details:  Production Level: {{ $json.TotalCon }} MW  Threshold Level: 1000 MW  This could potentially impact dependent systems or operations. Please take immediate action to investigate and restore power production to safe levels.  If you require assistance or further diagnostics, kindly escalate to the relevant maintenance or energy management team.  Stay safe, [Your System Name / Monitoring Service]",
        "options": {},
        "subject": "Critical Alert: Emergency Power Generation Below Threshold"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ff45f4cb-f910-4d3d-ae20-9395761543e5",
      "name": "Log Valid Production Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        240,
        40
      ],
      "parameters": {
        "columns": {
          "value": {
            "alert": "={{ $json.alert }}",
            "HourDK": "={{ $json.HourDK }}",
            "HourUTC": "={{ $json.HourUTC }}",
            "TotalCon": "={{ $json.TotalCon }}",
            "PriceArea": "={{ $json.PriceArea }}",
            "ConsumerType_DE35": "={{ $json.ConsumerType_DE35 }}"
          },
          "schema": [
            {
              "id": "HourUTC",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "HourUTC",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "HourDK",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "HourDK",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "PriceArea",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "PriceArea",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ConsumerType_DE35",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ConsumerType_DE35",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "TotalCon",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "TotalCon",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "alert",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "alert",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "HourUTC"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1111398960,
          "cachedResultUrl": "",
          "cachedResultName": "energy_production"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1cQ-TBf3-dqo7njDYzYpxpASYFvEp8lIzH7vpIqTLcwc",
          "cachedResultUrl": "",
          "cachedResultName": "N8N_Email_Attachment"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "ebcb1b27-011c-4f82-816a-a0ba3b157325",
      "name": "Post Summary to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        460,
        40
      ],
      "parameters": {
        "text": "={{ $json.TotalCon }}",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "99700ad8-ab8c-45a2-a37a-f6d7b0f761fa",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        240
      ],
      "parameters": {
        "width": 1440,
        "height": 480,
        "content": "## **Node Breakdown & Descriptions:**\n\n* The workflow starts with a **Schedule Trigger** node named **\"Trigger: Every 2 Hours\"**, which runs every 2 hours throughout the day to automate regular monitoring of solar energy production levels from the energy provider.\n\n* The next node, named **\"Fetch Solar Production Data\"**, is an HTTP Request node that fetches the latest solar energy production data from the Energidataservice API. This data includes hourly production values which will be analyzed for performance thresholds.\n\n* The **Code** node named **\"Filter Low Production Entries\"** processes the API response and filters entries where the solar energy production is below a defined minimum threshold. It outputs only the relevant records for further conditional handling.\n\n* The **If** node named **\"Check for Low Production\"** checks whether any low-production entries exist from the filtered list. If yes (true), the flow continues to alert the user; if no (false), the data is logged for reference.\n\n* If the condition is true, the **Gmail** node named **\"Send Email Alert (Low Production)\"** is triggered to notify users via email. The email includes details about the affected production entries and serves as an early warning for corrective action.\n\n* If the condition is false, the **Google Sheets** node named **\"Log Valid Production Data\"** appends the acceptable power production data into a connected Google Sheet. This allows maintaining a history of normal production records for tracking.\n\n* Finally, the **Slack** node named **\"Post Summary to Slack\"** sends a message to a specified Slack channel with the latest production data logged in Google Sheets. This acts as an end-of-day summary for visibility and team awareness.\n\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9874b516-8f7f-47a9-a12a-fc2d48cf9751",
  "connections": {
    "Trigger: Every 2 Hours": {
      "main": [
        [
          {
            "node": "Fetch Solar Production Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Low Production": {
      "main": [
        [
          {
            "node": "Send Email Alert (Low Production)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Valid Production Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Valid Production Data": {
      "main": [
        [
          {
            "node": "Post Summary to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Solar Production Data": {
      "main": [
        [
          {
            "node": "Filter Low Production Entries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Low Production Entries": {
      "main": [
        [
          {
            "node": "Check for Low Production",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}