Domoticz and Xiaomi button

Domoticz and Xiaomi button

I bought a Xiaomi gateway to be used with my Domoticz. Initially I was not sure it would work but I’m pleased with the result. The main reason for me to want to integrate it is because it has relatively cheap buttons and a multifunctional cube. These buttons support click and double click (the square ones), including long press and long press release (the circle ones).

Xiamoi Round ButtonXiaomi Square ButtonXiamoi Cube

 

The cube has all kinds of motion it recognizes, rotate, fall, spin, flip, double tap, shake etc.

On AliExpress, you should be able to get the buttons for around 8-9 Euro each. The cube for around 12 Euro.

When you use the button, click on it for example, it shows up as such in Domoticz but the status is not reset even though the button is no longer pressed. I wanted the status of those buttons to always be Off unless an event just happened so what I did is create an event per button to execute the needed actions and than reset itself. Again not real rocket science but if you need it, feel free to copy it. Please note that in order for you to reset the button, you need to know it’s index number (the number in the Idx column when you look at devices.

--
-- Button1, device id = 8
--

commandArray = {}

for deviceName,deviceValue in pairs(devicechanged) do
    --
    -- Only respond on Button1 and if the status is not Off
    --
    if (deviceName=="Button1" and deviceValue~="Off") then
        --
        -- This button has 4 possible statusses.
        -- Check for each one and execute.
        --
        if (deviceValue=="Click") then
        elseif (deviceValue=="Double Click") then
        elseif (deviceValue=="Long Click") then
        elseif (deviceValue=="Long Click Release") then
        end
        --
        -- Reset the button to Off
        --
        commandArray[#commandArray + 1] = {["UpdateDevice"] = "8|Off|0"}
    end
end

return commandArray

The code for the cube is similar:

--
-- Cube1, device id = 115
--

commandArray = {}

for deviceName,deviceValue in pairs(devicechanged) do
    --
    -- Only respond on Cube1 and if the status is not Off
    --
    if (deviceName=="Cube1" and deviceValue~="Off") then
        --
        -- This cube has 10 possible statusses.
        -- Check for each one and execute.
        --
        print ("Cube1: "..deviceValue)
        if (deviceValue=="flip90") then
        elseif (deviceValue=="flip180") then
        elseif (deviceValue=="move") then
        elseif (deviceValue=="tap_twice") then
        elseif (deviceValue=="shake_air") then
        elseif (deviceValue=="swing") then
        elseif (deviceValue=="alert") then
        elseif (deviceValue=="free_fall") then
        elseif (deviceValue=="clock_wise") then
        elseif (deviceValue=="anti_clock_wise") then
        end
        --
        -- Reset the cube to Off
        --
        commandArray[#commandArray + 1] = {["UpdateDevice"] = "115|Off|0"}
    end
end

return commandArray
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s