c5te1n / node-red-contrib-dwd-local-weather

Node Red node to retrieve local weather forecast from DWD (Germany)
Apache License 2.0
13 stars 11 forks source link

Lookahead with Input #11

Closed ei23com closed 4 years ago

ei23com commented 4 years ago

Could you please add something like this to dwdweather.js

[...] node.on('input', function(msg) { updateWeatherForecastIfOutdated(node) .then(() => { if (weatherForecast[node.mosmixStation]) { var forecastDate = new Date(); forecastDate.setTime(forecastDate.getTime() + node.lookAhead); try{ var mylookAheadHours = Number(msg.payload.lookAheadHours) * 3600000; // Set lookAheadHours with Input forecastDate.setTime(forecastDate.getTime() + mylookAheadHours); } catch (err) { // no input value set } [...]

This would help al lot.

ei23com commented 4 years ago

And maybe a timestamp in the output like this: try { msg.payload = { "DateTime": Number(forecastDate.getTime()), "station": weatherForecast[node.mosmixStation].description, "tempc": getForecastedTemperature(node.mosmixStation, forecastDate), "humidity": getForecastedHumidity(node.mosmixStation, forecastDate), "windspeed": Math.round(getInterpolatedValue(node.mosmixStation, "FF", forecastDate) * 10) / 10, "winddirection": Math.round(getInterpolatedValue(node.mosmixStation, "DD", forecastDate) * 10) / 10, "precipitation%": Math.round(getInterpolatedValue(node.mosmixStation, "wwP", forecastDate) * 10) / 10, "precipitationNext24h": Math.round(sumFutureValue(node.mosmixStation, "RR1c", 24, forecastDate) * 10) / 10 };

c5te1n commented 4 years ago

I have added similar code in v0.1.8. You can now override the look ahead hours via msg.lookAheadHours. There is also a timestamp of the forecast as part of the answer now. I used forecast_dt to stay more consistent with the open weather node naming.