Integrate Tuya 4-Gang switch in Openhab 3.3.0 with Sonoff ZBBridge

  • Platform information:
    • Hardware: RPi4/8GB/32GB
    • OS: Openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: openHAB 3.3.0
  • Issue of the topic:

Good morning everyone!

I use Openhab for years now and was always able to find a solution here or by google. This is my first post after few days of research and I’m very lucky to have this possibility, so thank you for your effort in advance!

I would like to add a Tuya 4-Gang Switch to my Openhab Home Automation. The switch has 4 buttons. After pairing with my Sonoff ZBBridge(Tasmota 12.2.0) I See this MQT entity after pushing buttons 1 to 4:

00:56:52.354 MQT: tele/tasmota_9D3F08/02CC/SENSOR = {"ZbReceived":{"Tuya_4G_Switch_KG":{"Device":"0x02CC","Name":"Tuya_4G_Switch_KG","0006!FD":"00","LidlPower1":0,"Endpoint":1,"LinkQuality":105}}}
00:56:54.270 MQT: tele/tasmota_9D3F08/02CC/SENSOR = {"ZbReceived":{"Tuya_4G_Switch_KG":{"Device":"0x02CC","Name":"Tuya_4G_Switch_KG","0006!FD":"00","LidlPower22":0,"Endpoint":2,"LinkQuality":102}}}
00:56:56.255 MQT: tele/tasmota_9D3F08/02CC/SENSOR = {"ZbReceived":{"Tuya_4G_Switch_KG":{"Device":"0x02CC","Name":"Tuya_4G_Switch_KG","0006!FD":"00","LidlPower33":0,"Endpoint":3,"LinkQuality":105}}}
00:56:57.325 MQT: tele/tasmota_9D3F08/02CC/SENSOR = {"ZbReceived":{"Tuya_4G_Switch_KG":{"Device":"0x02CC","Name":"Tuya_4G_Switch_KG","0006!FD":"00","LidlPower44":0,"Endpoint":4,"LinkQuality":97}}}

I tried to use SetOption101 1 to get sth like tele/tasmota_9D3F08/02CC**_1**/SENSOR but this did not work. May be anyone of you has an idea why this did not work?

Anyway, I were able to add this switch as a thing with this code:

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 adding 4 items to the different channels, I’m able to change the state from on to off for each button by pressing the button once or twice. This is for sure a partial success for me after hours, but I would like to find out how to switch it on and off by clicking just once on the button.
So I click one, the state changes to ON, and if I click once again the state should change to OFF. Is it possible?
Hope you can support me with some Ideas!

Thank you in advance!

Cheers!

Olexiy

  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

I created such a rule to control a Sonoff miniR2:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Tuya4GSwitch_Testtuya4gswitch_02
    type: core.ItemStateUpdateTrigger
conditions:
  - inputs: {}
    id: "3"
    configuration:
      itemName: virtuellerSchalterKGBuro_SonoffMiniR2
      state: OFF
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: virtuellerSchalterKGBuro_SonoffMiniR2
      command: ON
    type: core.ItemCommandAction

This solution works, but I’m not sure if this is the best solution. By using this rule I loose the possibility to use the two other modes(double-click, press for 2 sec) of the button. May be you have a better solution.