From 5b2a60908868ae9c304eb473ffe2bb42d5f15549 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Tue, 8 Jun 2021 23:10:37 +0200 Subject: [PATCH] https://github.com/baerengraben/ioBroker.swiss-weather-api/issues/42 --- main.js | 2742 +++++++++++++++++++++++++++---------------------------- 1 file changed, 1370 insertions(+), 1372 deletions(-) diff --git a/main.js b/main.js index b0ccd9a..7fe36a0 100644 --- a/main.js +++ b/main.js @@ -93,8 +93,7 @@ function getSystemLanguage(self) { self.defaultLanguage = "en-GB"; } else { self.defaultLanguage = state.common.language; - self.log.info("system language: " + state.common.language); - self.log.info("system language: " + self.defaultLanguage); + self.log.debug("system language: " + self.defaultLanguage); } }); } @@ -1029,1613 +1028,1612 @@ function setCurrentHour(self){ }); } -function getForecast(self){ - return new Promise((resolve, reject) => { - self.log.debug("Getting Forecast for geolocation id: " + geolocationId); +async function getForecast(self){ + self.log.debug("Getting Forecast for geolocation id: " + geolocationId); + + today = new Date(); + // @ts-ignore + today1 = new Date().addDays(1); + // @ts-ignore + today2 = new Date().addDays(2); + // @ts-ignore + today3 = new Date().addDays(3); + // @ts-ignore + today4 = new Date().addDays(4); + // @ts-ignore + today5 = new Date().addDays(5); + // @ts-ignore + today6 = new Date().addDays(6); + // @ts-ignore + today7 = new Date().addDays(7); + lastSuccessfulRun = getActualDateFormattet(today); + + //Get forecast + //Options for getting forecast + var options_forecast = { + "method": "GET", + "hostname": "api.srgssr.ch", + "port": null, + "path": "/srf-meteo/forecast/"+geolocationId, + "headers": { + "authorization": "Bearer " + access_token + } + }; - today = new Date(); - // @ts-ignore - today1 = new Date().addDays(1); - // @ts-ignore - today2 = new Date().addDays(2); - // @ts-ignore - today3 = new Date().addDays(3); - // @ts-ignore - today4 = new Date().addDays(4); - // @ts-ignore - today5 = new Date().addDays(5); - // @ts-ignore - today6 = new Date().addDays(6); - // @ts-ignore - today7 = new Date().addDays(7); - lastSuccessfulRun = getActualDateFormattet(today); - - //Get forecast - //Options for getting forecast - var options_forecast = { - "method": "GET", - "hostname": "api.srgssr.ch", - "port": null, - "path": "/srf-meteo/forecast/"+geolocationId, - "headers": { - "authorization": "Bearer " + access_token - } - }; - - self.log.debug("Options to get forecast: " + JSON.stringify(options_forecast)); - self.log.info("Getting forecast for GeolocationId: " + geolocationId); - - //set request - var req = https.request(options_forecast, function (res) { - var chunks = []; - res.on("data", function (chunk) { - chunks.push(chunk); - }); - res.on("end", function () { - self.log.debug("Answer of forecast Request: " + Buffer.concat(chunks).toString()); - var body = JSON.parse(Buffer.concat(chunks).toString()); - - //check if there is a Error-Code - if (body.hasOwnProperty("code")) { - self.log.debug("Return Code: " + body.code.toString()); - if (body.code.toString().startsWith("404")) { - self.setState('info.connection', false, true); - self.log.error("Forecast - Resource not found"); - return; - } else if (body.code.toString().startsWith("400")) { - self.setState('info.connection', false, true); - self.log.error("Forecast - Invalid request"); - self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); - return; - } else if (body.code.toString().startsWith("401")) { - self.setState('info.connection', false, true); - self.log.error("Forecast - Invalid or expired access token "); - self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); - return; - } else if (body.code.toString().startsWith("429")) { - self.setState('info.connection', false, true); - self.log.error("Forecast - Invalid or expired access token "); - self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); - return; - } else { - self.setState('info.connection', false, true); - self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); - return; - } + self.log.debug("Options to get forecast: " + JSON.stringify(options_forecast)); + self.log.info("Getting forecast for GeolocationId: " + geolocationId); + + //set request + var req = await https.request(options_forecast, function (res) { + var chunks = []; + res.on("data", function (chunk) { + chunks.push(chunk); + }); + res.on("end", function () { + self.log.debug("Answer of forecast Request: " + Buffer.concat(chunks).toString()); + var body = JSON.parse(Buffer.concat(chunks).toString()); + + //check if there is a Error-Code + if (body.hasOwnProperty("code")) { + self.log.debug("Return Code: " + body.code.toString()); + if (body.code.toString().startsWith("404")) { + self.setState('info.connection', false, true); + self.log.error("Forecast - Resource not found"); + return; + } else if (body.code.toString().startsWith("400")) { + self.setState('info.connection', false, true); + self.log.error("Forecast - Invalid request"); + self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); + return; + } else if (body.code.toString().startsWith("401")) { + self.setState('info.connection', false, true); + self.log.error("Forecast - Invalid or expired access token "); + self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); + return; + } else if (body.code.toString().startsWith("429")) { + self.setState('info.connection', false, true); + self.log.error("Forecast - Invalid or expired access token "); + self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); + return; + } else { + self.setState('info.connection', false, true); + self.log.error("Forecast - An error has occured. " + JSON.stringify(body)); + return; } + } - //************************************** - //*** Start extract forcast informations - //************************************** + //************************************** + //*** Start extract forcast informations + //************************************** - //*** geolocation informations *** - self.setObjectNotExists("geolocation." + "id", { - type: "state", - common: { - name: "id", - type: "string", - role: "text" - }, - native: {}, - }, function () { - self.setState("geolocation." + "id", { - val: body.geolocation.id.toString(), - ack: true - }); + //*** geolocation informations *** + self.setObjectNotExists("geolocation." + "id", { + type: "state", + common: { + name: "id", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "id", { + val: body.geolocation.id.toString(), + ack: true }); - self.setObjectNotExists("geolocation." + "lat", { - type: "state", - common: { - name: "latitude", - type: "number", - role: "value.gps.latitude", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "lat", { - val: body.geolocation.lat, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "lat", { + type: "state", + common: { + name: "latitude", + type: "number", + role: "value.gps.latitude", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "lat", { + val: body.geolocation.lat, + ack: true }); - self.setObjectNotExists("geolocation." + "lon", { - type: "state", - common: { - name: "longitude", - type: "number", - role: "value.gps.longitude", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "lon", { - val: body.geolocation.lon, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "lon", { + type: "state", + common: { + name: "longitude", + type: "number", + role: "value.gps.longitude", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "lon", { + val: body.geolocation.lon, + ack: true }); - self.setObjectNotExists("geolocation." + "station_id", { - type: "state", - common: { - name: "station id", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "station_id", { - val: body.geolocation.station_id, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "station_id", { + type: "state", + common: { + name: "station id", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "station_id", { + val: body.geolocation.station_id, + ack: true }); - self.setObjectNotExists("geolocation." + "timezone", { - type: "state", - common: { - name: "timezone", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "timezone", { - val: body.geolocation.timezone, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "timezone", { + type: "state", + common: { + name: "timezone", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "timezone", { + val: body.geolocation.timezone, + ack: true }); - self.setObjectNotExists("geolocation." + "default_name", { - type: "state", - common: { - name: "default name", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "default_name", { - val: body.geolocation.default_name, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "default_name", { + type: "state", + common: { + name: "default name", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "default_name", { + val: body.geolocation.default_name, + ack: true }); - self.setObjectNotExists("geolocation." + "alarm_region_id", { - type: "state", - common: { - name: "alarm region id", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "alarm_region_id", { - val: body.geolocation.alarm_region_id, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "alarm_region_id", { + type: "state", + common: { + name: "alarm region id", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "alarm_region_id", { + val: body.geolocation.alarm_region_id, + ack: true }); - self.setObjectNotExists("geolocation." + "alarm_region_name", { - type: "state", - common: { - name: "alarm region name", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "alarm_region_name", { - val: body.geolocation.alarm_region_name, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "alarm_region_name", { + type: "state", + common: { + name: "alarm region name", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "alarm_region_name", { + val: body.geolocation.alarm_region_name, + ack: true }); - self.setObjectNotExists("geolocation." + "district", { - type: "state", - common: { - name: "district", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("geolocation." + "district", { - val: body.geolocation.district, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "district", { + type: "state", + common: { + name: "district", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("geolocation." + "district", { + val: body.geolocation.district, + ack: true }); + }); - //Geolocation_Names - self.setObjectNotExists("geolocation." + "geolocation_names." + "district", { - type: "state", - common: { - name: "district", - type: "string", - role: "location" - }, - native: {}, - }, function () { - self.setState("geolocation." + "geolocation_names." + "district", { - val: body.geolocation.geolocation_names[0].district, - ack: true - }); + //Geolocation_Names + self.setObjectNotExists("geolocation." + "geolocation_names." + "district", { + type: "state", + common: { + name: "district", + type: "string", + role: "location" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "district", { + val: body.geolocation.geolocation_names[0].district, + ack: true }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "id", { - type: "state", - common: { - name: "id", - type: "string", - role: "text" - }, - native: {}, - }, function () { - self.setState("geolocation." + "geolocation_names." + "id", { - val: body.geolocation.geolocation_names[0].id, - ack: true - }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "id", { + type: "state", + common: { + name: "id", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "id", { + val: body.geolocation.geolocation_names[0].id, + ack: true }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "type", { - type: "state", - common: { - name: "City or POI (Point of Interest)", - type: "string", - role: "text" - }, - native: {}, - }, function () { - self.setState("geolocation." + "geolocation_names." + "type", { - val: body.geolocation.geolocation_names[0].type, - ack: true + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "type", { + type: "state", + common: { + name: "City or POI (Point of Interest)", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "type", { + val: body.geolocation.geolocation_names[0].type, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "language", { + type: "state", + common: { + name: "language", + type: "number", + role: "value" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "language", { + val: body.geolocation.geolocation_names[0].language, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "translation_type", { + type: "state", + common: { + name: "translation type", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "translation_type", { + val: body.geolocation.geolocation_names[0].translation_type, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "name", { + type: "state", + common: { + name: "name", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "name", { + val: body.geolocation.geolocation_names[0].name, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "country", { + type: "state", + common: { + name: "country", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "country", { + val: body.geolocation.geolocation_names[0].country, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "province", { + type: "state", + common: { + name: "province", + type: "string", + role: "text" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "province", { + val: body.geolocation.geolocation_names[0].province, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "inhabitants", { + type: "state", + common: { + name: "inhabitants", + type: "number", + role: "value" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "inhabitants", { + val: body.geolocation.geolocation_names[0].inhabitants, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "height", { + type: "state", + common: { + name: "height", + type: "number", + role: "value" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "height", { + val: body.geolocation.geolocation_names[0].height, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "plz", { + type: "state", + common: { + name: "plz", + type: "number", + role: "value" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "plz", { + val: body.geolocation.geolocation_names[0].plz, + ack: true + }); + }); + self.setObjectNotExists("geolocation." + "geolocation_names." + "ch", { + type: "state", + common: { + name: "ch", + type: "number", + role: "value" + }, + native: {}, + }, function () { + self.setState("geolocation." + "geolocation_names." + "ch", { + val: body.geolocation.geolocation_names[0].ch, + ack: true + }); + }); + + //*** Create 60minutes forecast *** + self.setObjectNotExists("forecast." + "60minutes", { + type: "channel", + common: { + name: "Forecast data for time windows of 60 minutes (for 98 hours from today 0:00)", + role: "info" + }, + native: {}, + }); + // Day 0 + self.setObjectNotExists("forecast." + "60minutes.day0", { + type: "channel", + common: { + name: "Forecast data for today", + role: "info" + }, + native: {}, + }); + // Day 1 + self.setObjectNotExists("forecast." + "60minutes.day1", { + type: "channel", + common: { + name: "Forecast data for tomorrow", + role: "info" + }, + native: {}, + }); + // Day 2 + self.setObjectNotExists("forecast." + "60minutes.day2", { + type: "channel", + common: { + name: "Forecast data for today + 2 days", + role: "info" + }, + native: {}, + }); + // Day 3 + self.setObjectNotExists("forecast." + "60minutes.day3", { + type: "channel", + common: { + name: "Forecast data for today + 3 days", + role: "info" + }, + native: {}, + }); + // Day 4 + self.setObjectNotExists("forecast." + "60minutes.day4", { + type: "channel", + common: { + name: "Forecast data for today + 4 days", + role: "info" + }, + native: {}, + }); + + + //iterate over all 60minutes objects + body.forecast["60minutes"].forEach(function (obj, index) { + var startTimeISOString = obj.local_date_time; + var objDate = new Date(startTimeISOString); + var myPath; + var myTime = getTimeFormattet(objDate); + + if (index < 24) { + myPath = "day0"; + } else if (index > 23 && index < 48) { + myPath = "day1"; + } else if (index > 47 && index < 72) { + myPath = "day2"; + } else if (index > 71 && index < 96) { + myPath = "day3"; + } else if (index > 95) { + myPath = "day4"; + } else { + self.setState('info.connection', false, true); + self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); + return; + } + + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "local_date_time", { + type: "state", + common: { + name: "Date for validity of record", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "local_date_time", { + val: obj.local_date_time, + ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "language", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTT_C", { type: "state", common: { - name: "language", + name: "Current temperature in °C", type: "number", - role: "value" + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "language", { - val: body.geolocation.geolocation_names[0].language, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTT_C", { + val: obj.TTT_C, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "translation_type", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTL_C", { type: "state", common: { - name: "translation type", - type: "string", - role: "text" + name: "Error range lower limit", + type: "number", + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "translation_type", { - val: body.geolocation.geolocation_names[0].translation_type, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTL_C", { + val: obj.TTL_C, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "name", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTH_C", { type: "state", common: { - name: "name", - type: "string", - role: "text" + name: "Error range upper limit", + type: "number", + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "name", { - val: body.geolocation.geolocation_names[0].name, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTH_C", { + val: obj.TTH_C, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "country", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { type: "state", common: { - name: "country", - type: "string", - role: "text" + name: "Probability of precipitation in %", + type: "number", + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "country", { - val: body.geolocation.geolocation_names[0].country, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { + val: obj.PROBPCP_PERCENT, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "province", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "RRR_MM", { type: "state", common: { - name: "province", - type: "string", - role: "text" + name: "Precipitation total", + type: "number", + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "province", { - val: body.geolocation.geolocation_names[0].province, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "RRR_MM", { + val: obj.RRR_MM, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "inhabitants", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "FF_KMH", { type: "state", common: { - name: "inhabitants", + name: "Wind speed in km/h", type: "number", - role: "value" + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "inhabitants", { - val: body.geolocation.geolocation_names[0].inhabitants, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "FF_KMH", { + val: obj.FF_KMH, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "height", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "FX_KMH", { type: "state", common: { - name: "height", + name: "Peak wind speed in km/h", type: "number", - role: "value" + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "height", { - val: body.geolocation.geolocation_names[0].height, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "FX_KMH", { + val: obj.FX_KMH, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "plz", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "DD_DEG", { type: "state", common: { - name: "plz", + name: "Wind direction in angular degrees: 0 = North wind", type: "number", - role: "value" + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "plz", { - val: body.geolocation.geolocation_names[0].plz, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "DD_DEG", { + val: obj.DD_DEG, ack: true }); }); - self.setObjectNotExists("geolocation." + "geolocation_names." + "ch", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "SYMBOL_CODE", { type: "state", common: { - name: "ch", + name: "Mapping to weather icon", type: "number", - role: "value" + role: "value", + write: false }, native: {}, }, function () { - self.setState("geolocation." + "geolocation_names." + "ch", { - val: body.geolocation.geolocation_names[0].ch, + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "SYMBOL_CODE", { + val: obj.SYMBOL_CODE, ack: true }); }); - - //*** Create 60minutes forecast *** - self.setObjectNotExists("forecast." + "60minutes", { - type: "channel", + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + type: "state", common: { - name: "Forecast data for time windows of 60 minutes (for 98 hours from today 0:00)", - role: "info" + name: "URL to color Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - // Day 0 - self.setObjectNotExists("forecast." + "60minutes.day0", { - type: "channel", + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + type: "state", common: { - name: "Forecast data for today", - role: "info" + name: "URL to dark Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - // Day 1 - self.setObjectNotExists("forecast." + "60minutes.day1", { - type: "channel", + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + type: "state", common: { - name: "Forecast data for tomorrow", - role: "info" + name: "URL to light Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - // Day 2 - self.setObjectNotExists("forecast." + "60minutes.day2", { - type: "channel", + + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "type", { + type: "state", common: { - name: "Forecast data for today + 2 days", - role: "info" + name: "result set; possible values: 60minutes, hour, day", + type: "string", + role: "text", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "type", { + val: obj.type, + ack: true + }); }); - // Day 3 - self.setObjectNotExists("forecast." + "60minutes.day3", { + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color", { type: "channel", common: { - name: "Forecast data for today + 3 days", + name: "Mapping temperature / color value", role: "info" }, native: {}, }); - // Day 4 - self.setObjectNotExists("forecast." + "60minutes.day4", { - type: "channel", + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "temperature", { + type: "state", common: { - name: "Forecast data for today + 4 days", - role: "info" + name: "Temperature value", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "temperature", { + val: obj.cur_color.temperature, + ack: true + }); + }); + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "background_color", { + type: "state", + common: { + name: "background hex color value", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "background_color", { + val: obj.cur_color.background_color, + ack: true + }); + }); + self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "text_color", { + type: "state", + common: { + name: "text hex color value", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "text_color", { + val: obj.cur_color.text_color, + ack: true + }); }); - - //iterate over all 60minutes objects - body.forecast["60minutes"].forEach(function (obj, index) { - var startTimeISOString = obj.local_date_time; - var objDate = new Date(startTimeISOString); - var myPath; - var myTime = getTimeFormattet(objDate); - - if (index < 24) { - myPath = "day0"; - } else if (index > 23 && index < 48) { - myPath = "day1"; - } else if (index > 47 && index < 72) { - myPath = "day2"; - } else if (index > 71 && index < 96) { - myPath = "day3"; - } else if (index > 95) { - myPath = "day4"; - } else { - self.setState('info.connection', false, true); - self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); - return; - } - - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "local_date_time", { + var jsonCharts = (createJson(body)); + jsonCharts.forEach(function (obj, index) { + self.setObjectNotExists("forecast." + "60minutes.day" + index + "." + "JsonChart", { type: "state", common: { - name: "Date for validity of record", + name: "JSON containing the weather-values of this 60min forecast - Use this with Material Design JSON Chart", type: "string", role: "text", write: false }, native: {}, }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "local_date_time", { - val: obj.local_date_time, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTT_C", { - type: "state", - common: { - name: "Current temperature in °C", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTT_C", { - val: obj.TTT_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTL_C", { - type: "state", - common: { - name: "Error range lower limit", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTL_C", { - val: obj.TTL_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTH_C", { - type: "state", - common: { - name: "Error range upper limit", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "TTH_C", { - val: obj.TTH_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - type: "state", - common: { - name: "Probability of precipitation in %", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - val: obj.PROBPCP_PERCENT, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "RRR_MM", { - type: "state", - common: { - name: "Precipitation total", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "RRR_MM", { - val: obj.RRR_MM, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "FF_KMH", { - type: "state", - common: { - name: "Wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "FF_KMH", { - val: obj.FF_KMH, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "FX_KMH", { - type: "state", - common: { - name: "Peak wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "FX_KMH", { - val: obj.FX_KMH, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "DD_DEG", { - type: "state", - common: { - name: "Wind direction in angular degrees: 0 = North wind", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "DD_DEG", { - val: obj.DD_DEG, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - type: "state", - common: { - name: "Mapping to weather icon", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - val: obj.SYMBOL_CODE, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - type: "state", - common: { - name: "URL to color Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - type: "state", - common: { - name: "URL to dark Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - type: "state", - common: { - name: "URL to light Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", + self.setState("forecast." + "60minutes.day" + index + "." + "JsonChart", { + val: JSON.stringify(obj), ack: true }); }); + }); + }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "type", { - type: "state", - common: { - name: "result set; possible values: 60minutes, hour, day", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "type", { - val: obj.type, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color", { - type: "channel", - common: { - name: "Mapping temperature / color value", - role: "info" - }, - native: {}, - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "temperature", { - type: "state", - common: { - name: "Temperature value", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "temperature", { - val: obj.cur_color.temperature, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "background_color", { - type: "state", - common: { - name: "background hex color value", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "background_color", { - val: obj.cur_color.background_color, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "text_color", { - type: "state", - common: { - name: "text hex color value", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes." + myPath + "." + myTime + "." + "cur_color." + "text_color", { - val: obj.cur_color.text_color, - ack: true - }); - }); + //*** Create day forecast *** + self.setObjectNotExists("forecast." + "day", { + type: "channel", + common: { + name: "Forecast data for a whole day (for 8 days from today 0:00 )", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day0", { + type: "channel", + common: { + name: "Forecast data for today", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day1", { + type: "channel", + common: { + name: "Forecast data for tomorrow", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day2", { + type: "channel", + common: { + name: "Forecast data for today + 2 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day3", { + type: "channel", + common: { + name: "Forecast data for today + 3 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day4", { + type: "channel", + common: { + name: "Forecast data for today + 4 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day5", { + type: "channel", + common: { + name: "Forecast data for today + 5 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day6", { + type: "channel", + common: { + name: "Forecast data for today + 6 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day.day7", { + type: "channel", + common: { + name: "Forecast data for today + 7 days", + role: "info" + }, + native: {}, + }); - var jsonCharts = (createJson(body)); - jsonCharts.forEach(function (obj, index) { - self.setObjectNotExists("forecast." + "60minutes.day" + index + "." + "JsonChart", { - type: "state", - common: { - name: "JSON containing the weather-values of this 60min forecast - Use this with Material Design JSON Chart", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "60minutes.day" + index + "." + "JsonChart", { - val: JSON.stringify(obj), - ack: true - }); - }); - }); - }); + // iterate over all day objects + body.forecast["day"].forEach(function (obj, index) { + var startTimeISOString = obj.local_date_time; + var objDate = new Date(startTimeISOString); + var myPath; + var myTime = getTimeFormattet(objDate); + var day_name = ""; + + if (index === 0) { + myPath = "day0"; + day_name = getDayName(today, self.defaultLanguage); + } else if (index === 1) { + myPath = "day1"; + day_name = getDayName(today1, self.defaultLanguage); + } else if (index === 2) { + myPath = "day2"; + day_name = getDayName(today2, self.defaultLanguage); + } else if (index === 3) { + myPath = "day3"; + day_name = getDayName(today3, self.defaultLanguage); + } else if (index === 4) { + myPath = "day4"; + day_name = getDayName(today4, self.defaultLanguage); + } else if (index === 5) { + myPath = "day5"; + day_name = getDayName(today5, self.defaultLanguage); + } else if (index === 6) { + myPath = "day6"; + day_name = getDayName(today6, self.defaultLanguage); + } else if (index === 7) { + myPath = "day7"; + day_name = getDayName(today7, self.defaultLanguage); + } else { + self.setState('info.connection', false, true); + self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); + return; + } - //*** Create day forecast *** - self.setObjectNotExists("forecast." + "day", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "day_name", { + type: "state", common: { - name: "Forecast data for a whole day (for 8 days from today 0:00 )", - role: "info" + name: "Day Name", + type: "string", + role: "text" }, native: {}, - }); - self.setObjectNotExists("forecast." + "day.day0", { - type: "channel", + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "day_name", { + val: day_name, + ack: true + }); + }.bind({day_name: day_name})); + + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "local_date_time", { + type: "state", common: { - name: "Forecast data for today", - role: "info" + name: "Date for validity of record", + type: "string", + role: "text", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "local_date_time", { + val: obj.local_date_time, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day1", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "TX_C", { + type: "state", common: { - name: "Forecast data for tomorrow", - role: "info" + name: "Maximum temperature in °C", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "TX_C", { + val: obj.TX_C, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day2", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "TN_C", { + type: "state", common: { - name: "Forecast data for today + 2 days", - role: "info" + name: "Lowest temperature in °C", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "TN_C", { + val: obj.TN_C, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day3", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { + type: "state", common: { - name: "Forecast data for today + 3 days", - role: "info" + name: "Probability of precipitation in %", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { + val: obj.PROBPCP_PERCENT, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day4", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "RRR_MM", { + type: "state", common: { - name: "Forecast data for today + 4 days", - role: "info" + name: "Precipitation total", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "RRR_MM", { + val: obj.RRR_MM, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day5", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "FF_KMH", { + type: "state", common: { - name: "Forecast data for today + 5 days", - role: "info" + name: "Wind speed in km/h", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "FF_KMH", { + val: obj.FF_KMH, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day6", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "FX_KMH", { + type: "state", common: { - name: "Forecast data for today + 6 days", - role: "info" + name: "Peak wind speed in km/h", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "FX_KMH", { + val: obj.FX_KMH, + ack: true + }); }); - self.setObjectNotExists("forecast." + "day.day7", { - type: "channel", + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "DD_DEG", { + type: "state", common: { - name: "Forecast data for today + 7 days", - role: "info" + name: "Wind direction in angular degrees: 0 = North wind", + type: "number", + role: "value", + write: false }, native: {}, - }); - - // iterate over all day objects - body.forecast["day"].forEach(function (obj, index) { - var startTimeISOString = obj.local_date_time; - var objDate = new Date(startTimeISOString); - var myPath; - var myTime = getTimeFormattet(objDate); - var day_name = ""; - - if (index === 0) { - myPath = "day0"; - day_name = getDayName(today, self.defaultLanguage); - } else if (index === 1) { - myPath = "day1"; - day_name = getDayName(today1, self.defaultLanguage); - } else if (index === 2) { - myPath = "day2"; - day_name = getDayName(today2, self.defaultLanguage); - } else if (index === 3) { - myPath = "day3"; - day_name = getDayName(today3, self.defaultLanguage); - } else if (index === 4) { - myPath = "day4"; - day_name = getDayName(today4, self.defaultLanguage); - } else if (index === 5) { - myPath = "day5"; - day_name = getDayName(today5, self.defaultLanguage); - } else if (index === 6) { - myPath = "day6"; - day_name = getDayName(today6, self.defaultLanguage); - } else if (index === 7) { - myPath = "day7"; - day_name = getDayName(today7, self.defaultLanguage); - } else { - self.setState('info.connection', false, true); - self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); - return; - } - - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "day_name", { - type: "state", - common: { - name: "Day Name", - type: "string", - role: "text" - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "day_name", { - val: day_name, - ack: true - }); - }.bind({day_name: day_name})); - - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "local_date_time", { - type: "state", - common: { - name: "Date for validity of record", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "local_date_time", { - val: obj.local_date_time, - ack: true - }); + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "DD_DEG", { + val: obj.DD_DEG, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "TX_C", { - type: "state", - common: { - name: "Maximum temperature in °C", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "TX_C", { - val: obj.TX_C, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUNSET", { + type: "state", + common: { + name: "Time sunset", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUNSET", { + val: obj.SUNSET, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "TN_C", { - type: "state", - common: { - name: "Lowest temperature in °C", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "TN_C", { - val: obj.TN_C, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUNRISE", { + type: "state", + common: { + name: "Time sunrise", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUNRISE", { + val: obj.SUNRISE, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - type: "state", - common: { - name: "Probability of precipitation in %", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - val: obj.PROBPCP_PERCENT, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUN_H", { + type: "state", + common: { + name: "Sun hours", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUN_H", { + val: obj.SUN_H, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "RRR_MM", { - type: "state", - common: { - name: "Precipitation total", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "RRR_MM", { - val: obj.RRR_MM, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SYMBOL_CODE", { + type: "state", + common: { + name: "Mapping to weather icon", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SYMBOL_CODE", { + val: obj.SYMBOL_CODE, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "FF_KMH", { - type: "state", - common: { - name: "Wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "FF_KMH", { - val: obj.FF_KMH, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + type: "state", + common: { + name: "URL to color Icon", + type: "string", + role: "weather.icon" + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "FX_KMH", { - type: "state", - common: { - name: "Peak wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "FX_KMH", { - val: obj.FX_KMH, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + type: "state", + common: { + name: "URL to dark Icon", + type: "string", + role: "weather.icon" + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "DD_DEG", { - type: "state", - common: { - name: "Wind direction in angular degrees: 0 = North wind", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "DD_DEG", { - val: obj.DD_DEG, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + type: "state", + common: { + name: "URL to light Icon", + type: "string", + role: "weather.icon" + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUNSET", { - type: "state", - common: { - name: "Time sunset", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUNSET", { - val: obj.SUNSET, - ack: true - }); + }); + + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "type", { + type: "state", + common: { + name: "result set; possible values: 60minutes, hour, day", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "type", { + val: obj.type, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUNRISE", { - type: "state", - common: { - name: "Time sunrise", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUNRISE", { - val: obj.SUNRISE, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color", { + type: "channel", + common: { + name: "Mapping temperature / color value", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "temperature", { + type: "state", + common: { + name: "temperature", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "temperature", { + val: obj.min_color.temperature, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SUN_H", { - type: "state", - common: { - name: "Sun hours", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SUN_H", { - val: obj.SUN_H, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "background_color", { + type: "state", + common: { + name: "background color", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "background_color", { + val: obj.min_color.background_color, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - type: "state", - common: { - name: "Mapping to weather icon", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - val: obj.SYMBOL_CODE, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "text_color", { + type: "state", + common: { + name: "text color", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "text_color", { + val: obj.min_color.text_color, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - type: "state", - common: { - name: "URL to color Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color", { + type: "channel", + common: { + name: "Mapping temperature / color value", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "temperature", { + type: "state", + common: { + name: "temperature", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "temperature", { + val: obj.max_color.temperature, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - type: "state", - common: { - name: "URL to dark Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "background_color", { + type: "state", + common: { + name: "background color", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "background_color", { + val: obj.max_color.background_color, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - type: "state", - common: { - name: "URL to light Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", - ack: true - }); + }); + self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "text_color", { + type: "state", + common: { + name: "text color", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "text_color", { + val: obj.max_color.text_color, + ack: true }); + }); + }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "type", { - type: "state", - common: { - name: "result set; possible values: 60minutes, hour, day", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "type", { - val: obj.type, - ack: true - }); + // *** Create hour forecast *** + self.setObjectNotExists("forecast." + "hour", { + type: "channel", + common: { + name: "forecast data for a time window of 3 hours (for 8 days from today 2:00 )", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day0", { + type: "channel", + common: { + name: "Forecast data for today", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day1", { + type: "channel", + common: { + name: "Forecast data for tomorrow", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day2", { + type: "channel", + common: { + name: "Forecast data for today + 2 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day3", { + type: "channel", + common: { + name: "Forecast data for today + 3 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day4", { + type: "channel", + common: { + name: "Forecast data for today + 4 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day5", { + type: "channel", + common: { + name: "Forecast data for today + 5 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day6", { + type: "channel", + common: { + name: "Forecast data for today + 6 days", + role: "info" + }, + native: {}, + }); + self.setObjectNotExists("forecast." + "hour.day7", { + type: "channel", + common: { + name: "Forecast data for today + 7 days", + role: "info" + }, + native: {}, + }); + //iterate over all hour objects + body.forecast["hour"].forEach(function (obj, index) { + var startTimeISOString = obj.local_date_time; + var objDate = new Date(startTimeISOString); + var myPath; + var myTime = getTimeFormattet(objDate); + + if (index < 8) { + myPath = "day0"; + } else if (index > 7 && index < 16) { + myPath = "day1"; + } else if (index > 15 && index < 24) { + myPath = "day2"; + } else if (index > 23 && index < 32) { + myPath = "day3"; + } else if (index > 31 && index < 40) { + myPath = "day4"; + } else if (index > 39 && index < 48) { + myPath = "day5"; + } else if (index > 47 && index < 56) { + myPath = "day6"; + } else if (index > 55 && index < 64) { + myPath = "day7"; + } else { + self.setState('info.connection', false, true); + self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); + return; + } + + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "local_date_time", { + type: "state", + common: { + name: "Date for validity of record", + type: "string", + role: "text", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "local_date_time", { + val: obj.local_date_time, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color", { - type: "channel", - common: { - name: "Mapping temperature / color value", - role: "info" - }, - native: {}, + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTT_C", { + type: "state", + common: { + name: "Current temperature in °C", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTT_C", { + val: obj.TTT_C, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "temperature", { - type: "state", - common: { - name: "temperature", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "temperature", { - val: obj.min_color.temperature, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTL_C", { + type: "state", + common: { + name: "Error range lower limit", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTL_C", { + val: obj.TTL_C, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "background_color", { - type: "state", - common: { - name: "background color", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "background_color", { - val: obj.min_color.background_color, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTH_C", { + type: "state", + common: { + name: "Error range upper limit", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTH_C", { + val: obj.TTH_C, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "text_color", { - type: "state", - common: { - name: "text color", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "min_color." + "text_color", { - val: obj.min_color.text_color, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { + type: "state", + common: { + name: "Probability of precipitation in %", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { + val: obj.PROBPCP_PERCENT, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color", { - type: "channel", - common: { - name: "Mapping temperature / color value", - role: "info" - }, - native: {}, + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "RRR_MM", { + type: "state", + common: { + name: "Precipitation total", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "RRR_MM", { + val: obj.RRR_MM, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "temperature", { - type: "state", - common: { - name: "temperature", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "temperature", { - val: obj.max_color.temperature, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "FF_KMH", { + type: "state", + common: { + name: "Wind speed in km/h", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "FF_KMH", { + val: obj.FF_KMH, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "background_color", { - type: "state", - common: { - name: "background color", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "background_color", { - val: obj.max_color.background_color, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "FX_KMH", { + type: "state", + common: { + name: "Peak wind speed in km/h", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "FX_KMH", { + val: obj.FX_KMH, + ack: true }); - self.setObjectNotExists("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "text_color", { - type: "state", - common: { - name: "text color", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "day." + myPath + "." + myTime + "." + "max_color." + "text_color", { - val: obj.max_color.text_color, - ack: true - }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "DD_DEG", { + type: "state", + common: { + name: "Wind direction in angular degrees: 0 = North wind", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "DD_DEG", { + val: obj.DD_DEG, + ack: true + }); + }); + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "SYMBOL_CODE", { + type: "state", + common: { + name: "Mapping to weather icon", + type: "number", + role: "value", + write: false + }, + native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "SYMBOL_CODE", { + val: obj.SYMBOL_CODE, + ack: true }); }); - - // *** Create hour forecast *** - self.setObjectNotExists("forecast." + "hour", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + type: "state", common: { - name: "forecast data for a time window of 3 hours (for 8 days from today 2:00 )", - role: "info" + name: "URL to color Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day0", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + type: "state", common: { - name: "Forecast data for today", - role: "info" + name: "URL to dark Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_DARK", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day1", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + type: "state", common: { - name: "Forecast data for tomorrow", - role: "info" + name: "URL to light Icon", + type: "string", + role: "weather.icon" }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { + val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day2", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "type", { + type: "state", common: { - name: "Forecast data for today + 2 days", - role: "info" + name: "result set; possible values: 60minutes, hour, day", + type: "string", + role: "text", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "type", { + val: obj.type, + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day3", { + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color", { type: "channel", common: { - name: "Forecast data for today + 3 days", + name: "Mapping temperature / color value", role: "info" }, native: {}, }); - self.setObjectNotExists("forecast." + "hour.day4", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "temperature", { + type: "state", common: { - name: "Forecast data for today + 4 days", - role: "info" + name: "Temperature value", + type: "number", + role: "value", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "temperature", { + val: obj.cur_color.temperature, + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day5", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "background_color", { + type: "state", common: { - name: "Forecast data for today + 5 days", - role: "info" + name: "background hex color value", + type: "string", + role: "text", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "background_color", { + val: obj.cur_color.background_color, + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day6", { - type: "channel", + self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "text_color", { + type: "state", common: { - name: "Forecast data for today + 6 days", - role: "info" + name: "text hex color value", + type: "string", + role: "text", + write: false }, native: {}, + }, function () { + self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "text_color", { + val: obj.cur_color.text_color, + ack: true + }); }); - self.setObjectNotExists("forecast." + "hour.day7", { - type: "channel", + + //Set last Sucessfull run + self.setObjectNotExists("info.lastrun", { + type: "state", common: { - name: "Forecast data for today + 7 days", - role: "info" + name: "Last successful run", + type: "string", + role: "text", + write: false }, native: {}, - }); - //iterate over all hour objects - body.forecast["hour"].forEach(function (obj, index) { - var startTimeISOString = obj.local_date_time; - var objDate = new Date(startTimeISOString); - var myPath; - var myTime = getTimeFormattet(objDate); - - if (index < 8) { - myPath = "day0"; - } else if (index > 7 && index < 16) { - myPath = "day1"; - } else if (index > 15 && index < 24) { - myPath = "day2"; - } else if (index > 23 && index < 32) { - myPath = "day3"; - } else if (index > 31 && index < 40) { - myPath = "day4"; - } else if (index > 39 && index < 48) { - myPath = "day5"; - } else if (index > 47 && index < 56) { - myPath = "day6"; - } else if (index > 55 && index < 64) { - myPath = "day7"; - } else { - self.setState('info.connection', false, true); - self.log.error("This should never happen. Please rerun adapter with debug-level and report it on https://github.com/baerengraben/ioBroker.swiss-weather-api/issues"); - return; - } - - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "local_date_time", { - type: "state", - common: { - name: "Date for validity of record", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "local_date_time", { - val: obj.local_date_time, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTT_C", { - type: "state", - common: { - name: "Current temperature in °C", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTT_C", { - val: obj.TTT_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTL_C", { - type: "state", - common: { - name: "Error range lower limit", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTL_C", { - val: obj.TTL_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "TTH_C", { - type: "state", - common: { - name: "Error range upper limit", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "TTH_C", { - val: obj.TTH_C, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - type: "state", - common: { - name: "Probability of precipitation in %", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "PROBPCP_PERCENT", { - val: obj.PROBPCP_PERCENT, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "RRR_MM", { - type: "state", - common: { - name: "Precipitation total", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "RRR_MM", { - val: obj.RRR_MM, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "FF_KMH", { - type: "state", - common: { - name: "Wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "FF_KMH", { - val: obj.FF_KMH, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "FX_KMH", { - type: "state", - common: { - name: "Peak wind speed in km/h", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "FX_KMH", { - val: obj.FX_KMH, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "DD_DEG", { - type: "state", - common: { - name: "Wind direction in angular degrees: 0 = North wind", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "DD_DEG", { - val: obj.DD_DEG, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - type: "state", - common: { - name: "Mapping to weather icon", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "SYMBOL_CODE", { - val: obj.SYMBOL_CODE, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - type: "state", - common: { - name: "URL to color Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_COLOR", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Color/" + obj.SYMBOL_CODE + ".png", - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - type: "state", - common: { - name: "URL to dark Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_DARK", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Dark/" + obj.SYMBOL_CODE + ".png", - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - type: "state", - common: { - name: "URL to light Icon", - type: "string", - role: "weather.icon" - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "ICON_URL_LIGHT", { - val: "https://raw.githubusercontent.com/baerengraben/ioBroker.swiss-weather-api/master/img/Meteo_API_Icons/Light/" + obj.SYMBOL_CODE + ".png", - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "type", { - type: "state", - common: { - name: "result set; possible values: 60minutes, hour, day", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "type", { - val: obj.type, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color", { - type: "channel", - common: { - name: "Mapping temperature / color value", - role: "info" - }, - native: {}, - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "temperature", { - type: "state", - common: { - name: "Temperature value", - type: "number", - role: "value", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "temperature", { - val: obj.cur_color.temperature, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "background_color", { - type: "state", - common: { - name: "background hex color value", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "background_color", { - val: obj.cur_color.background_color, - ack: true - }); - }); - self.setObjectNotExists("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "text_color", { - type: "state", - common: { - name: "text hex color value", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("forecast." + "hour." + myPath + "." + myTime + "." + "cur_color." + "text_color", { - val: obj.cur_color.text_color, - ack: true - }); + }, function () { + self.setState("info.lastrun", { + val: lastSuccessfulRun, + ack: true }); - - //Set last Sucessfull run - self.setObjectNotExists("info.lastrun", { - type: "state", - common: { - name: "Last successful run", - type: "string", - role: "text", - write: false - }, - native: {}, - }, function () { - self.setState("info.lastrun", { - val: lastSuccessfulRun, - ack: true - }); - }.bind({lastSuccessfulRun: lastSuccessfulRun})); - }); - }); - res.on("error", function (error) { - self.setState('info.connection', false, true); - self.log.error(error) + }.bind({lastSuccessfulRun: lastSuccessfulRun})); }); }); - req.end(); + res.on("error", function (error) { + self.setState('info.connection', false, true); + self.log.error(error) + }); }); + req.end(); + setCurrentHour(self); } function getGeolocationId(self,myCallback) {