stas-demydiuk / domoticz-zigbee2mqtt-plugin

zigbee2mqtt plugin for domoticz
MIT License
136 stars 97 forks source link

Xiaomi MiJia wireless switch - Getting on / off #235

Closed tcheronneau closed 4 years ago

tcheronneau commented 4 years ago

Hi,

I'm not sure it's an real issue or me that's doing bad configuration. My setup is : Zigbee2Mqtt -> MQTT -> Domoticz. I've few Xiaomi devices and everything seems to work well. When I click the wireless switch I see event in Zigbee2MQTT : {"battery":100,"voltage":3002,"linkquality":68,"click":"single"}

When I check the log of the device on domoticz I see "Click" But when I do an automation I've only that event value : Status: dzVents: Info: Handling events for: "Interrupteur", value: "On"

So I cannot do any automation based on the number of click only On/off.

Is it something somebody already experienced and can help me with ?

Thanks

stas-demydiuk commented 4 years ago

I guess you should use state property instead, like in example:

return {
    on = {
        devices = {
            'Switch',
        }
    },
    execute = function(domoticz, device)
        if (device.state == 'Click') then
            //Action 1
        end

        if (device.state == 'Double Click') then
            //Action 2
        end
    end
}
tcheronneau commented 4 years ago

I'm using it with a simple example found on internet :

return {
    active = true,
    on = {
        devices = {
            'Interrupteur'
        }
    },
    execute = function(domoticz, switch)
        if (switch.state == 'On' ) then
            domoticz.notify('This rocks!', 'Turns out that it is getting warm here', domoticz.PRIORITY_LOW)
            switch.switchOff()
        end
    end
}

If I put Click on state it's doing nothing.

stas-demydiuk commented 4 years ago

Could you please make a screenshot of your device. Are you sure it is selector switch?

tcheronneau commented 4 years ago

Yes it's a selector switch :

Screenshot_switch
stas-demydiuk commented 4 years ago

Then my script definitely should work as I have the same device with the same script

tcheronneau commented 4 years ago

Yes that's what I thought too from what I've seen on internet but it's really not :) I've tried with Blockly and DZevents and working only when I put state to On or Off. Even when I change the selector from domoticz directly.

stas-demydiuk commented 4 years ago

Do you have all these levels like "Click", "Double Click", etc in device menu?

tcheronneau commented 4 years ago

Yes I have everything.

stas-demydiuk commented 4 years ago

Then have no idea why it doesn't work. Just could recommend to check that you don't have devices with the same name in Domoticz and that when you perform action on physical device it changes state in Domoticz one.