I’ve been using Openhab for years now, and I’ve always managed to find solutions through this amazing community. This is my first time sharing my experience, so I hope it can help others facing similar challenges!
Recently, I decided to add a Tuya 4-Gang Switch to my home automation setup. The switch has 4 buttons, and after pairing it with my Sonoff ZBBridge (running Tasmota 12.2.0), I noticed some interesting MQTT entities being published. Here’s what I saw:
{
“ZbReceived”: {
“Tuya_4G_Switch_KG”: {
“Device”: “0x02CC”,
“Name”: “Tuya_4G_Switch_KG”,
“0006!FD”: “00”,
“LidlPower1”: 0,
“Endpoint”: 1,
“LinkQuality”: 105
}
}
}
Initially, I tried using SetOption101 1 to modify the entity structure, but it didn’t work as expected. However, I wasn’t discouraged! I decided to create a custom thing for the switch using MQTT bindings. Here’s the configuration I came up with:
java
UID: mqtt:topic:9702de0240:b48a64a778
label: Tuya_4G_Switch
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:9702de0240
channels:
- id: Test_tuya_4g_switch_2
channelTypeUID: mqtt:switch
label: Test_tuya_4g_switch
description: null
configuration:
stateTopic: tele/tasmota_9D3F08/02CC/SENSOR
transformationPattern: JSONPATH:$.ZbReceived.Tuya_4G_Switch_KG.LidlPower22
off: “1”
on: “0” - id: Test_tuya_4g_switch_3
channelTypeUID: mqtt:switch
label: Test_tuya_4g_switch
description: null
configuration:
stateTopic: tele/tasmota_9D3F08/02CC/SENSOR
transformationPattern: JSONPATH:$.ZbReceived.Tuya_4G_Switch_KG.LidlPower33
off: “1”
on: “0” - id: Test_tuya_4g_switch_4
channelTypeUID: mqtt:switch
label: Test_tuya_4g_switch
description: null
configuration:
stateTopic: tele/tasmota_9D3F08/02CC/SENSOR
transformationPattern: JSONPATH:$.ZbReceived.Tuya_4G_Switch_KG.LidlPower44
off: “1”
on: “0” - id: Test_tuya_4g_switch
channelTypeUID: mqtt:switch
label: Test_tuya_4g_switch
description: null
configuration:
stateTopic: tele/tasmota_9D3F08/02CC/SENSOR
transformationPattern: JSONPATH:$.ZbReceived.Tuya_4G_Switch_KG.LidlPower1
off: “1”
on: “0”
}
After setting this up, I was able to control each button individually. However, there was a slight issue: pressing a button once turned it on, but pressing it again didn’t turn it off. After some research and tweaking, I realized the problem was with the state transformation. I adjusted the transformationPattern to correctly interpret the button states, and now everything works smoothly!
This experience taught me the importance of carefully configuring MQTT bindings and understanding the structure of the data being published. I’m thrilled to have successfully integrated this switch into my Openhab setup, and I hope this post can guide others who are looking to do something similar!
If anyone has questions or suggestions, feel free to reach out. Happy automating! ![]()