{ "kind": "open-flow-workflow", "version": 1, "name": "Turn On a Philips Hue Light", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_720a4a84d86e4e92": { "name": "Enter the brightness", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 254 }, "nullable": false, "handle": "brightness" } ] }, "n_d31854ad98c0586f": { "inputs": { "brightness": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_720a4a84d86e4e92", "output": "brightness" } ] } }, "name": "Prepare the light state", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 254 }, "nullable": false, "handle": "brightness" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare the light state", "moduleId": "n_7c6a214a6a321a18", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_fb12f43d2043145e": { "inputs": { "url": { "kind": "value", "value": "https://api.meethue.com/route/api/REPLACE_WITH_USERNAME/lights/1/state" }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d31854ad98c0586f", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Update the Hue light", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Update the Hue light", "executor": { "method": "PUT", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_7600dd752a209b3b": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fb12f43d2043145e", "output": "body" } ] }, "brightness": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_720a4a84d86e4e92", "output": "brightness" } ] } }, "name": "Confirm the light state", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 254 }, "nullable": false, "handle": "brightness" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lightId" }, { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 254 }, "nullable": false, "handle": "brightness" } ], "name": "Confirm the light state", "moduleId": "n_078ef5e5665e5f85", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_df14c90cf46d8260": { "name": "Return the result", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lightId" }, { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 254 }, "nullable": false, "handle": "brightness" } ], "outputMappings": { "lightId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7600dd752a209b3b", "output": "lightId" } ] }, "brightness": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7600dd752a209b3b", "output": "brightness" } ] } } } }, "edges": [ { "source": "n_720a4a84d86e4e92", "target": "n_d31854ad98c0586f" }, { "source": "n_d31854ad98c0586f", "target": "n_fb12f43d2043145e" }, { "source": "n_fb12f43d2043145e", "target": "n_7600dd752a209b3b" }, { "source": "n_7600dd752a209b3b", "target": "n_df14c90cf46d8260" } ] } }, "modules": { "n_7c6a214a6a321a18": { "name": "Prepare the light state", "imports": [], "source": "export default function body({brightness}){if(!Number.isInteger(brightness)||brightness<1||brightness>254)throw Error('Brightness must be an integer from 1 to 254');return{body:{on:true,bri:brightness}}}\n" }, "n_078ef5e5665e5f85": { "name": "Confirm the light state", "imports": [], "source": "export default function confirm({body,brightness}){if(!Array.isArray(body)||!body.length)throw Error('Hue Bridge returned an invalid response');let onId,briId;for(const entry of body){if(!entry||typeof entry!=='object'||entry.error)throw Error('Hue Bridge did not confirm the command');const s=entry.success;if(!s||typeof s!=='object')throw Error('Hue Bridge returned an invalid response');for(const [path,v]of Object.entries(s)){let m=/^\\/lights\\/(\\d+)\\/state\\/(on|bri)$/.exec(path);if(!m)continue;if(m[2]==='on'&&v===true)onId=m[1];if(m[2]==='bri'&&v===brightness)briId=m[1]}}if(!onId||onId!==briId)throw Error('Hue Bridge did not confirm power and brightness on the same light');return{lightId:onId,brightness}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }