Issue with Aqara WXKG03LM switch Topic is solved

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.

Moderator: leecollings

Post Reply
User avatar
jjnh
Posts: 33
Joined: Sunday 09 December 2018 14:06
Target OS: Linux
Domoticz version: 2023.1
Location: Netherlands
Contact:

Issue with Aqara WXKG03LM switch

Post by jjnh »

Hi,

My setup is a RPi with Domoticz 4.10717 a CC2531 USB dongle and a recent version Zigbee2MQTT.
I have several Zigbee components working correctly including a WXKG02LM dual switch module, door window sensors, etc.

Now I want to add a WXKG03LM single switch module. The switch is recognized and the device is created in Domoticz as a On/Off switch.
When I press a button the zigbee state is showing up in the log, however the switch state never changes from "Off".
I wrote a dzvents script to capture and how the item.state in the Domoticz log:

Code: Select all

Debug2 = "YES"   -- Turn debugging on ("YES") or off ("NO")

return {

   on = { devices = { "Single Switch (ZB)" }},        -- Name of your button
               
   execute = function(dz, item )
       
        if Debug2=="YES" then
            print("Slaapkamer Switch1: Start script")
            print("Slaapkamer Switch1: -- Received State: " .. item.state)
            print("Slaapkamer Switch1: -- Received State: " .. item.rawData[1])
        end
                
        if item.state == "Left" then
            
            if Debug2=="YES" then
                print("Slaapkamer Switch1: -- Single" )
            end

        end

        if item.state == "Double" then
            
            if Debug2=="YES" then
                print("Slaapkamer Switch1: -- Double" )
            end

        end
        if item.state == "Hold" then
            
            if Debug2=="YES" then
                print("Slaapkamer Switch1: -- Hold" )
            end

        end
      
   end
}
When I press the button I see the following in the log:

Code: Select all

2019-12-08 16:07:38.621 (Zigbee2MQTT) MQTT message: zigbee2mqtt/0x00158d0002a56036 {'voltage': 3105, 'click': 'left', 'linkquality': 89, 'battery': 100}
2019-12-08 16:07:38.792 Status: dzVents: Info: Handling events for: "Single Switch (ZB)", value: "Off"
I can even see decoding for long-press and double-click actions in the log. However the switch state in Domoticz never changes.
For my double switch (WXKG02LM) this works correctly and I have a Selector Switch configured in Domoticz that works great.

Code: Select all

2019-12-08 16:13:47.962 (Zigbee2MQTT) MQTT message: zigbee2mqtt/0x00158d0002afc0eb {'voltage': 3025, 'click': 'left', 'battery': 100, 'linkquality': 26}
2019-12-08 16:13:48.098 Status: dzVents: Info: Handling events for: "Double Switch (Zigbee)", value: "Left"
So it look like the decoding in Domoticz is not working correctly.

Thanks for any help!
Kr.
John
Odroid N2+ 4GB, with an RfxTrx433E, Zigbee with Slaesh's CC2652RB, Z-Wave, BroadLink IR using RM mini 3 and P1 connected.
m147
Posts: 27
Joined: Saturday 04 August 2018 14:51
Target OS: Linux
Domoticz version:
Contact:

Re: Issue with Aqara WXKG03LM switch

Post by m147 »

Hi,

I have same issue. The switch is recognized by Z2M plugin as push on button instead selector switch.
I have made workaround with dummy selector switch and bash script listening on mosquitto broker.
I can post the script if you are interested.
User avatar
jjnh
Posts: 33
Joined: Sunday 09 December 2018 14:06
Target OS: Linux
Domoticz version: 2023.1
Location: Netherlands
Contact:

Re: Issue with Aqara WXKG03LM switch

Post by jjnh »

Yes, sure. Can you explain what you mean by a "bash scipt listening"
Odroid N2+ 4GB, with an RfxTrx433E, Zigbee with Slaesh's CC2652RB, Z-Wave, BroadLink IR using RM mini 3 and P1 connected.
m147
Posts: 27
Joined: Saturday 04 August 2018 14:51
Target OS: Linux
Domoticz version:
Contact:

Re: Issue with Aqara WXKG03LM switch

Post by m147 »

jjnh wrote: Saturday 14 December 2019 17:10 Yes, sure. Can you explain what you mean by a "bash scipt listening"
hereunder the script:

#!/bin/bash


mosquitto_sub -t 'zigbee2mqtt/obyvak-switch1' | while read RAW_DATA

do
STATE=$( echo $RAW_DATA | cut -f 4 -d","| cut -f 2 -d":"| cut -f 1 -d"}")
echo $STATE

if [ "$STATE" = '"single"' ]
then
mosquitto_pub -t domoticz/in -m '{"command": "switchlight", "idx": 225, "switchcmd": "Set Level", "level": 10 }'
fi
if [ "$STATE" = '"double"' ]
then
mosquitto_pub -t domoticz/in -m '{"command": "switchlight", "idx": 225, "switchcmd": "Set Level", "level": 20 }'
fi
if [ "$STATE" = '"hold"' ]
then
mosquitto_pub -t domoticz/in -m '{"command": "switchlight", "idx": 225, "switchcmd": "Set Level", "level": 30 }'
fi


done


It runs as service and listen on mqtt topic of switch. When state of switch is changed, it updates dummy selector switch accordingly.
User avatar
jjnh
Posts: 33
Joined: Sunday 09 December 2018 14:06
Target OS: Linux
Domoticz version: 2023.1
Location: Netherlands
Contact:

Re: Issue with Aqara WXKG03LM switch

Post by jjnh »

Thanks, I'll give it a shot.
Odroid N2+ 4GB, with an RfxTrx433E, Zigbee with Slaesh's CC2652RB, Z-Wave, BroadLink IR using RM mini 3 and P1 connected.
User avatar
jjnh
Posts: 33
Joined: Sunday 09 December 2018 14:06
Target OS: Linux
Domoticz version: 2023.1
Location: Netherlands
Contact:

Re: Issue with Aqara WXKG03LM switch

Post by jjnh »

Hi m147, sorry I did not get a chance to work on this issue before, but ... I FIGURED IT OUT!!

Now my Domoticz is working correctly with the WXKG03LM without bash script, just Zigbee2MQTT.

The issue was in the end down to and issue in the Domoticz Zigbee2MQTT plugin files. The file is called WXKG03LM.py which does not work with the new version of the Aqara switch. With some experimenting and copying code from the WXKG12LM.py file I was able to decode the messages correctly and create the selector switch automatically the right way in Domoticz.

This is the content of the WXKG03LM.py:

Code: Select all

from adapters.adapter_with_battery import AdapterWithBattery
from devices.switch.selector_switch import SelectorSwitch


class WXKG03LM(AdapterWithBattery):
    def __init__(self, devices):
        super().__init__(devices)

        self.switch = SelectorSwitch(devices, 'switch', 'state')
        self.switch.add_level('Off', None)
        self.switch.add_level('Single', 'single')
        self.switch.add_level('Double', 'double')
        self.switch.add_level('Hold', 'hold')
        self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU)

        self.devices.append(self.switch)

    def convert_message(self, message):
        message = super().convert_message(message)

        if 'click' in message.raw:
            message.raw['state'] = message.raw['click']
        elif 'action' in message.raw:
            message.raw['state'] = message.raw['action']

        return message
				
    def handleCommand(self, alias, device, device_data, command, level, color):
        self.switch.handle_command(device_data, command, level, color)
Also the fromZigbee.js file was changed, but I do not know if that is absolutely required. I changed the WXKG03LM block to this:

Code: Select all

    WXKG03LM_click: {
        cid: 'genOnOff',
        type: ['attReport', 'readRsp'],
        convert: (model, msg, publish, options) => {
            const ep = msg.endpoints[0];
            return {click: getKey(model.ep(ep.device), ep.epId)};
        },
    },
    WXKG03LM_click_multistate: {
        cid: 'genMultistateInput',
        type: ['attReport', 'readRsp'],
        convert: (model, msg, publish, options) => {
            const value = msg.data.data['presentValue'];
            const lookup = {
                1: {click: 'single'}, // single click
                2: {click: 'double'}, // double click
                3: {action: 'hold'}, // hold for more than 400ms
                17: {action: 'release'}, // release after hold for more than 400ms
                18: {action: 'shake'}, // shake
            };

            return lookup[value] ? lookup[value] : null;
        },
    },
After changing the files, do not forget to restart zigbee2mqtt and the Domoticz plugin.

I hope this helps more people out there.

Thanks for the help!!
John
Odroid N2+ 4GB, with an RfxTrx433E, Zigbee with Slaesh's CC2652RB, Z-Wave, BroadLink IR using RM mini 3 and P1 connected.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest