Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
36 stars 27 forks source link

Added support for Xiaomi Aqara singel gang button #58

Closed markiboy2all closed 4 years ago

markiboy2all commented 4 years ago

Added support for Xiaomi Aqara singel gang button including a modification in order to select heartbeat. the standard heartbeat of 10s is sufficient to provide the actual current state of the switch

Smanar commented 4 years ago

No problem ^^, it s perfect now.

But I still have question about heartbeat, script doesn't use the displayed state, but the device change. So I still don't see the problem.

On my side I m using this code in LUA

--Ikea remote
if (devicechanged['deCONZ - remote control'] == 'L +')  then
    a = otherdevices_svalues['deCONZ - Room']
    a = tonumber(a) + 5
    commandArray['deCONZ - Room'] = 'Set Level: '..a
end
-- bulb
if (devicechanged['deCONZ - Room'])  then
    if (otherdevices['deCONZ - remote control'] == 'L +') then
        a = otherdevices_svalues['deCONZ - Room']
        a = tonumber(a) + 5
        commandArray['deCONZ - Room'] = 'Set Level: '..a
    end
end

With this code I m using a long press to dim a light, and I haven't problem

The return to "off" is just cometic and not used in all plugin, for example this issue https://github.com/domoticz/domoticz/issues/4143

Device with "hold" feature have a "release" just after nope ?

markiboy2all commented 4 years ago

the Aqara switch does not support a rease state. i asumed that the plugin checks the state, therefore changing the heartbeat makes the plugin check more often if the button is still being pressed, and if thats not the case, the plugin switches the button off.

the behavior I got with the default heartbeat is that the lamp kept dimming after I released the button, and with a higher frequency heartbeat this did not happen, although the button went into the Off state after 3 seconds (and i asume that this is the button's hardware doing that)

Smanar commented 4 years ago

Ha ok, but I m not realy happy with the hearbeat (for the reason from the previous link, and if you use a device with release state). But if you want to make some test I have another idea.

In reality the plugin don't check the state, it's just a timed fonction. I m not sure I can use the python to do a delayed command (need to check) but I can set the 2 state immediately. Set the state "long press" and in same time "off" so your script will be trigger 2 time in just some ms.

And we can do that only for this device, to prevent bug for other one.

I will make some test in future days, I will be back in this PR

BTW thx for Pull, and typo correction, I m not rely good in english ^^.

Smanar commented 4 years ago

@markiboy2all Can you share your script to make tries on my side. I have 2 aquara switch from different generation.

markiboy2all commented 4 years ago
return {
    on = {
        devices = {
            'Conbee dongle - Livingroom Switch'
        }
    },
    execute = function(domoticz, device)
        local dimDevice = domoticz.devices('Bedroom Ceiling Light');
        local dimLevel = dimDevice.level;
        local delay = 0

        if device.state == "hold"  then
            repeat
                delay = delay + 0.15
                dimLevel = dimLevel - 10
                domoticz.log('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds', domoticz.LOG_INFO)
                dimDevice.dimTo(dimLevel).afterSec(delay)
            until dimLevel <= 0
        elseif device.state == "Off" then
            domoticz.log('Stop dimming of ' .. dimDevice.name, domoticz.LOG_INFO)
            dimDevice.cancelQueuedCommands()
            if dimDevice.level == 0 then
                dimDevice.switchOff()
            end
        end  
        domoticz.log('dimLevel ' .. dimLevel, domoticz.LOG_INFO)
        domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
    end
}
Smanar commented 4 years ago

Ok so now I understand the problem. This device is not made for that, just by curiosity, waht happen if you use long press during 15s ? It will reset the device ? I can't trigger the "hold"on my devices (IDK why, however I have the 2 versions), you need to press for more than 3s ? and you will have only 1 websocket return ?

Because I m trying to understand how work your script. If the heartbeat is set a 1s.

Deconz will not send again the "hold" event ? So the device state will be to "off" event you are keeping the pression nope ?

Smanar commented 4 years ago

I have make an issue for that , easier to follow than closed PR > https://github.com/Smanar/Domoticz-deCONZ/issues/61