Skip to content

Instantly share code, notes, and snippets.

@sstroot
Created March 2, 2019 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstroot/a2be61a889a6e6712fa0591ab1a69e35 to your computer and use it in GitHub Desktop.
Save sstroot/a2be61a889a6e6712fa0591ab1a69e35 to your computer and use it in GitHub Desktop.
Convert Loxone color string to Hue RGB

This flow converts a Loxone hsv(...) or temp(...) string from a LightControllerV2 directly to a RGB array.

You will need these nodes:

  • node-red-contrib-loxone
  • node-red-contrib-huemagic
  • node-red-contrib-color-convert

In Loxone:

  • Configure a LightControllerV2
  • Set the outputs to RGB

In Node-RED

  • Place a Loxone "control in" node and configure it with the LightControllerV2 and state color
  • Place a "Hue Lamp" or "Hue Group" node
  • Connect both with this flow. Loxone on the input and Hue on the output.

Loxone and Hue are now connected. The color and brightness setting in Loxone is then transferred to Hue.

[{"id":"7fa10a6e.8bda14","type":"subflow","name":"Loxone color string to Hue RGB","info":"","category":"","in":[{"x":327.5,"y":307,"wires":[{"id":"616f6d48.4176b4"}]}],"out":[{"x":1237.5,"y":319,"wires":[{"id":"21e6122.56392ee","port":0},{"id":"527b719d.025c7","port":0}]}]},{"id":"52121dad.3e9224","type":"color-convert","z":"7fa10a6e.8bda14","input":"hsv","output":"rgb","outputType":"array","x":898.5,"y":251,"wires":[["21e6122.56392ee"]]},{"id":"c0a01e2b.be63","type":"function","z":"7fa10a6e.8bda14","name":"split hsv","func":"msg.payload = msg.payload.replace(\"hsv(\", \"\").replace(\")\", \"\").split(\",\");\nflow.set(\"brightness\", msg.payload[2]);\nreturn msg;","outputs":1,"noerr":0,"x":732.5,"y":251,"wires":[["52121dad.3e9224"]]},{"id":"21e6122.56392ee","type":"function","z":"7fa10a6e.8bda14","name":"RGB > msg","func":"var brightness = flow.get(\"brightness\");\nif (brightness == '0') {\n return { payload: { on: false } };\n}\nreturn { payload: { on: true, rgb: msg.payload, brightness: brightness } };","outputs":1,"noerr":0,"x":1078.5,"y":251,"wires":[[]]},{"id":"616f6d48.4176b4","type":"switch","z":"7fa10a6e.8bda14","name":"hsv or temp","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"hsv(","vt":"str"},{"t":"cont","v":"temp(","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":518.5,"y":310,"wires":[["c0a01e2b.be63"],["fd3e393c.a0cbb8"]]},{"id":"fd3e393c.a0cbb8","type":"function","z":"7fa10a6e.8bda14","name":"spilt temp","func":"msg.payload = msg.payload.replace(\"temp(\", \"\").replace(\")\", \"\").split(\",\");\nreturn msg;","outputs":1,"noerr":0,"x":730.5,"y":368,"wires":[["527b719d.025c7"]]},{"id":"527b719d.025c7","type":"function","z":"7fa10a6e.8bda14","name":"Temp > RGB > msg","func":"var brightness = parseInt(msg.payload[0]);\nif (brightness == '0') {\n return { payload: { on: false } };\n}\n\nvar kelvin = parseFloat(msg.payload[1]);\nvar temp = kelvin / 100;\nvar red, green, blue;\n\nif (temp <= 66) { \n red = 255; \n\n green = temp;\n green = 99.4708025861 * Math.log(green) - 161.1195681661;\n\n if (temp <= 19) {\n blue = 0;\n } \n else {\n blue = temp - 10;\n blue = 138.5177312231 * Math.log(blue) - 305.0447927307;\n }\n} \nelse {\n red = temp - 60;\n red = 329.698727446 * Math.pow(red, -0.1332047592);\n\n green = temp - 60;\n green = 288.1221695283 * Math.pow(green, -0.0755148492 );\n\n blue = 255;\n\n}\n\nred = Math.round(Math.min(Math.max(red, 0), 255));\ngreen = Math.round(Math.min(Math.max(green, 0), 255));\nblue = Math.round(Math.min(Math.max(blue, 0), 255));\n\nreturn { payload: { on: true, rgb: [ red, green, blue ], brightness: brightness } };","outputs":1,"noerr":0,"x":920.5,"y":368,"wires":[[]]}]
@sstroot
Copy link
Author

sstroot commented Jan 13, 2020 via email

@knallt
Copy link

knallt commented Feb 2, 2020

Hi!
Thanks a lot for the converter. This works great.

I'm wondering if you have it by chance also into to other direction - Hue RGB to Loxone. I want to update/synch changes from e.g. the hue app or the remote control in the loxone ControlOut of the LightController.

Do you and how do you solve this?

@sstroot
Copy link
Author

sstroot commented Feb 3, 2020 via email

@liteworxav
Copy link

liteworxav commented Dec 23, 2021

Great work on the converter !!!

Do you have a converter for the Hue Ambiance Lamps?

Loxone sends out "temp(0,2700)"

0 being brightness
2700 being the colour temperature

Thanks

@sstroot
Copy link
Author

sstroot commented Dec 29, 2021

Yes, hsv(...) and temp(...) is supported.

@liteworxav
Copy link

Thanks sstrot :-) but for the Philips HUE Ambiance lamps (Warm White / Cool White only/ No RGB) it does not work

I had to use this flow to make it work:
https://discourse.nodered.org/t/node-red-loxone-philips-hue-ambiance/55617

[{"id":"0fad9fb9a5973506","type":"inject","z":"7351324319c98582","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"temp(100,2700)","payloadType":"str","x":250,"y":300,"wires":[["b33b52d374958461"]]},{"id":"b33b52d374958461","type":"change","z":"7351324319c98582","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"( \t $c:= $match(payload,/\((\d+),(\d+)\)/).groups; \t { \t "brightness":$number($c[0]),\t "colorTemp":$round(1000000/$number($c[1]),0) \t }\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":300,"wires":[["5e5a58324f26fd0c"]]},{"id":"5e5a58324f26fd0c","type":"debug","z":"7351324319c98582","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":300,"wires":[]}]

111

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