Json as MQTT output for zigbee light

Hey,

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: openhabian
    • openHAB version: 3
  • Issue of the topic:
    I have got a zigbee light and got it working via zigbee2mqtt. (this light: Lidl HG06106B control via MQTT | zigbee2mqtt.io) I can send commands to it via mqtt.fx. The commands are send via a json format. If I send commands via the Sitemap, the number e.g. 210 for color_temp, the output is just 210 and not converted to json ( What I want: {“color_temp”: 210})
    If I set the value manualy via MQTT.fx, the sitemap gets updated. So Jsonpath seems to be working.

How do I convert the number from the sitemap into a json message?

Configuration
Thing:

Thing mqtt:topic:e14 "Test Lampe " {
Channels:
    Type switch : e14_switch "Switch" [ stateTopic="zigbee2mqtt/e14" , commandTopic="zigbee2mqtt/e14/set", on="ON", off="OFF", transformationPattern="JSONPATH:$.state"]
    Type number : e14_birghtness "Brightness" [ stateTopic="zigbee2mqtt/e14" , commandTopic="zigbee2mqtt/e14/set", min=1, max=254, transformationPattern="JSONPATH:$.brightness" ]
    Type number : e14_temp "Color Temp" [ stateTopic="zigbee2mqtt/e14" , commandTopic="zigbee2mqtt/e14/set", min=150, max=500, transformationPattern="JSONPATH:$.color_temp" ]
    Type color : e14_color "Color" [stateTopic="zigbee2mqtt/e14", commandTopic="zigbee2mqtt/e14/set", transformationPattern="JSONPATH:$.color.rgb" ]
}

Item:
The Item is auto generated via the schemantic view (Create Equiptment from thing)
Sitemap:

Frame label="lampen" {
  Switch item=TestLampe_OnOffSwitch label="Lampe"
  Default item=TestLampe_ColorValueHSBRGBorCIExyY label="Farbe" 
  Slider item=TestLampe_E14_Birghtness label="Helligkeit[%d]" minValue=1 maxValue=254
  Slider item=TestLampe_E14_Temp label="Temperature [%d]" minValue=150 maxValue=500 step=10
}

Best Regards and thanks for the help
Schotte

I do not know how to set it in the textual configuration of a mqtt thing, but in the ui there is an option called “Outgoing value format”

In this area you should put your output format. I think it should some thing like this:

 {“color_temp”: %s}

on the other hand with zigbee2mqtt you cloud use the new command format and set Mqtt Command Topic to

zigbee2mqtt/<friendlyname>/set/color_temp

The you do nit need the json format. This should wirk with the new api version 0.17

1 Like

formatBeforePublish

Thank you guys a lot.
I found the keyword for the files. it is formatBeforePublish=

Type number : e14_birghtness "Brightness" [ stateTopic="zigbee2mqtt/e14" , commandTopic="zigbee2mqtt/e14/set", min=1, max=254, transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{ \"brightness\" : \"%s\" }" ]

I just needed to update the thing configurations.

I still have a problem with the color picker. It sends out 3 values, but it does not seem to be in RGB. It could be HSV, I am not realy sure.
I did find a post where the syntax for a thing would be

Color LEDStrip_1_Color “LEDStrip 1 Color”

Do I need to create a item in a text file like that? I did not find this kind of konfiguration in the GUI configuration…

1 Like

You should check the maxiumum values of the color picker. If value are 255 it is RGB. If one value is 360 and the others are 100 it is HSB/HSV,

Typically you could publish RGB Value to zigbee2mqtt. Some where in the forum in the zgbee2mqtt threads is a javascript that converts hsb to rgb. I am at the moment more interested to read the color value