Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Picker for Tradfri not working in HK Zigbee node. #189

Closed
kneip68 opened this issue Oct 20, 2019 · 13 comments
Closed

Color Picker for Tradfri not working in HK Zigbee node. #189

kneip68 opened this issue Oct 20, 2019 · 13 comments

Comments

@kneip68
Copy link
Contributor

kneip68 commented Oct 20, 2019

Hi hobbyquaker

First of all a big thx again for all your work, and in addition you seem to be able to read minds ;-). I have been working on integrating Tradfri Bulbs on Zigbee Stick into Homekit via RedMatic since a few days, and now you solved already a big part of it.

Now: I immediatly checked out the new node ZIGBEE, and found that the two bulbs Tradfri LED1624G9 I have are actually switching on/off and can be dimmed.

Color picker/Saturation does not work yet. Is that expected, my mistake or a bug? Actually I was not able to make the {"color": {"hue" : 50, "saturation": 50} payload work on either the Zigbee-Converter nor the Zigbee-Command Node, only the {"color": { "hex* : “#FF0000"} did work so far.

So if I can be of help testing or debugging, let me know.

Thanks Again

Kneip

BTW: If you prefer to continue in DE, just let me know , on Github I typically start in EN

@hobbyquaker
Copy link
Member

Can you pls show me the Device Data that you can find in the Herdsman-Node:

Bildschirmfoto 2019-10-21 um 18 51 52

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 21, 2019

Klar: Here we go

`{
    "ieeeAddr": "0x14b457fffe27a7fe",
    "applicationVersion": 17,
    "dateCode": "20180410",
    "endpoints": [
        {
            "ID": 1,
            "clusters": {
                "genBasic": {
                    "attributes": {
                        "modelId": "TRADFRI bulb E27 CWS opal 600lm",
                        "manufacturerName": "IKEA of Sweden",
                        "powerSource": 1,
                        "zclVersion": 1,
                        "appVersion": 17,
                        "stackVersion": 87,
                        "hwVersion": 1,
                        "dateCode": "20180410",
                        "swBuildId": "1.3.009"
                    }
                }
            },
            "deviceNetworkAddress": 19931,
            "deviceIeeeAddr": "0x14b457fffe27a7fe",
            "inputClusters": [
                0,
                3,
                4,
                5,
                6,
                8,
                768,
                2821,
                4096
            ],
            "outputClusters": [
                5,
                25,
                32,
                4096
            ],
            "profileID": 49246,
            "binds": []
        }
    ],
    "hardwareVersion": 1,
    "interviewCompleted": true,
    "interviewing": false,
    "lastSeen": 1571682875758,
    "manufacturerID": 4476,
    "manufacturerName": "IKEA of Sweden",
    "modelID": "TRADFRI bulb E27 CWS opal 600lm",
    "networkAddress": 19931,
    "powerSource": "Mains (single phase)",
    "softwareBuildID": "1.3.009",
    "stackVersion": 87,
    "type": "Router",
    "zclVersion": 1,
    "meta": {
        "name": "Tischlampe",
        "isReportable": true,
        "isPingable": true,
        "offline": false
    }
}

Additonal Info: In the meantime I have connected an Osram Lightify Classic RGBW60, which works perfectly. In case that helps, here is the device info as well:

{
    "ieeeAddr": "0x8418260000ca6eee",
    "endpoints": [
        {
            "ID": 3,
            "clusters": {
                "genBasic": {
                    "attributes": {
                        "modelId": "Classic A60 RGBW",
                        "manufacturerName": "OSRAM",
                        "powerSource": 1,
                        "zclVersion": 1
                    }
                },
                "genOnOff": {
                    "attributes": {
                        "onOff": 1
                    }
                },
                "genLevelCtrl": {
                    "attributes": {
                        "currentLevel": 254
                    }
                },
                "lightingColorCtrl": {
                    "attributes": {
                        "colorTemperature": 370,
                        "enhancedCurrentHue": 0,
                        "colorMode": 2,
                        "currentY": 24701,
                        "currentX": 24939,
                        "currentSaturation": 0
                    }
                }
            },
            "deviceNetworkAddress": 40813,
            "deviceIeeeAddr": "0x8418260000ca6eee",
            "inputClusters": [
                4096,
                0,
                3,
                4,
                5,
                6,
                8,
                768,
                64527
            ],
            "outputClusters": [
                25
            ],
            "profileID": 49246,
            "binds": [
                {
                    "target": {
                        "ID": 1,
                        "profileID": 260,
                        "deviceID": 5,
                        "inputClusters": [],
                        "outputClusters": [],
                        "deviceNetworkAddress": 0,
                        "deviceIeeeAddress": "0x00124b000766ccab",
                        "clusters": {},
                        "_binds": []
                    },
                    "cluster": 6
                },
                {
                    "target": {
                        "ID": 1,
                        "profileID": 260,
                        "deviceID": 5,
                        "inputClusters": [],
                        "outputClusters": [],
                        "deviceNetworkAddress": 0,
                        "deviceIeeeAddress": "0x00124b000766ccab",
                        "clusters": {},
                        "_binds": []
                    },
                    "cluster": 8
                },
                {
                    "target": {
                        "ID": 1,
                        "profileID": 260,
                        "deviceID": 5,
                        "inputClusters": [],
                        "outputClusters": [],
                        "deviceNetworkAddress": 0,
                        "deviceIeeeAddress": "0x00124b000766ccab",
                        "clusters": {},
                        "_binds": []
                    },
                    "cluster": 768
                }
            ]
        }
    ],
    "interviewCompleted": false,
    "interviewing": false,
    "lastSeen": 1571681747167,
    "manufacturerID": 48042,
    "manufacturerName": "OSRAM",
    "modelID": "Classic A60 RGBW",
    "networkAddress": 40813,
    "powerSource": "Mains (single phase)",
    "type": "Router",
    "zclVersion": 1,
    "meta": {
        "name": "Jörns Licht",
        "isReportable": true,
        "isPingable": true,
        "shouldReport": true,
        "reporting": true,
        "shouldPing": true,
        "offline": true
    }
}

With the Osram one I have connection problems, but that is a different story ;-)

KR

Kneip

PS: If I take a look at the input clusters, I guess it is an upstream problem, right?

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 21, 2019

New effect with Redmatic 5.1.2:

Now Herdsman Nodes reports

"Cannot read property '0x14b457fffe27a7fe' of undefined"

for all kinds of Bulbs, although details are shown in herdsman node. This also means that currently nothing shows up in Homekit for me. I will try to update the ZIGBEE HK node, and will come back if that changes anything.

I tried repairing, bulb shows as expected in GUI, but error is back. Nevertheless I can still control the device with on off. Here is the new output like above of the same Tradfri bulb:

{
    "ieeeAddr": "0x14b457fffe27a7fe",
    "applicationVersion": 17,
    "dateCode": "20180410",
    "endpoints": [
        {
            "ID": 1,
            "clusters": {
                "genBasic": {
                    "attributes": {
                        "modelId": "TRADFRI bulb E27 CWS opal 600lm",
                        "manufacturerName": "IKEA of Sweden",
                        "powerSource": 1,
                        "zclVersion": 1,
                        "appVersion": 17,
                        "stackVersion": 87,
                        "hwVersion": 1,
                        "dateCode": "20180410",
                        "swBuildId": "1.3.009"
                    }
                }
            },
            "deviceNetworkAddress": 64903,
            "deviceIeeeAddr": "0x14b457fffe27a7fe",
            "inputClusters": [
                0,
                3,
                4,
                5,
                6,
                8,
                768,
                2821,
                4096
            ],
            "outputClusters": [
                5,
                25,
                32,
                4096
            ],
            "profileID": 49246,
            "binds": []
        }
    ],
    "hardwareVersion": 1,
    "interviewCompleted": true,
    "interviewing": false,
    "lastSeen": 1571685536558,
    "manufacturerID": 4476,
    "manufacturerName": "IKEA of Sweden",
    "modelID": "TRADFRI bulb E27 CWS opal 600lm",
    "networkAddress": 64903,
    "powerSource": "Mains (single phase)",
    "softwareBuildID": "1.3.009",
    "stackVersion": 87,
    "type": "Router",
    "zclVersion": 1,
    "meta": {
        "name": "Tischlampe",
        "isReportable": true,
        "isPingable": true,
        "offline": false
    }
}

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 21, 2019

OK, last issue resolved. I deleted the old node and re-added the ZIGBEE HK node. First I thought I still get the error, but it only took a little time for the bulbs to show up in the selection list, now above error is gone.

@hobbyquaker
Copy link
Member

hobbyquaker commented Oct 22, 2019

Can you pls try to add the manufName and ModelID to the file /usr/local/addons/redmatic/lib/node_modules/node-red-contrib-zigbee/zigbee-devices/zll.color.js /usr/local/addons/redmatic/lib/node_modules/redmatic-homekit/zigbee-devices/zll.color.js like this:

const Accessory = require('./lib/accessory');

module.exports = class ZllColor extends Accessory {
    static get manufacturerName() {
        return ['IKEA of Sweden'];
    }

    static get modelID() {
        return ['TRADFRI bulb E27 CWS opal 600lm'];
    }

and report back if that works?

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 22, 2019

Is it correct I had to create the folder zigbee-devices and the contained file? If so, nothing changed. If not, I guess I have an installation problem...

In case it might help you: Debug does not show any messages, attached is the last bit of CCU logs.

ct 22 22:31:32 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 229
Oct 22 22:31:32 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":41688,"direction":0,"transtime":0}
Oct 22 22:31:32 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 28
Oct 22 22:31:32 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":71,"transtime":0}
Oct 22 22:31:33 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":41688,"direction":0,"transtime":0} Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:34 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 244
Oct 22 22:31:34 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":44418,"direction":0,"transtime":0}
Oct 22 22:31:34 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 45
Oct 22 22:31:34 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":114,"transtime":0}
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 242
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":44054,"direction":0,"transtime":0}
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 73
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":185,"transtime":0}
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 241
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":43872,"direction":0,"transtime":0}
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 79
Oct 22 22:31:35 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":201,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 358
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":65171,"direction":0,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 5
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":13,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 18
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":3277,"direction":0,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 79
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":201,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 17
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":3095,"direction":0,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 5
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":13,"transtime":0}
Oct 22 22:31:36 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl moveToSaturation {"saturation":13,"transtime":0} Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:37 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 162
Oct 22 22:31:37 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":29491,"direction":0,"transtime":0}
Oct 22 22:31:37 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 57
Oct 22 22:31:37 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":145,"transtime":0}
Oct 22 22:31:38 ccu daemon.debug node-red[8154]: [zigbee-shepherd:zigbee herdsman] read 0x14b457fffe27a7fe Tischlampe 1 genBasic ["zclVersion"] 
Oct 22 22:31:38 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":29491,"direction":0,"transtime":0} Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:39 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl moveToSaturation {"saturation":145,"transtime":0} Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:39 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Hue 163
Oct 22 22:31:39 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":29673,"direction":0,"transtime":0}
Oct 22 22:31:39 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] set 0 Saturation 91
Oct 22 22:31:39 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command Tischlampe lightingColorCtrl moveToSaturation {"saturation":231,"transtime":0}
Oct 22 22:31:40 ccu daemon.debug node-red[8154]: [zigbee-shepherd:zigbee herdsman] ping 0x14b457fffe27a7fe Tischlampe Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:40 ccu daemon.debug node-red[8154]: [ccu-connection:localhost] rpcCheckInit BidCos-RF 20 60
Oct 22 22:31:40 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl enhancedMoveToHue {"enhancehue":29673,"direction":0,"transtime":0} Data request failed with error: 'MAC no ack' (233)
Oct 22 22:31:41 ccu daemon.debug node-red[8154]: [redmatic-homekit-zigbee-devices:2470908.682df7] command error Tischlampe lightingColorCtrl moveToSaturation {"saturation":231,"transtime":0} Data request failed with error: 'MAC no ack' (233)

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 28, 2019

Looks that I did something wrong the last time, I have reimplemented the file, rebooted the Raspbi and now the clusters show up in the command node. Will keep you updated when being home tonight to see whether the color picker in HK is now working.

@hobbyquaker
Copy link
Member

Oh, sorry. I gave you the wrong path. Corrected it in my answer above (#189 (comment))

@kneip68
Copy link
Contributor Author

kneip68 commented Oct 28, 2019

The change in the file did not do anything, the bulb shows up in the zigbee HK node (in contrast to #197) , on/off and level can be controlled, but hue and saturation does not work.
Actually even with the command node and cluster lightingColorControl, I can not use currentHue or currentSaturation for read or command moveToHue with payload {"hue":100,"direction":0,"transtime":0}. If I query the bulb, it says ColorCapabilities = 8 which would translate to bin1000, which in turn according to ZCL/ZLL Cluster User guide would be CIE XY capabilities, but no hue/sat. From that I would still think we have an upstream problem coming from a converter definitions. Just to make sure, here is the complete file as on my system, I hope I did edit it correctly:
`cat /usr/local/addons/redmatic/lib/node_modules/redmatic-homekit/zigbee-devices/zll.color.js

const Accessory = require('./lib/accessory');

module.exports = class ZllColor extends Accessory {
static get manufacturerName() {
return ['IKEA of Sweden'];
}

static get modelID() {
    return ['TRADFRI bulb E27 CWS opal 600lm'];
}

static get deviceID() {
    return [0x200];
}

init(device) {
    const ep = device.endpoints[0].ID;
    this.addService('Lightbulb', device.meta.name)
        .get('On', ep, 'genOnOff', 'onOff', data => Boolean(data))
        .set('On', ep, 'genOnOff', data => {
            return {command: data ? 'on' : 'off', payload: {}};
        })

        .get('Brightness', ep, 'genLevelCtrl', 'currentLevel', data => Math.round(data / 2.54))
        .set('Brightness', ep, 'genLevelCtrl', data => {
            return {command: 'moveToLevel', payload: {level: Math.round(data * 2.54), transtime: 0}};
        })

        .get('Hue', ep, 'lightingColorCtrl', 'enhancedCurrentHue', data => Math.round(data / 65535 * 360))
        .set('Hue', ep, 'lightingColorCtrl', data => {
            return {command: 'enhancedMoveToHue', payload: {enhancehue: Math.round(data * 65535 / 360), direction: 0, transtime: 0}};
        })

        .get('Saturation', ep, 'lightingColorCtrl', 'currentSaturation', data => Math.round(data / 2.54))
        .set('Saturation', ep, 'lightingColorCtrl', data => {
            return {command: 'moveToSaturation', payload: {saturation: Math.round(data * 2.54), transtime: 0}};
        });
}

};
`
With my limited skills for reading code, I would think that with this file you are trying to recalculate values before you inject them to the zigbee functions, so I guess that we would need to define an internal conversion from hue/sat to XY values, I will try to investigate. Could a second device type just be added to the same file, then I would try to develop and test the code.

@kneip68
Copy link
Contributor Author

kneip68 commented Nov 2, 2019

Brief update: I found a github project in javascript which does do the conversion between hue/sat/bri and XY at https://github.com/athombv/com.ikea.tradfri which in turn uses conversions from a package from https://www.npmjs.com/package/color-space, but I am not good enough a progammer to integrate all this into a new Accessory class. I decided to go the route of a custom flow in node red using the universal homekit node. Will post here again when finished.

@kneip68
Copy link
Contributor Author

kneip68 commented Nov 4, 2019

While looking for other solutions, it now shows that this a limitation on hue/sat for the tradfri bulbs. It has been discussed at Kkoenks site already: hue/saturation color mode not working · Issue #1012

@kneip68
Copy link
Contributor Author

kneip68 commented Nov 8, 2019

For anybody who wants to have color control on the Tradffri Color Bulbs, here is a flow which seems to work for me after initial testing (using the custom node). I will close the issue for he moment, and if I get to be able to come up with a accessory class will put a pull request referencing the issue.
[ { "id": "3622156e.ab937a", "type": "tab", "label": "Flow 1", "disabled": false, "info": "" }, { "id": "32054431.85bc4c", "type": "redmatic-homekit-universal", "z": "3622156e.ab937a", "bridgeConfig": "", "name": "Test Bulb", "services": [ { "subtype": "0", "service": "Lightbulb", "name": "Test Bulb" } ], "x": 520, "y": 440, "wires": [ [ "218720f9.ab3c2" ] ] }, { "id": "aa8d915d.aaf6a", "type": "inject", "z": "3622156e.ab937a", "name": "0/Brightness", "topic": "0/Brightness", "payload": "Lampe1_brightness", "payloadType": "flow", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "x": 310, "y": 400, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "421493a.4f7f26c", "type": "inject", "z": "3622156e.ab937a", "name": "0/Hue", "topic": "0/Hue", "payload": "Lampe1_hue", "payloadType": "flow", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "x": 330, "y": 440, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "df1a38e3.8e5568", "type": "inject", "z": "3622156e.ab937a", "name": "0/Saturation", "topic": "0/Saturation", "payload": "Lampe1_sat", "payloadType": "flow", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "x": 310, "y": 480, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "96c4a09c.68b53", "type": "color-convert", "z": "3622156e.ab937a", "input": "hsv", "output": "hex", "outputType": "string", "scaleInput": true, "x": 950, "y": 500, "wires": [ [ "bee56c22.6e828" ] ] }, { "id": "cb25cf06.2bc19", "type": "function", "z": "3622156e.ab937a", "name": "Set Array", "func": "var hue = flow.get(\"Lampe1_hue\");\nvar sat = flow.get(\"Lampe1_sat\");\nvar bri = flow.get(\"Lampe1_brightness\");\n\nif (msg.topic == \"0/Saturation\") {\n sat = msg.payload;\n flow.set(\"Lampe1_sat\",sat);\n }\nif (msg.topic == \"0/Hue\") {\n hue = msg.payload;\n flow.set(\"Lampe1_hue\",hue);\n }\n\nmsg.payload = [hue,sat,bri];\n\nreturn msg;", "outputs": 1, "noerr": 0, "x": 800, "y": 500, "wires": [ [ "96c4a09c.68b53" ] ] }, { "id": "218720f9.ab3c2", "type": "switch", "z": "3622156e.ab937a", "name": "Topic", "property": "topic", "propertyType": "msg", "rules": [ { "t": "eq", "v": "0/On", "vt": "str" }, { "t": "eq", "v": "0/Brightness", "vt": "str" }, { "t": "else" } ], "checkall": "false", "repair": false, "outputs": 3, "x": 670, "y": 440, "wires": [ [ "3c6145ae.4b5cca" ], [ "415971ba.a6be4" ], [ "cb25cf06.2bc19" ] ] }, { "id": "3c6145ae.4b5cca", "type": "change", "z": "3622156e.ab937a", "name": "0/On", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "{\"state\":\"TOGGLE\"}", "tot": "json" }, { "t": "set", "p": "topic", "pt": "msg", "to": "zigbee/${ieeeAddr}/set", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1090, "y": 420, "wires": [ [ "e9cc97e8.6c2be8" ] ] }, { "id": "e9cc97e8.6c2be8", "type": "zigbee-converter", "z": "3622156e.ab937a", "shepherd": "", "name": "Stehlampe", "topic": "zigbee/${name}", "settopic": "zigbee/${name}/set", "gettopic": "zigbee/${name}/get", "device": "0x14b457fffe27a7fe", "attribute": "", "payload": "plain", "x": 1270, "y": 440, "wires": [ [ "c47d6be2.c6c9b8" ] ] }, { "id": "7461a344.23d62c", "type": "change", "z": "3622156e.ab937a", "name": "onOff", "rules": [ { "t": "change", "p": "topic", "pt": "msg", "from": "zigbee/Lampe1/state", "fromt": "str", "to": "0/On", "tot": "str" }, { "t": "change", "p": "payload", "pt": "msg", "from": "ON", "fromt": "str", "to": "true", "tot": "bool" }, { "t": "change", "p": "payload", "pt": "msg", "from": "OFF", "fromt": "str", "to": "false", "tot": "bool" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1050, "y": 240, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "415971ba.a6be4", "type": "change", "z": "3622156e.ab937a", "name": "0/Brightness", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "zigbee/${ieeeAddr}/set", "tot": "str" }, { "t": "set", "p": "Lampe1_brightness", "pt": "flow", "to": "payload", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "{\"brightness\" : $round(payload * 2.55, 0)}", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1070, "y": 460, "wires": [ [ "e9cc97e8.6c2be8" ] ] }, { "id": "c47d6be2.c6c9b8", "type": "switch", "z": "3622156e.ab937a", "name": "Topic", "property": "topic", "propertyType": "msg", "rules": [ { "t": "eq", "v": "zigbee/Lampe1/state", "vt": "str" }, { "t": "eq", "v": "zigbee/Lampe1/brightness", "vt": "str" }, { "t": "else" } ], "checkall": "false", "repair": false, "outputs": 3, "x": 510, "y": 280, "wires": [ [ "7461a344.23d62c" ], [ "6b8ee3dd.e9e75c" ], [ "6e52d977.042548" ] ] }, { "id": "6b8ee3dd.e9e75c", "type": "change", "z": "3622156e.ab937a", "name": "Brightness", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "0/Brightness", "tot": "str" }, { "t": "set", "p": "payload", "pt": "msg", "to": "$round(payload/2.55, 0)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1030, "y": 280, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "bee56c22.6e828", "type": "change", "z": "3622156e.ab937a", "name": "color", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "{\t \"color\": {\t \"hex\" : payload\t }\t}", "tot": "jsonata" }, { "t": "set", "p": "topic", "pt": "msg", "to": "zigbee/${ieeeAddr}/set", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1090, "y": 500, "wires": [ [ "e9cc97e8.6c2be8" ] ] }, { "id": "6e52d977.042548", "type": "function", "z": "3622156e.ab937a", "name": "cie_to_rgb", "func": "var x = msg.payload.x;\nvar y = msg.payload.y;\nvar brightness = flow.get(\"0x14b457fffe27a7fe_brightness\");\n\n//msg.payload = { \"msg.payload.x\": x, \"msg.payload.y\": y, \"brightness\": brightness };\n\n\tvar z = 1.0 - x - y;\n\tvar Y = brightness / 100;\n\tvar X = (Y / y) * x;\n\tvar Z = (Y / y) * z;\n\n\n\n\t//Convert to RGB using Wide RGB D65 conversion\n\tvar red = X * 1.656492 - Y * 0.354851 - Z * 0.255038;\n\tvar green = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;\n\tvar blue = X * 0.051713 - Y * 0.121364 + Z * 1.011530;\n\t\n\n\t//If red, green or blue is larger than 1.0 set it back to the maximum of 1.0\n\tif (red > blue && red > green && red > 1.0) {\n\n\t\tgreen = green / red;\n\t\tblue = blue / red;\n\t\tred = 1.0;\n\t}\n\telse if (green > blue && green > red && green > 1.0) {\n\n\t\tred = red / green;\n\t\tblue = blue / green;\n\t\tgreen = 1.0;\n\t}\n\telse if (blue > red && blue > green && blue > 1.0) {\n\n\t\tred = red / blue;\n\t\tgreen = green / blue;\n\t\tblue = 1.0;\n\t}\n\n\t//Reverse gamma correction\n\tred = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, (1.0 / 2.4)) - 0.055;\n\tgreen = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, (1.0 / 2.4)) - 0.055;\n\tblue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, (1.0 / 2.4)) - 0.055;\n\n\n\t//Convert normalized decimal to decimal\n\tred = Math.min(Math.max(Math.round(red * 255), 0), 255);\n\tgreen = Math.min(Math.max(Math.round(green * 255), 0), 255);\n\tblue = Math.min(Math.max(Math.round(blue * 255), 0), 255);\n\n\tif (isNaN(red))\n\t\tred = 0;\n\n\tif (isNaN(green))\n\t\tgreen = 0;\n\n\tif (isNaN(blue))\n\t\tblue = 0;\n\t\t\n msg.payload = [red, green, blue];\n\n\n\n\treturn msg;\n\n\n", "outputs": 1, "noerr": 0, "x": 670, "y": 320, "wires": [ [ "bfb94cde.5d6a4" ] ] }, { "id": "bfb94cde.5d6a4", "type": "color-convert", "z": "3622156e.ab937a", "input": "rgb", "output": "hsl", "outputType": "array", "scaleInput": true, "x": 830, "y": 320, "wires": [ [ "67f25b0.23328a4", "d7693cdd.86a95" ] ] }, { "id": "67f25b0.23328a4", "type": "change", "z": "3622156e.ab937a", "name": "0/Hue", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "0/Hue", "tot": "str" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload[0]", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1050, "y": 320, "wires": [ [ "32054431.85bc4c" ] ] }, { "id": "d7693cdd.86a95", "type": "change", "z": "3622156e.ab937a", "name": "0/Saturation", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "0/Saturation", "tot": "str" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload[1]", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1030, "y": 360, "wires": [ [ "32054431.85bc4c" ] ] } ]

Oh, and the two functions used:
Set Array Node:
`var hue = flow.get("Lampe1_hue");
var sat = flow.get("Lampe1_sat");
var bri = flow.get("Lampe1_brightness");

if (msg.topic == "0/Saturation") {
sat = msg.payload;
flow.set("Lampe1_sat",sat);
}
if (msg.topic == "0/Hue") {
hue = msg.payload;
flow.set("Lampe1_hue",hue);
}

msg.payload = [hue,sat,bri];

return msg;`

cie_to_rgb node:
`var x = msg.payload.x;
var y = msg.payload.y;
var brightness = flow.get("0x14b457fffe27a7fe_brightness");

//msg.payload = { "msg.payload.x": x, "msg.payload.y": y, "brightness": brightness };

var z = 1.0 - x - y;
var Y = brightness / 100;
var X = (Y / y) * x;
var Z = (Y / y) * z;



//Convert to RGB using Wide RGB D65 conversion
var red = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
var green = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
var blue = X * 0.051713 - Y * 0.121364 + Z * 1.011530;


//If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
if (red > blue && red > green && red > 1.0) {

	green = green / red;
	blue = blue / red;
	red = 1.0;
}
else if (green > blue && green > red && green > 1.0) {

	red = red / green;
	blue = blue / green;
	green = 1.0;
}
else if (blue > red && blue > green && blue > 1.0) {

	red = red / blue;
	green = green / blue;
	blue = 1.0;
}

//Reverse gamma correction
red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, (1.0 / 2.4)) - 0.055;
green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, (1.0 / 2.4)) - 0.055;
blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, (1.0 / 2.4)) - 0.055;


//Convert normalized decimal to decimal
red = Math.min(Math.max(Math.round(red * 255), 0), 255);
green = Math.min(Math.max(Math.round(green * 255), 0), 255);
blue = Math.min(Math.max(Math.round(blue * 255), 0), 255);

if (isNaN(red))
	red = 0;

if (isNaN(green))
	green = 0;

if (isNaN(blue))
	blue = 0;
	
msg.payload = [red, green, blue];



return msg;`

@kneip68 kneip68 closed this as completed Nov 8, 2019
@spiu16
Copy link

spiu16 commented Nov 8, 2019

@kneip68 funktioniert super! nur erst vorher "node-red-contrib-color-convert" installieren.
Danke für deine Arbeit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants