voici un petit script pour prendre en compte le double clic sur un interrupteur mural ou une télécommande,
pour par exemple pouvoir allumer ou éteindre occasionnellement plus d'une lampe..
voici le script lua
Code : Tout sélectionner
-- script_device_doubleTapeSalonOff.lua
--
-- script de gestion du double clic
--------------------------------
------ Variables à éditer ------
--------------------------------
local switch = 'inter de droite' -- nom de l'interrupteur à détecter
local state = 'Off' -- état à détecter (ex: double clic sur Off)
local delai = 5 -- temps en seconde durant lequel les 2 appuis doivent être effectués
-- actions à réaliser
-- attention, ne pas mettre dans action le switch d'activation,
-- sous peine de générer une boucle infinie.
local action = [[
commandArray['la chambre'] = 'Off'
commandArray['le salon'] = 'Off'
commandArray['les pierres'] = 'Off'
]]
local ip = '192.168.22.100:8080' -- user:pass@ip:port de domoticz pour création variable
--------------------------------
-- Fin des variables à éditer --
--------------------------------
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
commandArray = {}
if(uservariables['doubleTape_'..switch..'_'..state] == nil) then
commandArray['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname=doubleTape_'..url_encode(switch)..'_'..state..'&vtype=2&vvalue='..url_encode(otherdevices_lastupdate[switch])
print('DoubleTape : création variable manquante doubleTape_'..switch..'_'..state)
return commandArray
end
s1 = otherdevices_lastupdate[switch]
year1 = string.sub(s1, 1, 4)
month1 = string.sub(s1, 6, 7)
day1 = string.sub(s1, 9, 10)
hour1 = string.sub(s1, 12, 13)
minutes1 = string.sub(s1, 15, 16)
seconds1 = string.sub(s1, 18, 19)
s2 = uservariables['doubleTape_'..switch..'_'..state]
year2 = string.sub(s2, 1, 4)
month2 = string.sub(s2, 6, 7)
day2 = string.sub(s2, 9, 10)
hour2 = string.sub(s2, 12, 13)
minutes2 = string.sub(s2, 15, 16)
seconds2 = string.sub(s2, 18, 19)
t1 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
t2 = os.time{year=year2, month=month2, day=day2, hour=hour2, min=minutes2, sec=seconds2}
difference = os.difftime (t1, t2)
if (devicechanged[switch] == state) then
if (difference < delai) then
-- liste des actions en cas de double clic
load(action)()
print('doubleTape_'..switch..'_'..state..': '..difference..'s')
-- fin des actions
end
commandArray['Variable:doubleTape_'..switch..'_'..state] = s1
end
return commandArray