[
  {
    "id": "a1067aa100000001",
    "type": "tab",
    "label": "01 WEM2067 HTTP and Dashboard",
    "disabled": false,
    "info": "Poll the public simulator every 10 seconds. A = solar, B = grid. MQTT is not required for HTTP polling."
  },
  {
    "id": "a1067aa100000002",
    "type": "comment",
    "z": "a1067aa100000001",
    "name": "1. Read HTTP → 2. Parse → 3. Dashboard / Trends / Automation",
    "info": "Simulator: https://simulator.iammeter.com/WEM2067/monitorjson. Dashboard: /dashboard/iammeter. This example only displays text and Debug messages; it does not control loads.",
    "x": 380,
    "y": 60,
    "wires": []
  },
  {
    "id": "a1067aa100000003",
    "type": "inject",
    "z": "a1067aa100000001",
    "name": "Poll every 10 seconds",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "10",
    "crontab": "",
    "once": true,
    "onceDelay": "1",
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 140,
    "y": 160,
    "wires": [
      [
        "a1067aa100000004"
      ]
    ]
  },
  {
    "id": "a1067aa100000004",
    "type": "http request",
    "z": "a1067aa100000001",
    "name": "Read WEM2067",
    "method": "GET",
    "ret": "obj",
    "paytoqs": "ignore",
    "url": "https://simulator.iammeter.com/WEM2067/monitorjson",
    "tls": "",
    "persist": false,
    "proxy": "",
    "insecureHTTPParser": false,
    "authType": "",
    "senderr": false,
    "headers": [],
    "requestTimeout": "8000",
    "x": 350,
    "y": 160,
    "wires": [
      [
        "a1067aa100000005"
      ]
    ]
  },
  {
    "id": "a1067aa100000005",
    "type": "function",
    "z": "a1067aa100000001",
    "name": "Parse dual-channel data",
    "func": "if (msg.statusCode !== 200) {\n    node.error(\"HTTP request failed. Status: \" + msg.statusCode, msg);\n    return null;\n}\nconst data = msg.payload;\nif (!data || !Array.isArray(data.Datas) || data.Datas.length !== 2 ||\n    !data.Datas.every(row => Array.isArray(row) && row.length >= 7 && row.slice(0, 7).every(Number.isFinite))) {\n    node.error(\"Expected WEM2067 dual-channel Datas. Check the URL and response.\", msg);\n    return null;\n}\nconst channel = row => ({voltage_V: row[0], current_A: row[1], power_W: row[2],\n    import_kWh: row[3], export_kWh: row[4], frequency_Hz: row[5], power_factor: row[6]});\nconst reading = {SN: data.SN, source: \"HTTP\", updated_at: new Date().toISOString(),\n    A: channel(data.Datas[0]), B: channel(data.Datas[1])};\nmsg.payload = reading;\nflow.set(\"latestReading\", reading);\nnode.status({fill:\"green\", shape:\"dot\", text:\"Grid \" + reading.B.power_W + \" W\"});\nreturn [msg, [{topic:\"A Solar\", payload:reading.A.power_W}, {topic:\"B Grid\", payload:reading.B.power_W}]];",
    "outputs": 2,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 570,
    "y": 160,
    "wires": [
      [
        "a1067aa100000006",
        "a1067aa100000007",
        "a1067aa100000009"
      ],
      [
        "a1067aa100000008"
      ]
    ]
  },
  {
    "id": "a1067aa100000006",
    "type": "debug",
    "z": "a1067aa100000001",
    "name": "HTTP live readings",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 840,
    "y": 120,
    "wires": []
  },
  {
    "id": "a1067aa100000007",
    "type": "ui-template",
    "z": "a1067aa100000001",
    "group": "a1067aa100000013",
    "page": "",
    "ui": "",
    "name": "Dual-channel readings",
    "order": 1,
    "width": "12",
    "height": "7",
    "format": "<template>\n  <section v-if=\"msg && msg.payload && msg.payload.A\" class=\"meter-panel\">\n    <p class=\"meter-meta\">WEM2067 · SN {{ msg.payload.SN }} · Last successful update {{ new Date(msg.payload.updated_at).toLocaleTimeString('en-US', { hour12: false }) }}</p>\n    <div class=\"meter-cards\">\n      <article><div class=\"channel-label\">Channel A · Solar generation</div><div class=\"power-value solar\">{{ msg.payload.A.power_W.toFixed(1) }} <small>W</small></div><div>{{ msg.payload.A.voltage_V.toFixed(1) }} V · {{ msg.payload.A.current_A.toFixed(3) }} A</div></article>\n      <article><div class=\"channel-label\">Channel B · Grid power</div><div class=\"power-value grid\">{{ msg.payload.B.power_W.toFixed(1) }} <small>W</small></div><div>{{ msg.payload.B.power_W < 0 ? 'Exporting to grid' : 'Importing from grid' }} · {{ msg.payload.B.voltage_V.toFixed(1) }} V</div></article>\n    </div>\n    <table class=\"meter-values\"><thead><tr><th>Reading</th><th>Channel A</th><th>Channel B</th></tr></thead><tbody>\n      <tr><td>Forward energy (kWh)</td><td>{{ msg.payload.A.import_kWh.toFixed(3) }}</td><td>{{ msg.payload.B.import_kWh.toFixed(3) }}</td></tr>\n      <tr><td>Reverse energy (kWh)</td><td>{{ msg.payload.A.export_kWh.toFixed(3) }}</td><td>{{ msg.payload.B.export_kWh.toFixed(3) }}</td></tr>\n      <tr><td>Frequency (Hz) / Power factor</td><td>{{ msg.payload.A.frequency_Hz.toFixed(2) }} / {{ msg.payload.A.power_factor }}</td><td>{{ msg.payload.B.frequency_Hz.toFixed(2) }} / {{ msg.payload.B.power_factor }}</td></tr>\n    </tbody></table>\n    <p class=\"meter-note\">Default scenario: A = solar, B = grid. Positive B = import; negative B = export. Energy readings are cumulative.</p>\n  </section>\n  <p v-else>Waiting for the first valid HTTP reading...</p>\n</template>\n<style>\n.meter-panel{padding:4px 10px;color:#223149}.meter-meta{font-size:13px;color:#526178;margin:4px 0 18px}.meter-cards{display:grid;grid-template-columns:1fr 1fr;gap:18px}.meter-cards article{background:#f4f7fb;border:1px solid #e4eaf2;border-radius:10px;padding:18px 22px}.channel-label{font-size:15px;font-weight:600}.power-value{font-size:38px;font-weight:700;line-height:1.6}.power-value small{font-size:18px;font-weight:400}.solar{color:#21845a}.grid{color:#2369ba}.meter-values{width:100%;border-collapse:collapse;margin-top:18px;font-size:14px}.meter-values td,.meter-values th{text-align:left;padding:10px 6px;border-bottom:1px solid #e4eaf2}.meter-note{font-size:12px;color:#526178;margin:16px 0 4px}@media(max-width:600px){.meter-cards{grid-template-columns:1fr}.power-value{font-size:30px}.meter-values{font-size:12px}}\n</style>",
    "storeOutMessages": true,
    "passthru": false,
    "resendOnRefresh": true,
    "templateScope": "local",
    "className": "",
    "x": 850,
    "y": 180,
    "wires": [
      []
    ]
  },
  {
    "id": "a1067aa100000008",
    "type": "ui-chart",
    "z": "a1067aa100000001",
    "group": "a1067aa100000014",
    "name": "Live power trend",
    "label": "Solar generation and grid power (W)",
    "order": 1,
    "chartType": "line",
    "category": "topic",
    "categoryType": "msg",
    "xAxisLabel": "Time",
    "xAxisProperty": "",
    "xAxisPropertyType": "timestamp",
    "xAxisType": "time",
    "xAxisFormat": "HH:mm:ss",
    "xAxisFormatType": "auto",
    "yAxisLabel": "W",
    "yAxisProperty": "payload",
    "yAxisPropertyType": "msg",
    "action": "append",
    "stackSeries": false,
    "pointShape": "circle",
    "pointRadius": 2,
    "showLegend": true,
    "removeOlder": "10",
    "removeOlderUnit": "60",
    "removeOlderPoints": "",
    "colors": [
      "#21845a",
      "#2369ba"
    ],
    "textColor": [
      "#526178"
    ],
    "width": "12",
    "height": "5",
    "className": "",
    "x": 850,
    "y": 240,
    "wires": [
      []
    ]
  },
  {
    "id": "a1067aa100000009",
    "type": "function",
    "z": "a1067aa100000001",
    "name": "Grid power automation",
    "func": "const power = msg.payload.B.power_W;\nif (power < 0) {\n    msg.payload = \"Exporting to the grid; flexible loads may be considered\";\n} else if (power > 1000) {\n    msg.payload = \"Grid import exceeds 1000 W; an import alert may be triggered\";\n} else {\n    msg.payload = \"Grid import is between 0 and 1000 W\";\n}\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 580,
    "y": 340,
    "wires": [
      [
        "a1067aa100000010"
      ]
    ]
  },
  {
    "id": "a1067aa100000010",
    "type": "rbe",
    "z": "a1067aa100000001",
    "name": "State changes only",
    "func": "rbe",
    "gap": "",
    "start": "",
    "inout": "out",
    "septopics": false,
    "property": "payload",
    "topi": "topic",
    "x": 830,
    "y": 340,
    "wires": [
      [
        "a1067aa100000011",
        "a1067aa100000012"
      ]
    ]
  },
  {
    "id": "a1067aa100000011",
    "type": "debug",
    "z": "a1067aa100000001",
    "name": "Automation state changes",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 1080,
    "y": 320,
    "wires": []
  },
  {
    "id": "a1067aa100000012",
    "type": "ui-text",
    "z": "a1067aa100000001",
    "group": "a1067aa100000014",
    "order": 2,
    "width": "12",
    "height": "1",
    "name": "Automation message",
    "label": "Status",
    "format": "{{msg.payload}}",
    "layout": "row-spread",
    "style": false,
    "font": "",
    "fontSize": 16,
    "color": "#526178",
    "className": "",
    "x": 1060,
    "y": 380,
    "wires": [],
    "value": "payload",
    "valueType": "msg",
    "wrapText": true
  },
  {
    "id": "a1067aa100000013",
    "type": "ui-group",
    "name": "WEM2067 dual-channel readings",
    "page": "a1067aa100000015",
    "width": "12",
    "height": "1",
    "order": 1,
    "showTitle": true,
    "className": "",
    "visible": "true",
    "disabled": "false",
    "groupType": "default"
  },
  {
    "id": "a1067aa100000014",
    "type": "ui-group",
    "name": "Live trends and automation",
    "page": "a1067aa100000015",
    "width": "12",
    "height": "1",
    "order": 2,
    "showTitle": true,
    "className": "",
    "visible": "true",
    "disabled": "false",
    "groupType": "default"
  },
  {
    "id": "a1067aa100000015",
    "type": "ui-page",
    "name": "IAMMETER Meter Simulator",
    "ui": "a1067aa100000016",
    "path": "/iammeter",
    "icon": "electric_meter",
    "layout": "grid",
    "theme": "a1067aa100000017",
    "breakpoints": [
      {
        "name": "Default",
        "px": "0",
        "cols": "3"
      },
      {
        "name": "Tablet",
        "px": "576",
        "cols": "6"
      },
      {
        "name": "Desktop",
        "px": "1024",
        "cols": "12"
      }
    ],
    "order": 1,
    "className": "",
    "visible": "true",
    "disabled": "false"
  },
  {
    "id": "a1067aa100000016",
    "type": "ui-base",
    "name": "IAMMETER Node-RED Example",
    "path": "/dashboard",
    "appIcon": "",
    "includeClientData": true,
    "acceptsClientConfig": [
      "ui-notification",
      "ui-control"
    ],
    "showPathInSidebar": false,
    "showPageTitle": true,
    "navigationStyle": "none",
    "titleBarStyle": "default",
    "showReconnectNotification": true,
    "notificationDisplayTime": 1,
    "showDisconnectNotification": true,
    "allowInstall": false,
    "headerContent": "page"
  },
  {
    "id": "a1067aa100000017",
    "type": "ui-theme",
    "name": "IAMMETER Tutorial Theme",
    "colors": {
      "surface": "#ffffff",
      "primary": "#2369ba",
      "bgPage": "#eef2f7",
      "groupBg": "#ffffff",
      "groupOutline": "#dce4ee"
    },
    "sizes": {
      "density": "default",
      "pagePadding": "16px",
      "groupGap": "16px",
      "groupBorderRadius": "12px",
      "widgetGap": "12px"
    }
  },
  {
    "id": "a1067aa100000018",
    "type": "catch",
    "z": "a1067aa100000001",
    "name": "Catch HTTP and parsing errors",
    "scope": [
      "a1067aa100000004",
      "a1067aa100000005"
    ],
    "uncaught": false,
    "x": 250,
    "y": 450,
    "wires": [
      [
        "a1067aa100000019"
      ]
    ]
  },
  {
    "id": "a1067aa100000019",
    "type": "debug",
    "z": "a1067aa100000001",
    "name": "Connection or data format error",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "error",
    "targetType": "msg",
    "x": 580,
    "y": 450,
    "wires": []
  }
]