{"name":"Sonnenstand","type":"virtual_device","properties":{"deviceIcon":210,"currentIcon":"210","log":"","logTemp":"","mainLoop":"","ui.Label1.value":"05:05","ui.Label2.value":"21:29","ui.Label3.value":"270 °","ui.Label4.value":"26 °","ui.Label5.value":"22:17","ui.Label6.value":"24.05.2016 18:13:13","visible":"true","rows":[{"type":"label","elements":[{"id":1,"lua":false,"waitForResponse":false,"caption":"Sonnenaufgang","name":"Label1","favourite":false,"main":false}]},{"type":"label","elements":[{"id":2,"lua":false,"waitForResponse":false,"caption":"Sonnenuntergang","name":"Label2","favourite":false,"main":false}]},{"type":"label","elements":[{"id":3,"lua":false,"waitForResponse":false,"caption":"Sonnenstand","name":"Label3","favourite":false,"main":true}]},{"type":"label","elements":[{"id":4,"lua":false,"waitForResponse":false,"caption":"Höhenwinkel","name":"Label4","favourite":false,"main":false}]},{"type":"label","elements":[{"id":5,"lua":false,"waitForResponse":false,"caption":"Abenddämmerung","name":"Label5","favourite":false,"main":false}]},{"type":"label","elements":[{"id":6,"lua":false,"waitForResponse":false,"caption":"Update","name":"Label6","favourite":false,"main":false}]},{"type":"button","elements":[{"id":7,"lua":true,"waitForResponse":false,"caption":"Update","name":"Button11","empty":false,"msg":"-------------------------------------------------------------------------------------------\n-- HOWTO --\n--http://www.mondverlauf.de oder \n--http://www.sonnenverlauf.de\n--API-Key von http://www.torsten-hoffmann.de/apis/suncalcmooncalc/api_en.html\n--Die Globale Variable (GV) \"Abendaemmerung\" wird benötigt; steuert anderes Script\n--Die Globale Variable (GV) \"Sonnenstand\" wird benötigt; steuert anderes Script\n\n\nlocal APIkey = \"xxxx\" \t-- Put your Api key here\nlocal lat = 50.000000 \t\t--Latitude des Standorttes eingeben\nlocal lon = 12.000000 \t\t--Longitude des Standorttes eingeben\n\nlocal VDid = fibaro:getSelfId()\n\nfunction setDevicePropertyValue(id, label, value)\n fibaro:call(id, \"setProperty\", \"ui.\"..label..\".value\", value)\nend\n\n-------------------------------------------\nlocal FHTE = Net.FHttp(\"www.torsten-hoffmann.de\"); \nlocal response, status, errorCode = FHTE:GET(\"/apis/suncalcmooncalc/xml/?key=\"..APIkey..\"&lat=\"..lat..\"&lon=\"..lon); \nif (tonumber(status) == 200 and tonumber(errorCode)==0) then \nlocal status_resp = response:match('(.+)')\nfibaro:debug(status)\nfibaro:debug(status_resp) \n \nlocal Sonnenaufgang_resp = response:match('(.+)') \nlocal Sonnenaufgang = string.sub(Sonnenaufgang_resp, 1, 5); \n\nlocal Sonnenuntergang_resp = response:match('(.+)') \nlocal Sonnenuntergang = string.sub(Sonnenuntergang_resp, 1, 5); \n \n--local time = string.gsub(\"15:26 = 15.441\", \"%S+\")\n--local time = string.sub(\"15:26 = 15.441\", 1 , 5)\n \nlocal Sonnenstand_resp = response:match('(.+)') \nSonnenstand = tonumber(string.format(\"%.0f\", Sonnenstand_resp)) --Runded den Wert \n---Auskommentierung hier entfernen, damit eine zuvor angeelgt GV \"Sonnenstand\" befüllt wird\n--fibaro:setGlobal(\"Sonnenstand\", Sonnenstand) \n \nlocal SonnenAlt_resp = response:match('(.+)') \nSonnenAlt = tonumber(string.format(\"%.0f\", SonnenAlt_resp)) --Runded den Wert \n\n\n-----------------------------------------------------\n--Setzt Globale Variable für andere Zwecke als dieses VD \nlocal Abendaemmerung_resp = response:match('(.+)') \nlocal Abendaemmerung = string.sub(Abendaemmerung_resp, 1, 5)\n--fibaro:setGlobal(\"Abenddaemmerung\", Abendaemmerung) \n \nsetDevicePropertyValue(VDid, \"Label1\", Sonnenaufgang)\nsetDevicePropertyValue(VDid, \"Label2\", Sonnenuntergang)\nsetDevicePropertyValue(VDid, \"Label3\", Sonnenstand..\" °\") \nsetDevicePropertyValue(VDid, \"Label4\", SonnenAlt..\" °\")\nsetDevicePropertyValue(VDid, \"Label5\", Abendaemmerung)\n \nend\n\nDate = os.date(\"%d.%m.%Y %H:%M:%S\", os.time())\nsetDevicePropertyValue(VDid, \"Label6\", Date)","buttonIcon":210,"favourite":false,"main":true}]}]},"actions":{"pressButton":1,"setSlider":2,"setProperty":2}}