Supergiovane / node-red-contrib-knx-ultimate

Control your KNX intallation via Node-Red! A bunch of KNX nodes, with integrated Philips HUE control and ETS group address importer.
https://youtu.be/egRbR_KwP9I
MIT License
141 stars 34 forks source link

Feature: Hue Light: Support for HSV color control #314

Closed ColdFireIce closed 5 months ago

ColdFireIce commented 6 months ago

Hi,

I really love the integration of the hue <-> KNX link. But one thing is missing to make it completly replace my custom flows. The MDT "Glass Push-button II Smart" support Color-Change only via a HSV color control. See 4.4.12 in the manual. It works with a 3.007 Dimmer to change either Hue, Saturation oder Value (Brightness) and as response: 5.003 Winkel (Grad) for Hue 5.001 Prozent (0..100%) for Saturation 5.001 Prozent (0..100%) for Value (Helligkeit)

In my current implementation I use the last received value and add the dimmer value until the stop command is received. (color is of course %360).

It would be really cool to have this function to use the link with these controllers.

Best regards!

Supergiovane commented 6 months ago

Hi, i'm taking a look at the user manual...

ColdFireIce commented 6 months ago

Excellent. If I can support you, let me know!

Supergiovane commented 6 months ago

Hi Cold, what's your name? I'm Max. Basically, it works like the "tunable white" controls, but with HUE, Saturation and brightness and with slight changes to the statuses GA.

Node-RED___192_168_1_16

I'll work on that. The main issue is to retrieve and read the HUE color wheel. Can you share here some code you used, to let me save some time?

ColdFireIce commented 6 months ago

Hi Max,

yes I think this is basically the case for saturation and brightness. For Hue its the degree on an color wheel. My current implementation is far from perfect, but basically it works like this:

My code looks like this:

[{"id":"0f254daf2271a72b","type":"looptimer2","z":"cc2d22b7145c4de5","duration":"0.5","units":"Second","maxloops":"100","maxtimeout":"1","maxtimeoutunits":"Minute","name":"","x":370,"y":220,"wires":[["3957120ceaf4e1e7","c647e9e28f005820"],["be82a6b2865fca59"]]},{"id":"939b714536929f5d","type":"function","z":"cc2d22b7145c4de5","name":"","func":"if (msg.payload.data === 0) {\n    return {payload:\"STOP\"}\n} else {\n    let sign = (msg.payload.decr_incr === 0) ? -1 : 1;\n    return {payload: sign * msg.payload.data * 10}\n}\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":220,"wires":[["0f254daf2271a72b"]]},{"id":"3957120ceaf4e1e7","type":"function","z":"cc2d22b7145c4de5","name":"hue -> HSV","func":"let flowHue = flow.get(\"colorHue\")\n\nlet hue = flowHue ? ((flow.get(\"colorHue\") + msg.payload) % 360) : 0\nhue = (hue < 0) ? hue +360 : hue; \nflow.set(\"colorHue\", hue)\n\nreturn {payload: [hue, 100, 100]};","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":220,"wires":[["bf38073094f528a7"]]},{"id":"bf38073094f528a7","type":"color-convert","z":"cc2d22b7145c4de5","input":"hsv","output":"rgb","outputType":"array","scaleInput":true,"x":1010,"y":220,"wires":[["cd866f929ab6820b"]]},{"id":"cd866f929ab6820b","type":"function","z":"cc2d22b7145c4de5","name":"-> payload.rgb","func":"\nreturn {payload: {rgb: msg.payload}};","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1200,"y":220,"wires":[[]]},{"id":"c647e9e28f005820","type":"change","z":"cc2d22b7145c4de5","name":"","rules":[{"t":"set","p":"running","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":200,"wires":[[]]},{"id":"be82a6b2865fca59","type":"change","z":"cc2d22b7145c4de5","name":"","rules":[{"t":"set","p":"running","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":260,"wires":[[]]}]

For saving the hue value I just convert the hue lamps RGB to HSV and save the H part:

[{"id":"52cfe893.a0bdc8","type":"change","z":"c73b7b76.eb5d18","name":"","rules":[{"t":"set","p":"colorHue","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":180,"wires":[[]]},{"id":"7f8a301e.f01a9","type":"color-convert","z":"c73b7b76.eb5d18","input":"rgb","output":"hsv","outputType":"array","scaleInput":false,"x":570,"y":180,"wires":[["419aeeac.de433"]]},{"id":"681f3a71.db4c64","type":"function","z":"c73b7b76.eb5d18","name":"payload.rgb ->","func":"return {payload: msg.payload.rgb};","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":180,"wires":[["7f8a301e.f01a9"]]},{"id":"419aeeac.de433","type":"function","z":"c73b7b76.eb5d18","name":"payload[0]","func":"\nreturn {payload: msg.payload[0]};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":180,"wires":[["fc1d950e.aaefb8"]]},{"id":"fc1d950e.aaefb8","type":"switch","z":"c73b7b76.eb5d18","name":"","property":"running","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":180,"wires":[[],["52cfe893.a0bdc8"]]}]

I hope this helps a little bit.

Best regards Daniel

ColdFireIce commented 6 months ago

A thing on the side: I played around with the HA template and noticed, that it is currently not possible to have color and tuneable white: https://community.home-assistant.io/t/solved-flapping-states-knx-light-card/667139/12 There are versions for https://www.home-assistant.io/integrations/knx/#rgbw_address but I don't have any KNX lights that support that.

I thought I share my findings as soon as possible for you.

Supergiovane commented 5 months ago

Hi Do you have your MDT set like this? https://youtu.be/cx85Y5eTSHQ?t=528

Supergiovane commented 5 months ago

Out in 2.4.5-beta.1 https://github.com/Supergiovane/node-red-contrib-knx-ultimate/milestone/24