-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostTemp.vfib
1 lines (1 loc) · 4.89 KB
/
PostTemp.vfib
1
{"name":"PostTemp","type":"virtual_device","properties":{"deviceIcon":0,"currentIcon":"0","mainLoop":"","saveLogs":"1","rows":[{"type":"button","elements":[{"id":1,"lua":true,"waitForResponse":false,"caption":"Post Temp Srv 1","name":"Button11","empty":false,"msg":"local debug = 0;\nlocal srv = \"192.168.0.238\"\nlocal btnNumber = 1;\nlocal idToDo = fibaro:getGlobalValue(\"currTempID\")\n\nif (idToDo == \"-1\") then\n if (debug == 1) then\n\tfibaro:debug(\"Rien A faire\"); \n end\nelse \n local id = tonumber(idToDo);\n \n if (fibaro:getType(id) == \"temperature_sensor\" \n or fibaro:getType(id) == \"weather\") then\n \n local temp;\n \n \tif (fibaro:getType(id) == \"temperature_sensor\") then\n temp = fibaro:getValue(id, \"value\");\n elseif (fibaro:getType(id) == \"weather\") then\n temp = fibaro:getValue(id, \"Temperature\");\n end\n \n local room = fibaro:getRoomID(id);\n local name = fibaro:getName(id);\n local date = os.date(\"%Y-%m-%d %H:%M:%S\");\n \n if (debug == 1) then\n fibaro:debug(id);\n fibaro:debug(temp);\n fibaro:debug(room);\n fibaro:debug(name);\n end\n \n local jsonTable = {room= room,id = id, name= name, temp = temp, date = date};\n \n local jsonString = json.encode (jsonTable);\n \n local http = Net.FHttp(srv, \"80\");\n \n local nberreur = 0;\n \n while (nberreur>=0 and nberreur<5) do\n \n if (debug == 1) then\n \tfibaro:debug(\"Essai: \"..nberreur);\n end\n \n response, status, errorCode = http:PUT(\"/temperatures/datas.php\", jsonString);\n \n if (debug == 1) then \n fibaro:debug(status); \n end\n \n if (status == \"200\") then\n \n if (debug == 1) then\n fibaro:debug(\"UPDATED\");\n end\n \n nberreur = -1;\n else \n nberreur = nberreur+1;\n end \n \n end\n \n if (nberreur > -1 and btnNumber == 1) then\n \t-- on appui sur le boutton 2 (2eme serveur au cas ou)\n \tfibaro:call(59, \"pressButton\", 2); \n else\n \tfibaro:setGlobal(\"currTempID\", \"-1\"); \n \tfibaro:sleep(1000);\n end\n \n else\n if (debug == 1) then\n \tfibaro:debug(\"Pas une sonde de température\"); \n end\n \n fibaro:setGlobal(\"currTempID\", \"-1\"); \n fibaro:sleep(1000);\n\n end \nend\n \nfibaro:debug(\"Traitement Ok\");\nfibaro:log(\"Traitement Ok\");\n ","buttonIcon":0,"favourite":false,"main":true}]},{"type":"button","elements":[{"id":2,"lua":true,"waitForResponse":false,"caption":"Post Temp Srv 2","name":"Button21","empty":false,"msg":"local debug = 0;\nlocal srv = \"192.168.0.237\"\nlocal btnNumber = 2;\nlocal idToDo = fibaro:getGlobalValue(\"currTempID\")\n\nif (idToDo == \"-1\") then\n if (debug == 1) then\n\tfibaro:debug(\"Rien A faire\"); \n end\nelse \n local id = tonumber(idToDo);\n \n if (fibaro:getType(id) == \"temperature_sensor\" \n or fibaro:getType(id) == \"weather\") then\n \n local temp;\n \n \tif (fibaro:getType(id) == \"temperature_sensor\") then\n temp = fibaro:getValue(id, \"value\");\n elseif (fibaro:getType(id) == \"weather\") then\n temp = fibaro:getValue(id, \"Temperature\");\n end\n \n local room = fibaro:getRoomID(id);\n local name = fibaro:getName(id);\n local date = os.date(\"%Y-%m-%d %H:%M:%S\");\n \n if (debug == 1) then\n fibaro:debug(id);\n fibaro:debug(temp);\n fibaro:debug(room);\n fibaro:debug(name);\n end\n \n local jsonTable = {room= room,id = id, name= name, temp = temp, date = date};\n \n local jsonString = json.encode (jsonTable);\n \n local http = Net.FHttp(srv, \"80\");\n \n local nberreur = 0;\n \n while (nberreur>=0 and nberreur<5) do\n \n if (debug == 1) then\n \tfibaro:debug(\"Essai: \"..nberreur);\n end\n \n response, status, errorCode = http:PUT(\"/temperatures/datas.php\", jsonString);\n \n if (debug == 1) then \n fibaro:debug(status); \n end\n \n if (status == \"200\") then\n \n if (debug == 1) then\n fibaro:debug(\"UPDATED\");\n end\n \n nberreur = -1;\n else \n nberreur = nberreur+1;\n end \n \n end\n \n if (nberreur > -1 and btnNumber == 1) then\n \t-- on appui sur le boutton 2 (2eme serveur au cas ou)\n \tfibaro:call(59, \"pressButton\", 2); \n else\n \tfibaro:setGlobal(\"currTempID\", \"-1\"); \n \tfibaro:sleep(1000);\n end\n \n else\n if (debug == 1) then\n \tfibaro:debug(\"Pas une sonde de température\"); \n end\n \n fibaro:setGlobal(\"currTempID\", \"-1\"); \n fibaro:sleep(1000);\n\n end \nend\n \nfibaro:debug(\"Traitement Ok\");\nfibaro:log(\"Traitement Ok\");\n ","buttonIcon":0,"favourite":false,"main":false}]}]},"actions":{"pressButton":1,"setSlider":2,"setProperty":2}}