OH3 with zigbee2mqtt and Philips Hue Color Channel

Hi,
I am trying since hours to get the color channel of my Philips Hue
to work. The switch is no Problem, but I want to use the colorwheel in OH3.

I thougt I found a solution here : https://community.openhab.org/t/zigbee2mqtt-revisited-no-more-ugly-transformations/86362/206?u=vbbaby3 , but I can´t get it to work.

I have these two transformation files in the transform folder:
zigbeeColorIN.js

// example input: {"brightness":50,"color":{"hue":359,"saturation":100,"x":0.6942,"y":0.2963},"color_mode":"xy","color_temp":158}
(function(color){
        // convert 254 Steps to 100% of brightness
        var bright = Number(color.split(/[,:]/)[1]) / 2.54;
        // example output to openHAB: x,y,brightness - f.e.: 0.6942,0.2963,50
        return color.split(/[,:]/)[8] + "," + color.split(/[,:}]/)[10] + "," + bright.toFixed(0);
})(input)

and zigbeeColorOUT.js :

        // convert 100% to 254 Steps of brightness
        var bright = Number(color.split(/[,:]/)[2]) * 2.54;
        // example output to mqtt: {"brightness":239,"color":{"x":0.601297,"y":0.311017}}
        return '{"brightness":' + bright.toFixed(0) + ',"color":{"x":' + color.split(/[,:]/)[0] + ',"y":' + color.split(/[,:]/)[1] + '}}';
})(input)

In zigbee2mqtt I changed the output type to:
image

Here is my channel config:

UID: mqtt:topic:mqttBroker:mqtt_miffy_tom
label: Mqtt Miffy Tom
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mqttBroker
channels:
  - id: switch
    channelTypeUID: mqtt:switch
    label: switch
    description: null
    configuration:
      commandTopic: zigbee2mqtt/Miffy Tom/set/state
      stateTopic: zigbee2mqtt/Miffy Tom/state
      off: OFF
      on: ON
  - id: MQQTTZ2MColorCh1Test
    channelTypeUID: mqtt:color
    label: Miffy Tom Color
    description: null
    configuration:
      commandTopic: zigbee2mqtt/Miffy Tom/set
      colorMode: XYY
      transformationPatternOut: JS:zigbeeColorOUT.js
      formatBeforePublish: “%”
      stateTopic: zigbee2mqtt/Miffy Tom
      transformationPattern: JS:zigbeeColorIN.js

and my item:

But I have no chance to change the color…

@Airmr @AndreHimSelf Do you have any idea what is going wrong here ?

Hi,
mine is working. Following my transforms and screens from my config. I do config with textfiles.
Maybe try to translate my config to OH3 or just simply create a Thing Textfile and try if it works.

ZigbeeIn:

// example input: {"brightness":50,"color":{"hue":359,"saturation":100,"x":0.6942,"y":0.2963},"color_mode":"xy","color_temp":158}
(function(color){
	// convert 254 Steps to 100% of brightness
	var bright = Number(color.split(/[,:]/)[1]) / 2.54;
	// example output to openHAB: x,y,brightness - f.e.: 0.6942,0.2963,50
	return color.split(/[,:]/)[8] + "," + color.split(/[,:}]/)[10] + "," + bright.toFixed(0);
})(input)

Zigbeeout:

(function(color){
	// convert 100% to 254 Steps of brightness
	var bright = Number(color.split(/[,:]/)[2]) * 2.54;
	// example output to mqtt: {"brightness":239,"color":{"x":0.601297,"y":0.311017}}
	return '{"brightness":' + bright.toFixed(0) + ',"color":{"x":' + color.split(/[,:]/)[0] + ',"y":' + color.split(/[,:]/)[1] + '}}';
})(input)

image

Thing with Channels:

  Thing topic MQTTHueWhiteColor1 "MQTT Hue WhiteColor 1" @ "Hue" {
    Channels:
        Type switch : switch "MQTT Hue WhiteColor1 Switch" [ stateTopic="zigbee2mqtt/MQTTHueWhiteColor1/state", commandTopic="zigbee2mqtt/MQTTHueWhiteColor1/set", on="ON", off="OFF" ]
        Type dimmer : dimmer "MQTT Hue WhiteColor1 Dimmer" [ stateTopic="zigbee2mqtt/MQTTHueWhiteColor1/brightness", commandTopic="zigbee2mqtt/MQTTHueWhiteColor1/set/brightness", min=0, max=255]
        Type dimmer : colortemp "MQTT Hue WhiteColor1 TempDimmer" [ stateTopic="zigbee2mqtt/MQTTHueWhiteColor1/color_temp", commandTopic="zigbee2mqtt/MQTTHueWhiteColor1/set/color_temp", min=153, max=500]
        Type color : farbe "MQTT Hue WhiteColor1 Color" [ stateTopic="zigbee2mqtt/MQTTHueWhiteColor1", commandTopic="zigbee2mqtt/MQTTHueWhiteColor1/set", colorMode="XYY", transformationPattern="JS:zigbeeColorIN.js", transformationPatternOut="JS:zigbeeColorOUT.js"]
        Type number : lqi "MQTT Hue WhiteColor1 LQI" [stateTopic="zigbee2mqtt/MQTTHueWhiteColor1", transformationPattern="JSONPATH:$.linkquality"]
      }

In the Sitemap i can use the colorwheel.
image

        Colorpicker item=MQTTHueWhiteColor1Color label="Lampe Color [%s]"

Hey Jörg

Basics first:

  • Did you restart openHAB already?
  • Did you link the Item to the correct channel?
  • Does this work in the z2m Webinterface?

Grüße,
Andre

  • yes
  • yes
  • yes

Let me guess, the log file also doesn’t contain anything useful?

Could you at least turn the bulb on via openHAB? Or adjust the brightness f.e.?
So don’t use the color picker item, just a slider / dimmer for testing

1 Like

You are my Hero :slight_smile:
When I tested the slider i found out that something was wrong with the js transformation…after a reinstall, I got the colorpicker !
Thanks to @AndreHimSelf and @Airmr :+1:t3:

1 Like

Your welcome :slight_smile: :+1:

I’m having this exact same problem with OpenHab 4.2.2. I’ve confirmed that I can power the light on and off and that I can operate everything (including color) in M2Z. What did you mean when you said you reinstalled? What did you reinstall?

Never mind, I sorted it out. I believe it was a combination of needing to clear my cache and a misconfiguration on my channel.

On a side note, I noticed that one of my three bulbs in my ceiling fan was not publishing the same payload on the MQTT broker. The transformations still work, though.

MQTT publish: topic ‘zigbee2mqtt/Bulb1’, payload ‘{“brightness”:254,“color”:{“x”:0.410998,“y”:0.167833},“color_mode”:“xy”,“color_temp”:153,“linkquality”:255,“power_on_behavior”:“on”,“state”:“ON”,“update”:{“installed_version”:16787456,“latest_version”:16787456,“state”:“idle”}}’

MQTT publish: topic ‘zigbee2mqtt/Bulb2’, payload ‘{“brightness”:254,“color”:{“hue”:240,“saturation”:99,“x”:0.139178,“y”:0.044622},“color_mode”:“xy”,“color_temp”:500,“linkquality”:255,“state”:“ON”,“update”:{“installed_version”:16787456,“latest_version”:16787456,“state”:“idle”}}’