[
  {
    "id": "alexa-redmatic-tab-1",
    "type": "tab",
    "label": "Alexa Agent RedMatic Template",
    "disabled": false,
    "info": "Konservative RedMatic/Homematic-Vorlage für den lokalen Alexa-Agenten"
  },
  {
    "id": "http-in-alexa-redmatic-1",
    "type": "http in",
    "z": "alexa-redmatic-tab-1",
    "name": "Alexa Device 1 Webhook",
    "url": "/alexa/device/1",
    "method": "post",
    "upload": false,
    "swaggerDoc": "",
    "x": 180,
    "y": 120,
    "wires": [["fn-prepare-redmatic-1"]]
  },
  {
    "id": "fn-prepare-redmatic-1",
    "type": "function",
    "z": "alexa-redmatic-tab-1",
    "name": "Prepare Homematic Command",
    "func": "const operation = msg.payload.operation;\nconst payload = msg.payload.payload || {};\n\nconst deviceConfig = {\n    iface: 'HmIP-RF',\n    homematicId: '00161A499D4B7D:6',\n    channelLabel: 'Q7-Ausgang: CH2-A',\n    datapointOnOff: 'STATE'\n};\n\nif (operation !== 'turnOn' && operation !== 'turnOff') {\n    msg.payload = {\n        success: false,\n        result: {},\n        state: {},\n        error: `Unsupported operation: ${operation}`\n    };\n    return [null, msg];\n}\n\nmsg.hm = {\n    iface: deviceConfig.iface,\n    homematicId: deviceConfig.homematicId,\n    channelLabel: deviceConfig.channelLabel,\n    datapoint: deviceConfig.datapointOnOff,\n    value: operation === 'turnOn'\n};\n\nmsg.alexaResult = {\n    success: true,\n    result: {\n        executed: true,\n        operation,\n        target: deviceConfig.homematicId,\n        iface: deviceConfig.iface,\n        datapoint: deviceConfig.datapointOnOff\n    },\n    state: {\n        power: operation === 'turnOn'\n    }\n};\n\nreturn [msg, null];",
    "outputs": 2,
    "timeout": "",
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 430,
    "y": 120,
    "wires": [["comment-redmatic-hook", "fn-build-response-1"], ["http-response-error-1", "debug-error-1"]]
  },
  {
    "id": "comment-redmatic-hook",
    "type": "comment",
    "z": "alexa-redmatic-tab-1",
    "name": "Hier echten RedMatic/Homematic-Node einschleifen: msg.hm.homematicId / msg.hm.datapoint / msg.hm.value",
    "info": "Zwischen Prepare Homematic Command und Build Alexa Response kommt in RedMatic der echte Homematic-Ausführungsnode rein.",
    "x": 770,
    "y": 80,
    "wires": []
  },
  {
    "id": "fn-build-response-1",
    "type": "function",
    "z": "alexa-redmatic-tab-1",
    "name": "Build Alexa Response",
    "func": "msg.payload = msg.alexaResult || {\n    success: false,\n    result: {},\n    state: {},\n    error: 'missing_alexa_result'\n};\nreturn msg;",
    "outputs": 1,
    "timeout": "",
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 770,
    "y": 140,
    "wires": [["http-response-ok-1", "debug-ok-1"]]
  },
  {
    "id": "http-response-ok-1",
    "type": "http response",
    "z": "alexa-redmatic-tab-1",
    "name": "HTTP Response OK",
    "statusCode": "200",
    "headers": {},
    "x": 1030,
    "y": 120,
    "wires": []
  },
  {
    "id": "http-response-error-1",
    "type": "http response",
    "z": "alexa-redmatic-tab-1",
    "name": "HTTP Response Error",
    "statusCode": "200",
    "headers": {},
    "x": 1020,
    "y": 180,
    "wires": []
  },
  {
    "id": "debug-ok-1",
    "type": "debug",
    "z": "alexa-redmatic-tab-1",
    "name": "Alexa Homematic OK",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 1020,
    "y": 80,
    "wires": []
  },
  {
    "id": "debug-error-1",
    "type": "debug",
    "z": "alexa-redmatic-tab-1",
    "name": "Alexa Homematic Error",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 1020,
    "y": 240,
    "wires": []
  }
]
