Weather1 to darksky binding migration: calculating MinMax Temperature

Hey all,
with OH3 approaching I started migration from good old weather1 binding to DarkSky binding, since I already used the ForecastIO backend in weather1.
In the old binding I used the minMax item which looked like this:

    	"Min/Max Temp Heute [%s °C]"
    	{weather="locationId=home-FIO, type=temperature, property=minMax, forecast=0, scale=0"}

Since the MinMax is not available in DarkSky I want to use a virtual item and update via rule. Items:

Number:Temperature aussen_wetter_forecast_0_mintemp
	"Minimum Temperatur Heute [%.0f %unit%]"
	{ channel="darksky:weather-and-forecast:api:local:forecastToday#min-temperature" }

Number:Temperature aussen_wetter_forecast_0_maxtemp
	"Maximum Temperatur Heute [%.0f %unit%]"
	{ channel="darksky:weather-and-forecast:api:local:forecastToday#max-temperature" }

// Value needs to be calculated by rule
String aussen_wetter_forecast_0_minmaxtemp
	"Min/Max Temperatur Heute [%s °C]"

I’m not able to round the temperature items to NOT have comma, as well as only having a single “°C”. Here’s the current rule with current output.

rule "calculate weather minmax string"
    Item aussen_wetter_forecast_0_mintemp received update
    val String minmax_current = (aussen_wetter_forecast_0_mintemp.state as Number).toString + " / " + (aussen_wetter_forecast_0_maxtemp.state as Number).toString
    if (log) logInfo(filename, "MinTemp: " + aussen_wetter_forecast_0_mintemp.state + " MaxTemp: " + aussen_wetter_forecast_0_maxtemp.state)
    if (log) logInfo(filename, "MinMaxTemp calculated: " + minmax_current)


2020-10-15 13:42:33.997 [INFO ] [.script.aussen_wetter_forecast.rules] - MinTemp: 6.97 °C MaxTemp: 11.34 °C
2020-10-15 13:42:33.998 [INFO ] [.script.aussen_wetter_forecast.rules] - MinMaxTemp calculated: 6.97 °C / 11.34 °C

Any recommendation to make it look like “7/11 °C” would be appreciated.
Thanks much

Probably not the best choice. Apple bought DarkSky and will be shutting off the API within the next year according to their announcements.

You need to use String formatting and you need to convert the Item’s state from a Number:Temperature to a Number in the Rule.

Something along the lines of:

(aussen_wetter_forecats_0_maxtemp.state as Number).intValue

might be sufficient. I believe intValue will round up. You will have to add back the °C

1 Like

Hey Rich,
thanks for your feedback, even tough I was hoping DarkSky would last a bit longer. Any alternative recommendation these days?

At least I got my rule working for now. Seems like intValue is rounding down.

2020-10-15 23:48:49.042 [INFO ] [.script.aussen_wetter_forecast.rules] - MinTemp: 6.97 °C MaxTemp: 10.64 °C
2020-10-15 23:48:49.043 [INFO ] [.script.aussen_wetter_forecast.rules] - MinMaxTemp calculated: 6/10 °C

Thanks much

Depends on where you are located. I use OpenWeatherMap but only use it for current temp, current humidity, and cloudiness. For that it’s accurate enough.

1 Like