transformationPatternOut Things for zigbee2mqtt

  • Platform information:
    • Hardware: RP4
    • OS: Buster
    • openHAB version: 2.5.3
  • Issue of the topic:
    I’m trying to configure a zigbee2mqtt Thing for ZM-L03E-Z (https://www.zigbee2mqtt.io/devices/ZM-L03E-Z.html)
    From zigbee2mqtt Side it seems to be recognized successfully. Checked using a mqtt Client and Send commands to the device like this:

{“state_left”:“ON/OFF”}
{“state_center”:“ON/OFF”}

works fine!

My Things configuration is this:

Thing topic 2WAYSWITCHGARAGE "2WAYSWITCHGARAGE"  {
	Channels:
		Type switch : 2WAYSWITCHGARAGELEFT "Garage Schalter Links On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0", transformationPatternOut="JSONPATH:$.state_left", transformationPattern="JSONPATH:$.state_left", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set",on="ON", off="OFF"]
		Type switch : 2WAYSWITCHGARAGERIGHT "Garage Schalter Rechts On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0", transformationPatternOut="JSONPATH:$.state_center", transformationPattern="JSONPATH:$.state_center", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set",on="ON", off="OFF"]
	}

And my Item-File is like this:

Switch 2WAYSWITCHGARAGELEFT "Garage aussen Links" { ga="Switch", channel="mqtt:topic:mosquitto:2WAYSWITCHGARAGE:2WAYSWITCHGARAGELEFT"}
Switch 2WAYSWITCHGARAGERIGHT "Garage aussen Rechts" { ga="Switch", channel="mqtt:topic:mosquitto:2WAYSWITCHGARAGE:2WAYSWITCHGARAGERIGHT"}

Now if I try to set 2WAYSWITCHGARAGELEFT to on and off, everything works fine. But if i try to switch 2WAYSWITCHGARAGERIGHT it switches ALSO state_left to on or off. It seems that the command to the device is allways the same and also the answer (and its state) is processed not according to the tranfsformationPattern and tranformationPatternOut.

Based on my unterstanding of tranformationPatternOut (transformationPatternOut=“JSONPATH:$.state_center”) openhab should send {“state_center”:“ON/OFF”}

What Im doing wrong?

I also tried to use formatBeforePublish="{ “state_center” : %s }" withing the Things configuration, but this also changed nothing.

The zigbee2mqtt log says following:

,zigbee2mqtt:info 2020-12-16 12:46:47: MQTT publish: topic ‘zigbee2mqtt/0x60a423fffea3acd0’, payload ‘{“state_left”:“ON”,“linkquality”:26,“state_center”:“OFF”,“state”:“ON”}’

I tried to debug the device on zigbee2mqtt side, and it seems that if i want to set state_center, it must be only {“state_center”:“ON”}. That works.

If i send {“state_left”:“ON”, “state_center”:“ON”} only the state_left statement is processed never the state_center. state_center is never changed, only state_left

I’m confused. How to debug the JSON Message send to zigbee2mqtt?

Thank you so much

Your state and command topics are the same for both is this correct?

Thing topic 2WAYSWITCHGARAGE "2WAYSWITCHGARAGE" {
Channels:
  Type switch : 2WAYSWITCHGARAGELEFT "Garage Schalter Links On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0", transformationPatternOut="JSONPATH:$.state_left", transformationPattern="JSONPATH:$.state_left", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set",on="ON", off="OFF"]
  Type switch : 2WAYSWITCHGARAGERIGHT "Garage Schalter Rechts On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0", transformationPatternOut="JSONPATH:$.state_center", transformationPattern="JSONPATH:$.state_center", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set",on="ON", off="OFF"]
}

Looking at the z2mqtt doc zigbee2mqtt/[FRIENDLY_NAME]/set/state should be your commandTopic

thanks for your reply. Yes you are right!

The commantTopic could also be “zigbee2mqtt/0x60a423fffea3acd0/set/state_left” and “zigbee2mqtt/0x60a423fffea3acd0/set/state_center” --> This works if i try it out with the mqtt client.

Within PaperUI the State of state_center is correctly displayed, but it does not toggle the state_center value.

  1. If it is ON (set state_center to on with the mqtt client) and I try to toggle it off within PaperUI it jumps back to ON.
  2. It it is OFF (set state_center to off with the mqtt client) and I try to toggle it ON within PaperUI state_left jumps to ON, not state_center.

My configuration now looks like this:

Thing topic 2WAYSWITCHGARAGE "2WAYSWITCHGARAGE" @ "Casa" {
	Channels:
		Type switch : 2WAYSWITCHGARAGELEFT "Garage Schalter Links On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0/get/state_left", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set/state_left",on="ON", off="OFF"]
		Type switch : 2WAYSWITCHGARAGERIGHT "Garage Schalter Rechts On/Off" [stateTopic="zigbee2mqtt/0x60a423fffea3acd0/get/state_center", commandTopic="zigbee2mqtt/0x60a423fffea3acd0/set/state_center",on="ON", off="OFF"]
	}

Unfortunately this isn’t a solution to your specific problem, but I would recommend setting up zigbee2mqtt so that it publishes is attributes separately, rather than in a single JSON string. Here’s a primer:

This usually simplifies your Thing configuration, as you don’t have to transform anything on the way out of openHAB.

I mark your answer as Solution because the hint with the specific commandTopic was right.

The “Solution” was just to restart the Raspberry. Did not know that Linux and or Openhab is windows like. Restart and everything works fine…

more serious question: is it common that openhab needs to be restarted from time to time to avoid such strange behaviour? The System was running for months until now.

I restarted the system because of the aquara motion sensor which also does not update anymore within openhab. After that I changed the Log-Level from zigbee2mqtt to investigate the messages received and send. Found out that the message is corretly send to zigbee2mqtt. After that plugged in the 2 way tuya switch and state_left and state_center are working correctly.

I suspect you’re running in to the annoying bug where Things files aren’t properly loaded by openHAB after they have been saved. One solution is to restart openHAB, or you can do this.

Thank you! Will try it next time this way - and if it does not work - restart openhab before restarting the raspberry…