let CONFIG = { wheatherWunderlandAPI: "https://api.weather.com/v2/pws/observations/current?", stationID: , apiKey: , coverControlDevices: { "Zaluzie Dolina": "http://192.168.0.101/", "Zaluzie Ulica": "http://192.168.0.102/", "Zaluzie Predne": "http://192.168.0.103/" }, windGustLimit: 45, windGustLimitRelease: 15, solarRadiationLimits: { "Dark": 0, "Cloudy": 150, "Sunny": 300 }, }; let windGustLimitAchieved = false; function getWeatherURL() { return CONFIG.wheatherWunderlandAPI + "stationId=" + CONFIG.stationID + "&format=json" + "&units=m" + "&apiKey=" + CONFIG.apiKey + "&numericPrecision=decimal"; }; function BlindsManagement() { Shelly.call ( "http.get", { url: getWeatherURL() }, function (response, error_code, error_message) { let currentWheatherData = JSON.parse(response.body); CheckWheatherConditions(currentWheatherData); }, null ); }; function CheckWheatherConditions(wheatherData) { if (!CheckWindGust(wheatherData.observations[0].metric.windGust)) { let solarRadiation = wheatherData.observations[0].solarRadiation; print("SolarRadiation: ", solarRadiation, "W/m2"); if (solarRadiation === CONFIG.solarRadiationLimits["Dark"]) { SetAllBlindsPosition("close"); return; } if (solarRadiation < CONFIG.solarRadiationLimits["Cloudy"]) SetAllBlindsPosition("go_pos&roller_pos=4"); if (solarRadiation > CONFIG.solarRadiationLimits["Sunny"]) SetAllBlindsPosition("close"); }; } function CheckWindGust(windGust) { print("WindGust: ", windGust, "m/s"); if (windGust > CONFIG.windGustLimit) { windGustLimitAchieved = true; SetAllBlindsPosition("open"); return true; }; if (windGust < CONFIG.windGustLimitRelease) { windGustLimitAchieved = false; } return windGustLimitAchieved; } function SetAllBlindsPosition(position) { for (let i in CONFIG.coverControlDevices) { BlindsControl(CONFIG.coverControlDevices[i], position); } } function BlindsControl(device, position) { Shelly.call ( "http.get", { url: device + "roller/0?go=" + position }, function (response, error_code, error_message, ud) { print(JSON.stringify(response)); }, null ); }; Timer.set ( 5 * 60 * 1000, //runs every 5 mins true, BlindsManagement );