Par contre sur mon Pi 2, le pass2php.php bloque au curl.
D'ailleurs, quel est l'intérêt du PHP (à part le langage de programmation)?
Un curl dans un lua lancé par un os.execute() n'aurait-il pas le même résultat ?
Code : Tout sélectionner
curl = '/usr/bin/curl ' -- ne pas oublier l'espace à la fin
json = assert(loadfile '/home/pi/domoticz/scripts/lua/JSON.lua')() -- for linux http://regex.info/blog/lua/json
domoticzIP = '127.0.0.1'
domoticzPORT = '8080'
domoticzURL = 'http://'..domoticzIP..':'..domoticzPORT
-- get group/scene idx
function groupIdx(device)
local getallgroups = assert(io.popen(curl..'"'..domoticzURL..'/json.htm?type=scenes"'))
local readallgroups = getallgroups:read('*all')
getallgroups:close()
alldecoded = json:decode(readallgroups)
allgroups = alldecoded.result
for n, group in pairs(allgroups) do
if (group.Name == device) then
return group.idx
end
end
end
-- 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 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='..groupIdx(device)..'&switchcmd=On" &')
end
-- switch Off a group
function groupOff(device)
os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchscene&idx='..groupIdx(device)..'&switchcmd=Off" &')
end
Code : Tout sélectionner
-- chargement des modules
package.path = package.path..";/home/pi/domoticz/scripts/lua/?.lua"
require "modules"
Code : Tout sélectionner
commandArray['ma lampe']='On' devient switchOn('ma lampe')
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')
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
-- chargement des modules
package.path = package.path..";/home/pi/domoticz/scripts/lua/?.lua"
require "modules"
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-09 18:44:24.703 User: Admin initiated a switch command (13/Plafonnier Loisir/Toggle)
2016-10-09 18:44:24.703 RFLink Sending: 10;TriState;080002;2;OFF
2016-10-09 18:44:24.548 (RFLink Ser2net) Light/Switch (Inter loisir)
2016-10-09 18:44:25.587 Hardware Monitor: Fetching data (System sensors)
2016-10-09 18:44:25.731 LUA: TWICE : Plafonnier Loisir -> Off
2016-10-09 18:44:25.732 EventSystem: Script event triggered: Device Twice
2016-10-09 18:44:25.548 (RFLink Ser2net) Light/Switch (Plafonnier Loisir)
2016-10-09 18:44:26.305 (RFXTRXE) Lighting 2 (Inter Loisir 2)
2016-10-09 18:44:26.926 RFLink Sending: 10;TriState;080002;2;OFF
Merci pour le script, Pour le toggle, ok fastochevil1driver a écrit ::Code : Tout sélectionner
-- switch On a device function switchOn(device) os.execute(curl..'"'..domoticzURL..'/json.htm?type=command¶m=switchlight&idx='..otherdevices_idx[device]..'&switchcmd=On" &') end
Code : Tout sélectionner
'..otherdevices_idx[device]..'Code : Tout sélectionner
'..otherscenes_idx[device]..'