Lampen von der Hue Bridge einfach per Node Red einbinden

Hallo in die Runde,

ich war mal wieder fleißig und habe mal eine Funktion erstellt mit der alle Lampen von der Hue in node Red und homeeDevice importiert werden können.
Es ist nicht mehr Notwendig die Profile und Attribute selber zusammen zustellen und ID’s zu vergeben.
Einfach in Node Red Hue Magic und homeeDeviceNode installieren und dann folgende Funktion ausführen.

[
    {
        "id": "4350b40a.b44834",
        "type": "function",
        "z": "da13544f.133da",
        "name": "",
        "func": "if (msg.updated){return}\nvar arr = msg.lights;\nvar node_id;\nvar y_val = 0;\nvar send=[];\nvar func;\nvar hue;\nvar rfunc;\n\narr.forEach(function(ar){\n    if(ar.attributes.attributes.type === \"Dimmable light\" || ar.attributes.attributes.type === \"Extended color light\" || ar.attributes.attributes.type ===\"Color temperature light\" || ar.attributes.attributes.type ===\"Color light\"){\n    y_val = y_val + 40;\n    node_id = variable()\n    var s = [];\n    //node.send({payload:ar.state.attributes})\n    if (ar.state.attributes.on === true ||ar.state.attributes.on === false){s.push(x(1))}\n    if (ar.state.attributes.bri){s.push(x(2))}//dim\n    if (ar.state.attributes.ct){s.push(x(3))}//ct\n    if (ar.state.attributes.hue){s.push(x(4))}//hue\n    var nodehomee =\n    new homee_node(\n        node_id+10,\n        ar.attributes.attributes.name,\n        node_id,\n        profileid(ar.attributes.attributes.type),\n        \n            s\n            )\n    send.push(nodehomee);\n    func = new funktion(node_id+20,ar.attributes.attributes.name);\n    send.push(func);\n    hue = new huenode(node_id+30,ar.attributes.attributes.name,ar.attributes.attributes.id);\n    send.push(hue);\n    rfunc = new rfunktion(node_id+40,ar.attributes.attributes.name);\n    send.push(rfunc);\n    \n}})\nreturn{payload:send};\n\n\n\n\n//return {payload: {nodehomee}};\nfunction Attribute(\n      id, nodeID, instance, min, max, currentValue, targetValue, lastValue, unit, stepValue, editable, type, data) {\n    this.id = id;\n    this.node_id = nodeID;\n    this.instance = instance;\n    this.minimum = min;\n    this.maximum = max;\n    this.current_value = currentValue;\n    this.target_value = targetValue;\n    this.last_value = lastValue;\n    this.unit = unit;\n    this.step_value = stepValue;\n    this.editable = editable;\n    this.type = type;\n    this.state = 1;\n    this.last_changed = 12345555;\n    this.changed_by = 1;\n    this.changed_by_id = 0;\n    this.based_on = 1;\n    this.data = data;\n  }\nfunction Node (name, id, profile, attributes) {\n    this.name = name;\n    this.id = id;\n    this.profile = profile;\n    this.image = 'default';\n    this.favorite= 0;\n    this.order = id;\n    this.protocol = 1;\n    this.routing = 1;\n    this.state = 1;\n    this.state_changed = 12345;\n    this.added = 12345;\n    this.history = 0;\n    this.cube_type=1;\n    this.note ='';\n    this.services= 0;\n    this.phonetic_name = '';\n    this.owner = 0;\n    this.denied_user_ids = [];\n    this.attributes = attributes;\n  }\nfunction homee_node (id,name,nodeId,profile,attribute)\n    {\n        this.id = id ;\n        this.type = \"homeeDevice\";\n        this.z = var_z();\n        this.virtual_homee = \"\";\n        this.name = name;\n        this.nodeId = nodeId;\n        this.showNodeId = false;\n        this.profile = profile;\n        this.icon = \"default\";\n        this.attributes = \n            attribute;\n        this.statusTemplate= \"\";\n        this.x = 10;\n        this.y = y_val;\n        this.wires= [\n            [\n               id +10\n            ]\n        ]\n    }  \nfunction x(x){\nswitch(x){\n    case 1 : y =new Attribute(node_id+1, node_id, 0, 0, 1, 0, 0, 0, '', 1, 1, 1, '');// on/off\n    break;\n    case  2 : y =new Attribute(node_id+2, node_id, 0, 0, 100, 0, 0, 0, '%25', 1, 1, 2, \"\");// dimmer\n    break;\n    case 3 : y =new Attribute(node_id+3, node_id, 0, 0, 500, 0, 0, 0, '', 1, 1, 42, \"\");// farbtemperatur\n    break;\n    case 4 : y =new Attribute(node_id+4, node_id, 0, 0, 16777215, 0, 0, 0, '', 1, 1, 23, \"7001020%3B16419669%3B12026363%3B16525995\");// farbtemperatur\n    break\n    }\n    return y\n    \n}    \nfunction profileid(x){\n    switch(x){\n        case \"Dimmable light\" : y = 1002;\n        break;\n        case \"Extended color light\" : y = 1002;\n        break;\n        case \"Color light\" : y = 1002 ;\n        break;\n        case \"Color temperature light\" : y = 1002;\n        break\n    }\n    return y\n}\nfunction variable() {\n    var max = 9999;\n    return Math.floor(Math.random() * Math.floor(max));\n}\nfunction var_z() {\n    var max = 999999;\n    return Math.floor(Math.random() * Math.floor(max));\n}\nfunction huenode(id,name,light_id){\n    this.id = id;\n    this.type =  \"hue-light\";\n    this.z =  var_z();\n    this.name = name;\n    this.bridge = \"\";\n    this.lightid =  light_id;\n    this.colorname = true;\n    this.skipevents= false;\n    this.universalevents = false;\n    this.x = 500;\n    this.y = y_val;\n    this.wires= [[id+10]]\n    \n}\nfunction funktion(id,name){\n       this.id = id;\n        this.type= \"function\";\n        this.z = var_z();\n        this.name= name,\n        this.func= 'if (msg.payload.attributeId === '+(node_id+4)+'){ausgabe2 = Math.abs(msg.payload.targetValue).toString(16);node.send({payload:{\"hex\":ausgabe2}});}if (msg.payload.attributeId === '+(node_id+1)+'){node.send({payload:{\"on\":msg.payload.targetValue === 1 ? true:false}})}if (msg.payload.attributeId === '+(node_id+2)+'){node.send({payload:{\"brightness\":msg.payload.targetValue}})}if (msg.payload.attributeId === '+(node_id+3)+'){node.send({payload:{\"colorTemp\":msg.payload.targetValue}})}';\n        this.outputs= 1;\n        this.noerr=0;\n        this.initialize= \"\";\n        this.finalize= \"\";\n        this.libs= [];\n        this.x = 300;\n        this.y = y_val;\n        this.wires= [\n            [\n               id+10\n            ]\n        ]\n}\nfunction rfunktion(id,name){\n       this.id = id;\n        this.type= \"function\";\n        this.z = var_z();\n        this.name= \"Rückgabe\",\n        this.func= 'node.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+1)+',\\\"value\\\":msg.payload.on === true ? 1:0}}})\\nnode.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+2)+',\\\"value\\\":msg.payload.brightness}}})\\nnode.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+3)+',\\\"value\\\":msg.payload.colorTemp}}})\\nif( msg.payload.hex){\\nnode.send({payload: {\\\"attribute\\\":{\\\"id\\\":'+(node_id+4)+',\\\"value\\\":parseInt(msg.payload.hex,16)}}})}';\n        this.outputs= 1;\n        this.noerr=0;\n        this.initialize= \"\";\n        this.finalize= \"\";\n        this.libs= [];\n        this.x = 700;\n        this.y = y_val;\n        this.wires= [\n            [\n               id-30\n            ]\n        ]\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 900,
        "wires": [
            [
                "18447739.ae64f1"
            ]
        ]
    },
    {
        "id": "ad76ff60.a26468",
        "type": "hue-bridge-node",
        "z": "da13544f.133da",
        "name": "",
        "bridge": "31b24fdc.22595",
        "autoupdates": false,
        "skipglobalevents": true,
        "x": 290,
        "y": 900,
        "wires": [
            [
                "4350b40a.b44834"
            ]
        ]
    },
    {
        "id": "4ca5230.465ee5c",
        "type": "inject",
        "z": "da13544f.133da",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"fetch\":\"lights\"}",
        "payloadType": "json",
        "x": 120,
        "y": 900,
        "wires": [
            [
                "ad76ff60.a26468"
            ]
        ]
    },
    {
        "id": "18447739.ae64f1",
        "type": "debug",
        "z": "da13544f.133da",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 590,
        "y": 900,
        "wires": []
    },
    {
        "id": "31b24fdc.22595",
        "type": "hue-bridge",
        "name": "Philips hue",
        "bridge": "",
        "key": "",
        "interval": "3000",
        "disableupdates": false
    }
]

Das Hue Node mit der Bridge verbinden und dann den Inject ausführen.
dann den Wert im Debug Fenster kopieren.

danach auf Importieren gehen und den Zwischenspeicher einfügen.


und nun import drücken und die Nodes positionieren.

Jetzt noch einfach in den homeeDevice den entsprechenden vhih auswählen und im hue Node noch die Bridge.
Danach in homee noch Geräte hinzufügen wählen und hih auswählen und entsprechende Geräte auswählen.

Bei den Geräten werden die entsprechenden Attribute automatisch gesetzt je nach Vorgabe der Bridge.
Die LampenID der Bridge und die Namen werden auch automatisch von der Hue übernommen.

Dann viel Spaß beim Testen und spielen.

Micha

19 „Gefällt mir“

Die Funktion ist für hue Magic 3.0.0 ausgelegt.
Bei hue Magic 4.2.2 sind der Pfade anders , werde das dann nachmal anpassen an das aktuelle Node.

2 „Gefällt mir“

Hier der geänderte Flow für Hue Magic 4.2.2

[
    {
        "id": "4350b40a.b44834",
        "type": "function",
        "z": "d0db4d4a18df259c",
        "name": "",
        "func": "if (msg.updated){return}\nvar arr = msg.results.light;\nvar node_id;\nvar y_val = 0;\nvar send=[];\nvar func;\nvar hue;\nvar rfunc;\n\narr.forEach(function(ar){\n    if(ar.info.type === \"light\"){\n    y_val = y_val + 40;\n    node_id = variable()\n    var s = [];\n    //node.send({payload:ar.state.attributes})\n    if (ar.payload.on === true ||ar.payload.on === false){s.push(x(1))}\n    if (ar.payload.brightness){s.push(x(2))}//dim\n    if (ar.payload.colorTemp === true || ar.payload.colorTemp === false){s.push(x(3))}//ct\n    if (ar.payload.hex){s.push(x(4))}//hue\n    \n    var nodehomee =\n    new homee_node(\n        node_id+10,\n        ar.info.name,\n        node_id,\n        profileid(ar.info.model.name),\n        \n            s\n            )\n    send.push(nodehomee);\n    func = new funktion(node_id+20,ar.info.name);\n    send.push(func);\n    hue = new huenode(node_id+30,ar.info.name,ar.info.deviceId);\n    send.push(hue);\n    rfunc = new rfunktion(node_id+40,ar.info.name);\n    send.push(rfunc);\n    \n}})\nreturn{payload:send};\n\n\n\n\n//return {payload: {nodehomee}};\nfunction Attribute(\n      id, nodeID, instance, min, max, currentValue, targetValue, lastValue, unit, stepValue, editable, type, data) {\n    this.id = id;\n    this.node_id = nodeID;\n    this.instance = instance;\n    this.minimum = min;\n    this.maximum = max;\n    this.current_value = currentValue;\n    this.target_value = targetValue;\n    this.last_value = lastValue;\n    this.unit = unit;\n    this.step_value = stepValue;\n    this.editable = editable;\n    this.type = type;\n    this.state = 1;\n    this.last_changed = 12345555;\n    this.changed_by = 1;\n    this.changed_by_id = 0;\n    this.based_on = 1;\n    this.data = data;\n  }\nfunction Node (name, id, profile, attributes) {\n    this.name = name;\n    this.id = id;\n    this.profile = profile;\n    this.image = 'default';\n    this.favorite= 0;\n    this.order = id;\n    this.protocol = 1;\n    this.routing = 1;\n    this.state = 1;\n    this.state_changed = 12345;\n    this.added = 12345;\n    this.history = 0;\n    this.cube_type=1;\n    this.note ='';\n    this.services= 0;\n    this.phonetic_name = '';\n    this.owner = 0;\n    this.denied_user_ids = [];\n    this.attributes = attributes;\n  }\nfunction homee_node (id,name,nodeId,profile,attribute)\n    {\n        this.id = id ;\n        this.type = \"homeeDevice\";\n        this.z = var_z();\n        this.virtual_homee = \"\";\n        this.name = name;\n        this.nodeId = nodeId;\n        this.showNodeId = false;\n        this.profile = profile;\n        this.icon = \"default\";\n        this.attributes = \n            attribute;\n        this.statusTemplate= \"\";\n        this.x = 10;\n        this.y = y_val;\n        this.wires= [\n            [\n               id +10\n            ]\n        ]\n    }  \nfunction x(x){\nswitch(x){\n    case 1 : y =new Attribute(node_id+1, node_id, 0, 0, 1, 0, 0, 0, '', 1, 1, 1, '');// on/off\n    break;\n    case  2 : y =new Attribute(node_id+2, node_id, 0, 0, 100, 0, 0, 0, '%25', 1, 1, 2, \"\");// dimmer\n    break;\n    case 3 : y =new Attribute(node_id+3, node_id, 0, 153, 500, 0, 0, 0, '', 1, 1, 42, \"\");// farbtemperatur\n    break;\n    case 4 : y =new Attribute(node_id+4, node_id, 0, 0, 16777215, 0, 0, 0, '', 1, 1, 23, \"7001020%3B16419669%3B12026363%3B16525995\");// farbtemperatur\n    break\n    }\n    return y\n    \n}    \nfunction profileid(x){\n    switch(x){\n        case \"Dimmable light\" : y = 1002;\n        break;\n        case \"Extended color light\" : y = 1002;\n        break;\n        case \"Color light\" : y = 1002 ;\n        break;\n        case \"Color temperature light\" : y = 1002;\n        break;\n        case \"Hue lightstrip plus\" : y =1002;\n        break;\n        case \"hue_iris\" : y = 1002;\n        break;\n        case \"Hue color lamp\" : y = 1002;\n        break\n    }\n    return y\n}\nfunction variable() {\n    var max = 9999;\n    return Math.floor(Math.random() * Math.floor(max));\n}\nfunction var_z() {\n    var max = 999999;\n    return Math.floor(Math.random() * Math.floor(max));\n}\nfunction huenode(id,name,light_id){\n    this.id = id;\n    this.type =  \"hue-light\";\n    this.z =  var_z();\n    this.name = name;\n    this.bridge = \"\";\n    this.lightid =  light_id;\n    this.colorname = true;\n    this.skipevents= false;\n    this.universalevents = false;\n    this.x = 500;\n    this.y = y_val;\n    this.wires= [[id+10]]\n    \n}\nfunction funktion(id,name){\n       this.id = id;\n        this.type= \"function\";\n        this.z = var_z();\n        this.name= name,\n        this.func= 'if (msg.payload.attributeId === '+(node_id+4)+'){ausgabe2 = Math.abs(msg.payload.targetValue).toString(16);node.send({payload:{\"hex\":ausgabe2}});}if (msg.payload.attributeId === '+(node_id+1)+'){node.send({payload:{\"on\":msg.payload.targetValue === 1 ? true:false}})}if (msg.payload.attributeId === '+(node_id+2)+'){node.send({payload:{\"brightness\":msg.payload.targetValue}})}if (msg.payload.attributeId === '+(node_id+3)+'){node.send({payload:{\"colorTemp\":msg.payload.targetValue}})}';\n        this.outputs= 1;\n        this.noerr=0;\n        this.initialize= \"\";\n        this.finalize= \"\";\n        this.libs= [];\n        this.x = 300;\n        this.y = y_val;\n        this.wires= [\n            [\n               id+10\n            ]\n        ]\n}\nfunction rfunktion(id,name){\n       this.id = id;\n        this.type= \"function\";\n        this.z = var_z();\n        this.name= \"Rückgabe\",\n        this.func= 'node.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+1)+',\\\"value\\\":msg.payload.on === true ? 1:0}}})\\nnode.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+2)+',\\\"value\\\":msg.payload.brightness}}})\\nnode.send({payload:{\\\"attribute\\\":{\\\"id\\\":'+(node_id+3)+',\\\"value\\\":msg.payload.colorTemp}}})\\nif( msg.payload.hex){\\nnode.send({payload: {\\\"attribute\\\":{\\\"id\\\":'+(node_id+4)+',\\\"value\\\":parseInt(msg.payload.hex,16)}}})}';\n        this.outputs= 1;\n        this.noerr=0;\n        this.initialize= \"\";\n        this.finalize= \"\";\n        this.libs= [];\n        this.x = 700;\n        this.y = y_val;\n        this.wires= [\n            [\n               id-30\n            ]\n        ]\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 240,
        "wires": [
            [
                "18447739.ae64f1"
            ]
        ]
    },
    {
        "id": "ad76ff60.a26468",
        "type": "hue-bridge-node",
        "z": "d0db4d4a18df259c",
        "name": "",
        "bridge": "5feebd98.7c174c",
        "autoupdates": false,
        "skipglobalevents": true,
        "initevents": false,
        "x": 350,
        "y": 240,
        "wires": [
            [
                "4350b40a.b44834"
            ]
        ]
    },
    {
        "id": "4ca5230.465ee5c",
        "type": "inject",
        "z": "d0db4d4a18df259c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"fetch\":\"light\"}",
        "payloadType": "json",
        "x": 120,
        "y": 240,
        "wires": [
            [
                "ad76ff60.a26468"
            ]
        ]
    },
    {
        "id": "18447739.ae64f1",
        "type": "debug",
        "z": "d0db4d4a18df259c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 240,
        "wires": []
    },
    {
        "id": "5feebd98.7c174c",
        "type": "hue-bridge",
        "name": "Philips hue",
        "bridge": "100.100.100.1",
        "key": "xyzzy",
        "worker": "10",
        "autoupdates": true,
        "disableupdates": true
    }
]

Wenn jemand ein passendes Video dazu braucht dann einfach sagen.

2 „Gefällt mir“

Willst du dein Werk nicht in den Wiki-Bereich verschieben?
Ich werde es bei Gelegenheit Mal testen. :+1:

Was fürn Wiki :joy:

4 „Gefällt mir“

Hat gut geklappt, Danke!
Nur zur Info: Bei einigen Geräten (homeeDevice) war das Profil leer und musst manuell ausgewählt werden

1 „Gefällt mir“

Kannst du mir sagen was für Geräte das waren?
Dann würde ich mir das nochmal anschauen.

Oder du gibst mir mal nen Zugang und ich schaue mir die Daten mal selber an.

VG

1 „Gefällt mir“