This script will turn on the cube for 5 mins when the tap twice action is performed . The hub speaker will play the knock on wood ring tome to confirm activation. after 5 mins of non use the cube becomes inactive until the tap twice action is performed again .
The script uses a string user variable XiaomiCube to hold the date and time of the last action. This is used to time the activation window.
The script assumes all the device names for Xiaomi hub and Cube are unchanged.
Replace the device names to be triggered between the IF statements for the cube actions except the first IF (tap twice) which updates the the user variable . You must add
Code: Select all
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
I toggle the actions so if the TV is On the Flip 180 action will turn the TV Off. If its Off the Flip 180 action will turn the TV on.
I use the clock wise and anti clockwise to change volume and the shake air to turn on netflix
Code: Select all
return {
active = true,
on = {
devices = {
'Xiaomi Cube'
},
},
execute = function(domoticz, cube)
local Time = require('Time')
local currentTime = Time()
local cubeset = Time(domoticz.variables("XiaomiCube").value)
if (cube.levelName == "tap_twice") then
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
cubeset = Time(currentTime.rawDate .. " " .. currentTime.rawTime)
domoticz.devices("Xiaomi Gateway Doorbell").switchSelector(20)
domoticz.log("Cube is active for 5 Mins time now is " .. cubeset.rawTime)
end
if (cube.levelName == 'shake_air') and cubeset.minutesAgo < 5 then
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
if domoticz.devices("Movies").state == "On" then
domoticz.devices("Movies").switchOff()
domoticz.log('Movies Off')
elseif domoticz.devices("Movies").state == "Off" then
domoticz.devices("Movies").switchOn()
domoticz.log('Movies On')
end
end
if (cube.levelName == 'flip180') and cubeset.minutesAgo < 5 then
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
if domoticz.devices("TV").state == "On" then
domoticz.devices("TV").switchOff()
domoticz.log('TV Off')
elseif domoticz.devices("TV").state == "Off" then
domoticz.devices("TV").switchOn()
domoticz.log('TV on')
end
end
if (cube.levelName == 'clock_wise') and cubeset.minutesAgo < 5 then
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
domoticz.devices("Sound").switchOn()
end
if (cube.levelName == 'anti_clock_wise') and cubeset.minutesAgo < 5 then
domoticz.variables("XiaomiCube").set(currentTime.rawDate .. " " .. currentTime.rawTime)
domoticz.devices("Sound").switchOff()
end
end
}
}