function myFunction() { // The code below logs the HTML code of the Google home page. // Data from Sunrise-Sunset.org var response = UrlFetchApp.fetch("http://api.sunrise-sunset.org/json?lat=XX.XX2001&lng=XX.XX128998&date=today"); Logger.log(response.getContentText()); var str = response.getContentText(); //var SunriseStr = (str.substring(23, 30)); //var SunsetStr = (str.substring(45, 52)); //Logger.log(SunriseStr); //Logger.log(SunsetStr); var SunriseHrInt = (Number(str.substring(23, 24))-2); // Extract the Sunrise hour, converts it to an integer and roughly convert Zulu to Local time for Sunrise, the factor allows for residule light var SunriseMinInt = (Number(str.substring(25, 27)))/60; // Extract the Sunrise Minutes and converts to decimal minutes //Logger.log(SunriseHrInt); //Logger.log(SunriseMinInt); Sunrise = SunriseHrInt + SunriseMinInt; Sunrise = Math.round(Sunrise*100.0)/100.0; //Sets decimal time to two decimal place Logger.log(Sunrise); var SunsetHrInt = (Number(str.substring(45, 46))+13); // Extract the Sunser hour, converts it to an integer and roughly convert Zulu to Local time for Sunrise, the factor allows for residule light var SunsetMinInt = (Number(str.substring(47, 49)))/60; // Extract the Sunrise Minutes and converts to decimal minutes //Logger.log(SunsetHrInt); //Logger.log(SunsetMinInt); Sunset = SunsetHrInt + SunsetMinInt; Sunset = Math.round(Sunset*100.0)/100.0; //Sets decimal time to two decimal place Logger.log(Sunset); var str = new Date() + ""; //Logger.log(str); //var Day = (str.substring(0, 11)); //Logger.log(Day); var TimeNowHr = (Number(str.substring(16, 18))); //Extrants "Now" hour and converts to a number var TimeNowMin = (Number(str.substring(19, 21)))/60; //Extrants "Now" minutes, converts to a number and decimal minutes TimeNow = TimeNowHr + TimeNowMin; TimeNow = Math.round(TimeNow*100.0)/100.0; //Sets decimal time to two decimal place Logger.log(TimeNow); if ((TimeNow >= Sunset) || (TimeNow <= Sunrise)) { var resultZipatoSunrise = UrlFetchApp.fetch("https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xxxxxxxxxxxx&apiKey=xxxxxxxxxxxxxxxx&uuid=xxxxxxxxxxxxxxxxxxxxxxxxxx&value=1"); Logger.log("Set to 1 (ON)"); } else { var resultZipatoSunrise = UrlFetchApp.fetch("https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xxxxxxxxxxxxxxxxxxx&apiKey=xxxxxxxxxxxxxxxxxxxx&uuid=xxxxxxxxxxxxxxxxxxxxxxxxxxx&value=0"); Logger.log("Set to 0 (OFF"); } Logger.log(resultZipatoSunrise); }