Re: Envoyer 2 fois les commandes On/Off
Publié : 20 déc. 2015, 22:41
Super, ca fonctionne...
Merci bcp.
Merci bcp.
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
if (chaine=='On') then
commandArray[1]={['Radiateur Parents']='Off'} -- on renvoie la commande inverse
commandArray[2]={['Radiateur Parents']='On AFTER 2'} -- on renvoie la commande normale
else
commandArray[1]={['Radiateur Parents']='On'} -- on renvoie la commande inverse
commandArray[2]={['Radiateur Parents']='Off AFTER 2'} -- on renvoie la commande normale
Code : Tout sélectionner
2016-01-12 09:52:15 On
2016-01-12 09:52:11 On
Code : Tout sélectionner
-- script_device_twice.lua
--
-- ce script permet de doubler les commandes envoyées à certain périphériques
-- de sorte à fiabiliser leur fonctionnement
-- domoticz agit alors comme un répeteur
--------------------------------
------ Tableau à éditer ------
--------------------------------
local ip = '192.168.0.17:8080' -- user:pass@ip:port de domoticz
local switchs={}
switchs['0']='Volet cuisine'
switchs['1']='Volet salon'
switchs['2']='Volet Salle à manger'
switchs['3']='Volet ElostF'
switchs['4']='Volet Maxime'
switchs['5']='PHILIPS salle manger'
switchs['6']='PHILIPS salon'
switchs['7']='Luminaire'
switchs['8']='Radiateur Sejour'
switchs['9']='Radiateur Maxime'
switchs['10']='Radiateur EloStF'
switchs['11']='Enceinte Bluetooth'
switchs['12']='Webcam Maxime'
switchs['13']='Camera'
switchs['14']='VMC'
--------------------------------
-- Fin du tableau à éditer --
--------------------------------
time = os.date("*t")
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
function urlencode(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 = {}
for key, valeur in pairs(switchs) do
if(uservariables['TWICE_'..valeur..'_On'] == nil) then
commandArray[tonumber(key)]={['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname=TWICE_'..urlencode(valeur)..'_On&vtype=2&vvalue='..urlencode(otherdevices_lastupdate[valeur])}
print('TWICE : création variable manquante TWICE_'..valeur..'_On')
elseif(uservariables['TWICE_'..valeur..'_Off'] == nil) then
commandArray[tonumber(key)]={['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname=TWICE_'..urlencode(valeur)..'_Off&vtype=2&vvalue='..urlencode(otherdevices_lastupdate[valeur])}
print('TWICE : création variable manquante TWICE_'..valeur..'_Off')
elseif (devicechanged[valeur] and timedifference(uservariables['TWICE_'..valeur..'_'..otherdevices[valeur]]) > 5) then
commandArray[valeur] = otherdevices[valeur]..' AFTER 1'
commandArray['Variable:TWICE_'..valeur..'_'..otherdevices[valeur]]=otherdevices_lastupdate[valeur]
print('TWICE : '..valeur.. ' -> ' ..otherdevices[valeur])
end
end
return commandArray
Code : Tout sélectionner
if(uservariables['TWICE_'.. valeur ..'_'.. otherdevices[valeur]] == nil) then
commandArray[tonumber(key)]={['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname=TWICE_'..urlencode(valeur)..'_'.. otherdevices[valeur] ..'&vtype=2&vvalue='..urlencode(otherdevices_lastupdate[valeur])}
print('TWICE : creation variable manquante TWICE_'..valeur..'_'.. otherdevices[valeur])
elseif(uservariables['TWICE_'.. valeur..'_'.. otherdevices[valeur]] == nil) then
commandArray[tonumber(key)]={['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname=TWICE_'..urlencode(valeur)..'_'..otherdevices[valeur]..'&vtype=2&vvalue='..urlencode(otherdevices_lastupdate[valeur])}
print('TWICE : creation variable manquante TWICE_'..valeur..'_'.. otherdevices[valeur]) 
