# Hue magic and tuya LSC

**URL:** <https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059>\
**Category:** General\
**Created:** [5 September 2023 17:08 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059 "2023-09-05T17:08:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [5 September 2023 17:08 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/1 "2023-09-05T17:08:38Z")

</div>

Hello,

new to Node-RED, I'm gradually discovering the immense possibilities it offers. I've successfully integrated my Hue lights using Node Hue Magic, and everything is working correctly. I've also integrated non-Zigbee Tuya LSC devices using node-red-contrib-tuya-smart-device, and that's all fine too. However, I still have a question. I would like one of my Hue bulbs to be able to send its color state to a Tuya device to synchronize them together. I'm trying to retrieve the status of the Hue bulb, perhaps by creating a looptimer that fetches its status every 2 seconds and then sends it to the Tuya Wi-Fi device. Is this feasible?

If anyone has done this before, I'd appreciate your help in advance.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [5 September 2023 21:45 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/2 "2023-09-05T21:45:14Z")

</div>

You probably do not need to fetch the status of your zigbee lamp as mine send an update whenever an attribute changes. So, as long as you have the details of how to translate the output data from the zigbee lamp to the input required by the Tuya lamp this should be fairly straightforward.

If you are trying to match colours, brightness etc. you will probably have to do some experimentation to get the lamp outputs to match.

---

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [5 September 2023 22:08 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/3 "2023-09-05T22:08:33Z")

</div>

I'm going to try some tests, but if someone has the conversion function, it would be helpful to me because I'm just starting out, and it doesn't seem so easy, but it will help me learn how to use Node-RED a bit more.

---

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [5 September 2023 22:38 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/4 "2023-09-05T22:38:22Z")

</div>

I'm not quite sure how to create a function that takes the payload from a Hue bulb and returns the brightness, color, and state of the bulb. I'm looking at the API

> [tuyapi 7.2.0 | Documentation](https://codetheweb.github.io/tuyapi/index.html#tuyadeviceset)

, but it doesn't seem to be working right now. I'll continue working on it tomorrow. Thank you.

---

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [16 September 2023 15:07 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/5 "2023-09-16T15:07:33Z")

</div>

Hello,  
I'm still unable to pair a Hue bulb and a Tuya LSC bulb with Node-RED, nothing is working. I would like the Tuya light to follow the colors and brightness of the Hue light. I've also tried with Home Assistant and the group light feature, but without success. I've seen a node that should do this called "node-red-contrib-light," but I don't quite understand how it works. If anyone has a concrete example of this, I'm stuck. Thank you.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [17 September 2023 16:51 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/6 "2023-09-17T16:51:12Z")

</div>

If you supply the output from the Hue bulb - result in Node-RED (MQTT and debug node) and the required input to the Tuya bulb I will have a go

---

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [17 September 2023 21:56 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/7 "2023-09-17T21:56:29Z")

</div>

Thank you very much for looking into this. Regarding the Tuya input, I believe it's in the documentation I provided earlier. Otherwise, I'm not sure how to capture it. I might need a code to send for it. For the Hue, I received this code. {"on":true,"brightness":90.12,"brightnessLevel":229,"reachable":true,"connectionStatus":"connected","updated":"2023-09-17T23:47:44+02:00","rgb":[255,235,73],"hex":"ffeb49","xyColor":{"x":0.4524,"y":0.476},"color":"black","colorTemp":false,"colorTempName":"unknown"}

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [18 September 2023 21:14 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/8 "2023-09-18T21:14:53Z")

</div>

As you have installed the `node-red-contrib-tuya-smart-device` to get / set the Tuya bulb you should be able to control it by sending

```auto
msg.payload = {"dps":"20","set":true}

```

and you should get back something like

```auto
{"data":{"dps":{"20":true},"t":1695071477},"deviceId":"bfed04c9d469db879doe2y","deviceName":"Smart Bulb 04"}

```

These are some of the DPs that work for my lamps

```auto
Version 3.3 - Light Type (RGB)
DPS Function Point Type Range Units
20 Switch bool True/False 	
21 Mode enum white,colour,scene,music 	
22 Bright integer 10-1000 % * 10 	
23 Color Temp integer 0-1000 1,000,000 / kelvins
24 Color hexstring h:0-360,s:0-1000,v:0-1000 hsv (s & v * 10)

```

this function converts an HSV colour to the hex string used by my Tuya lamps

```auto

	/ ******************************************************************************
	* Description	Converts an HSV colour value to Tuya hexadecimal colour.
	* 
	* Assumes Hue in set [0, 360], Saturation and Value in the set [0, 100] and
	* returns Tuya colour as 12 character hexadecimal string
	* 
	*
	* @param {Object | number} hue - The hue as an integer or an HSV Object {hue, saturation, value})
	* @param {number} [saturation]	- The saturation
	* @param {number} [value] - The value
	* 
	* @returns {string} - A 12 character hexadecimal string as used by Tuya devices for colour
	* 
	* Note: To convert RGB colour to Tuya colour use RGBtoHSV() as input
	*/

	function HSVtoTuyaColour(hue, saturation, value) {
		// Note: hue = hue.hue MUST go last
		if (arguments.length === 1) {
			saturation = hue.saturation;
			value = hue.value;
			hue = hue.hue;

		}

		// Increase saturation & value to correct set [0, 1000]
		saturation = saturation * 10;
		value = value * 10;

		return HSVtoHexStr(hue, saturation, value);

	} // End Function HSVtoTuyaColour()

```

You will need to convert the zigbee RGB colour to HSV

---

<div class="post-metadata">

**Author:** ![davidd1205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davidd1205/32/82609_2.png) [@davidd1205](https://discourse.nodered.org/u/davidd1205)\
**Post date:** [20 September 2023 14:22 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/9 "2023-09-20T14:22:41Z")

</div>

Okay, thank you very much. I will try to understand all of this first. Yes, I have the same code for the Tuya LSC lamp, not Zigbee, only Wi-Fi. So, the conversion function from Hue to it might be different, but for now, I can't even turn it on when I connect them together. Thank you for all of this. But since I'm redoing all the home automation towards Node-RED, I have many other things to look at too. Right now, I've managed to control my IPX800 and parse all its content. It works great, at least that's something, haha!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 November 2023 14:22 UTC](https://discourse.nodered.org/t/hue-magic-and-tuya-lsc/81059/10 "2023-11-19T14:22:45Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
