Set up colorpicker for mqtt device

  • Platform information:
    • Hardware: Raspberry Pi 4
    • openHAB version: 3.4.0

Hello together,

as I´m out of ideas after trying for hours i want to ask for help.

Im setting up a Tint Aris LED Panel. I use zigbee2mqtt to connect all my devices. On/Off and Brightness are already working fine but i stuck with the colors.

The panel supports color xy, rgb and hex. As i learned a colorpicker works with HSB. When i manually send a payload

{"color":{"r":255,"g":0,"b":0}}

to the panel with Mqtt.fx im able to change the color but im not able to set this up in my configuration.

There a lot of informations about HSB to RGB but i dont understand how to put these informations together to get the payload i need. Any ideas?

I tried a lot, this is my latest setup:

Items:

Switch                     LivingRoomMainLight            "Hauptlicht"                      <lightbulb>    (gLight,eLightLivingroom)            ["Light","Switch"]    {channel="mqtt:topic:livingroom:main_light"}
Dimmer                     LivingRoomMainBrightness       "Helligkeit Hauptlicht [%s]"      <lightbulb>    (eLightLivingroom)                   ["Light"]             {channel="mqtt:topic:livingroom:main_light_brightness", ga="Light", synonyms="Hauptlicht", roomHint="Wohnzimmer"}
Color                      LivingRoomMainLightColor       "Farbe"                           <lightbulb>    (eLightLivingroom)                   ["Light"]             {channel="mqtt:topic:livingroom:main_light_color2", ga="Light", synonyms="Hauptlicht Farbe", roomHint="Wohnzimmer"}

Things:

Thing  mqtt:topic:livingroom "MQTT Living Room" (mqtt:broker:Zigbee2Mqtt) {
    Channels:
//mueller licht
        Type switch : main_light    "Hauptlicht"    [ stateTopic="zigbee2mqtt/LivingRoomMain/state", commandTopic="zigbee2mqtt/LivingRoomMain/set", on="ON", off="OFF"] 
        Type dimmer : main_light_brightness "Hauptlicht Helligkeit" [ stateTopic="zigbee2mqtt/LivingRoomMain", transformationPatternOut="JS:openhabdimmer2zigbeebridge.js", transformationPattern="JS:tradfri2openhab.js" ,commandTopic="zigbee2mqtt/LivingRoomMain/set", min=0, max=100, step=1]
        Type color : main_light_color2   "Hauptlicht Farbe" [ stateTopic="zigbee2mqtt/LivingRoomMain", commandTopic="zigbee2mqtt/LivingRoomMain/set", transformationPattern="JSONPATH:$.color", colorMode="RGB", formatBeforePublish="{\"color\":{\"r\":255,\"g\":0,\"b\":0}}"] //
        Type string : main_light_effect "Hauptlicht Effekt" [ stateTopic="zigbee2mqtt/LivingRoomMain", commandTopic="zigbee2mqtt/LivingRoomMain/set", transformationPattern="JSONPATH:$.effect" ]
}

Sitemap:

Colorpicker item=LivingRoomMainLightColor label="Farbe" icon="colorwheel"

Actual error message within zigbee2mqtt:

2023-02-04 08:57:59</small>`Publish 'set' 'color' to 'LivingRoomMain' failed: 'Error: Value does not contain valid color definition'`

Default pattern for formatBeforePublish for RGB: "%1$d,%2$d,%3$d"
"{\"color\":{\"r\":%1$d,\"g\":%2$d,\"b\":%3$d}}" might work.

1 Like

good hint. i guess i had kinda double color attribut in my transformation.

This one is working:

Item:

Color                      LivingRoomMainLightColor       "Farbe"                           <lightbulb>    (eLightLivingroom)                   ["Light"]             {channel="mqtt:topic:livingroom:main_light_color", ga="Light", synonyms="Hauptlicht Farbe", roomHint="Wohnzimmer"}

Thing:

Type color : main_light_color   "Hauptlicht Farbe" [ stateTopic="zigbee2mqtt/LivingRoomMain/color", commandTopic="zigbee2mqtt/LivingRoomMain/set", colorMode="RGB", formatBeforePublish="{\"color\":{\"r\":%1$d,\"g\":%2$d,\"b\":%3$d}}"]

Hello,

I’m having the same issue, but this solution haven’t worked for me. I know I’m close, maybe someone could give me a hint. I’m a total noob in transformations, jsonpaths and all that creepy stuff.

In MQTT explorer, if I send

zigbee2mqtt/TVLight/set
{"color":{"r":255,"g":0,"b":100}}

The colors change and I can see in MQTT explorer that the correct MQTT path is addressed:

TVLight = {"brightness":191.25,"color":{"h":352,"hue":352,"s":100,"saturation":100,"x":0.6224,"y":0.2634},"color_mode":"xy","color_power_on_behavior":"initial","color_temp":136,"do_not_disturb":false,"linkquality":54,"state":"ON"}
get = {"state": ""}
set = {"color":{"r":255,"g":0,"b":100}}

However, when I try to do it via the OpenHab item, the “set” item is addressed incompletely:

TVLight = {"brightness":191.25,"color":{"h":352,"hue":352,"s":100,"saturation":100,"x":0.6224,"y":0.2634},"color_mode":"xy","color_power_on_behavior":"initial","color_temp":136,"do_not_disturb":false,"linkquality":54,"state":"ON"}
get = {"state": ""}
set = 84,99,83

Any idea what am I doing wrong? My configuration:

Thing:

UID: mqtt:topic:My_Mosquitto:BBB-TESTE-DIMMER
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:My_Mosquitto
channels:
  - id: BBB-TESTE-STATE
    channelTypeUID: mqtt:switch
    label: BBB-TESTE-STATE
    description: BBB-TESTE-STATE
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set
      stateTopic: zigbee2mqtt/TVLight/get
  - id: BBB-TESTE-DIMMER
    channelTypeUID: mqtt:dimmer
    label: BBB-TESTE-DIMMER
    description: BBB-TESTE-DIMMER
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set/brightness
      min: 0
      stateTopic: zigbee2mqtt/TVLight/get/brightness
      max: 255
  - id: BBB-Color-Teste
    channelTypeUID: mqtt:color
    label: BBB-Color-Teste
    description: BBB-Color-Teste
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set
      Type color: main_light_color   "label" [ stateTopic="zigbee2mqtt/TVLight/color",
        commandTopic="zigbee2mqtt/TVLight/set", colorMode="RGB",
        formatBeforePublish="{\"color\":{\"r\":%1$d,\"g\":%2$d,\"b\":%3$d}}"]
      colorMode: RGB
      stateTopic: zigbee2mqtt/TVLight/get

Item:

label: BBB-Color-Teste
type: Color
category: colorwheel
groupNames: []
tags:
  - Point

The item profile is defined as default. I guess I should use jsonpath instead, but have no idea what expression to include there.

Any hint will be welcomed! I think I’m close.
Cheers,

Got it (by a lot of tentative/error)

UID: mqtt:topic:My_Mosquitto:BBB-TESTE-DIMMER
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:My_Mosquitto
channels:
  - id: BBB-TESTE-STATE
    channelTypeUID: mqtt:switch
    label: BBB-TESTE-STATE
    description: BBB-TESTE-STATE
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set
      stateTopic: zigbee2mqtt/TVLight/get
  - id: BBB-TESTE-DIMMER
    channelTypeUID: mqtt:dimmer
    label: BBB-TESTE-DIMMER
    description: BBB-TESTE-DIMMER
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set/brightness
      min: 0
      stateTopic: zigbee2mqtt/TVLight/get/brightness
      max: 255
  - id: BBB-Color-Teste
    channelTypeUID: mqtt:color
    label: BBB-Color-Teste
    description: BBB-Color-Teste
    configuration:
      commandTopic: zigbee2mqtt/TVLight/set
      colorMode: RGB
      formatBeforePublish: '{"color": {"r":%1$d,"g":%2$d,"b":%3$d}}'
      stateTopic: zigbee2mqtt/TVLight/get
      transformationPattern: JSONPATH:$.color

The profile in the item is default (no transformation).

With this configuration, I’m able to:

  • Switch on/off
  • Dim light intensity
  • Change color

Hope it helps someone that has the same difficulty as myself.