pour faire suite à ce sujet viewtopic.php?f=8&t=1898
je vous fais part ici de la solution collégialement trouvée (merci à Deennoo et Neutrino)
alors voila :
créer un fichier dans le dossier lua nommé modules.lua dont voici le contenu :
Code : Tout sélectionner
-- /!\ require Domoticz v3.5776 and after /!\
curl = '/usr/bin/curl ' -- don't forgot the final space
domoticzIP = '127.0.0.1'
domoticzPORT = '8080'
domoticzURL = 'http://'..domoticzIP..':'..domoticzPORT
-- switch On a device and set level if dimmmable
function switchOn(device, level)
if level ~= nil then
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchlight&idx='..otherdevices_idx[device]..'&switchcmd=Set%20Level&level='..level..'" &')
else
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchlight&idx='..otherdevices_idx[device]..'&switchcmd=On" &')
end
end
-- switch On a devive for x seconds
-- non compatible avec le script sendTwice
function switchOnFor(device, secs)
switchOn(device)
commandArray[device] = "Off AFTER "..secs
end
-- switch Off a device
function switchOff(device)
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchlight&idx='..otherdevices_idx[device]..'&switchcmd=Off" &')
end
-- Toggle a device
function switch(device)
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchlight&idx='..otherdevices_idx[device]..'&switchcmd=Toggle" &')
end
-- switch On a group or scene
function groupOn(device)
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchscene&idx='..otherdevices_scenesgroups_idx[device]..'&switchcmd=On" &')
end
-- switch Off a group
function groupOff(device)
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchscene&idx='..otherdevices_scenesgroups_idx[device]..'&switchcmd=Off" &')
end
en suite dans tous vos script_device_blabla.lua dans lesquels vous souhaitez avoir un gain de réactivité,
ajoutez au tout début ces 2 lignes pour charger modules.lua (en adaptant le chemin vers votre dossier lua au besoin)
Code : Tout sélectionner
-- chargement des modules
dofile('/home/pi/domoticz/scripts/lua/modules.lua')
Code : Tout sélectionner
commandArray['ma lampe']='On' devient switchOn('ma lampe')
commandArray['ma lampe']='On FOR 30' devient switchOnFor('ma lampe', '30')
commandArray['ma lampe']='Off' devient switchOff('ma lampe')
commandArray['ma lampe']='Toggle' devient switch('ma lampe')
commandArray['ma lampe']='Set Level 50' devient switchOn('ma lampe',50)
commandArray['Group:mon groupe']='On' devient groupOn('mon groupe')
commandArray['Group:mon groupe']='Off' devient groupOff('mon groupe')
commandArray['Scene:ma scène']='On' devient groupOn('ma scène')
exemple avec un script qui va allumer la lumière dans la pièce dès que j'ouvre la porte ( script_device_porte.lua )
avant :
Code : Tout sélectionner
commandArray = {}
-- si la porte s'ouvre la nuit, on allume la lampe
if ( devicechanged['la porte'] == 'Open' and timeofday['Nighttime'] ) then
commandArray['le salon']='On'
end
return commandArray
Code : Tout sélectionner
2016-10-16 15:40:38.829 (rfx_net) Lighting 2 (la porte)
2016-10-16 15:40:38.846 LUA: > commandArray["le salon"]='On'
2016-10-16 15:40:39.647 (rfx_net) Lighting 1 (le salon)
après :
Code : Tout sélectionner
-- chargement des modules
dofile('/home/pi/domoticz/scripts/lua/modules.lua')
commandArray = {}
-- si la porte s'ouvre la nuit, on allume la lampe
if ( devicechanged['la porte'] == 'Open' and timeofday['Nighttime'] ) then
switchOn('le salon')
end
return commandArray
Code : Tout sélectionner
2016-10-16 15:40:32.159 (rfx_net) Lighting 2 (la porte)
2016-10-16 15:40:32.179 LUA: > switchOn("le salon")
2016-10-16 15:40:32.201 (rfx_net) Lighting 1 (le salon)