{"name":"Clock Sync","type":"virtual_device","properties":{"deviceIcon":11,"currentIcon":"11","log":"","logTemp":"","mainLoop":"----------------------------------------------------------------------\n-- SYNCHRONIZATION TIME CONFIGURATION --------------------------------\n----------------------------------------------------------------------\nlocal synchroTime = \"02:00\";\n----------------------------------------------------------------------\n-- DO NOT EDIT BELOW THIS LINE ---------------------------------------\n----------------------------------------------------------------------\nlocal currentDate = os.date(\"*t\");\nlocal selfId = fibaro:getSelfId();\n\nif (currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and \n (string.format(\"%02d\", currentDate.hour) .. \":\" .. string.format(\"%02d\", currentDate.min) == tostring(synchroTime)) then\n -- request synchronization with ntp server\n fibaro:call(selfId, \"pressButton\", 3);\nend\n\nfibaro:sleep(60*1000);","ui.lblLastUpdate.value":"Fri Mar 3 02:00:23 2017","ui.lblNtpServer.value":"ntp1.t-online.de","visible":"true","rows":[{"type":"label","elements":[{"id":1,"lua":false,"waitForResponse":false,"caption":"NTP Server","name":"lblNtpServer","favourite":false,"main":false}]},{"type":"label","elements":[{"id":2,"lua":false,"waitForResponse":false,"caption":"Last update","name":"lblLastUpdate","favourite":false,"main":false}]},{"type":"button","elements":[{"id":3,"lua":true,"waitForResponse":false,"caption":"Clock Sync","name":"btnSync","empty":false,"msg":"----------------------------------------------------------------------\n-- SYNCHRONIZATION TIME CONFIGURATION --------------------------------\n----------------------------------------------------------------------\nlocal ntpServer = \"ntp1.t-online.de\";\n----------------------------------------------------------------------\n-- DO NOT EDIT BELOW THIS LINE ---------------------------------------\n----------------------------------------------------------------------\nlocal _selfId = fibaro:getSelfId();\nfibaro:debug(\"Working please wait\")\nfibaro:call(_selfId, \"setProperty\", \"ui.lblNtpServer.value\", ntpServer);\n\nlocal HC2 = Net.FHttp(\"127.0.0.1\", 11111);\n-- get current location settings\n result ,status2, errorCode2 = HC2:GET(\"/api/settings/location\");\n--- checking\n\nif (tonumber(status2)==200)\n then\n response = json.decode(result);\nresponse.ntpServer = ntpServer;\nresponse.ntp = true;\n\nlocal s = \"Try synchronization, please wait...\";\nfibaro:log(s);\nfibaro:debug(s);\n-- set with new settings\nlocal payload = json.encode(response);\nlocal response, status, errorCode = HC2:PUT(\"/api/settings/location\", payload);\n\nif tonumber(status) == 200 then\n fibaro:call(_selfId, \"setProperty\", \"ui.lblLastUpdate.value\", os.date());\n local s = \"Synchronized with \" .. ntpServer .. \" NTP server\";\n fibaro:log(s);\n fibaro:debug(s); \nelse\n fibaro:debug(\"Error \" .. status); \n fibaro:log(\"Error \" .. status);\nend\n--end checking\n else\n fibaro:debug(\"Error \" .. status2); \n fibaro:log(\"Error \" .. status2); \nend","buttonIcon":11,"favourite":false,"main":true}]}]},"actions":{"pressButton":1,"setSlider":2,"setProperty":2}}