[SOLVED] Comparaison with OpenWeatherMap temperature

Hello everybody

I am trying to implement a new rule in my setup. I would like to get the temperature in the next 12 hours and if this temperature is below 12°C, I will get a notification to start my boiler. I am using OpenWeatherMap Binding to get the weather forecast.

My actual rule is :

.rules

rule "Check 12h temperature"
when
    Item localHourlyForecast12Temperature changed 
then
    if( (localHourlyForecast12Temperature.state as DecimalType).intValue <= 12 ){
        notificationBoilerStart.sendCommand("ON")
    } 
    else{
        notificationBoilerStart.sendCommand("OFF")
    }
end

.items

Number:Temperature localHourlyForecast12Temperature "Température à 12h [%.1f %unit%]" <temperature> { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#temperature" }

Unfortunatelly I am not able to get the comparaison <12°C

Thanks for your help

Hello,
If I’m thinking right before the first coffee as its a number item you don’t actually need to convert it for the if comparison. You can just use localHourlyForecast12Temperature.state <= 12. Also you could add a log line before the if part to see if the rule actually triggers.
If the trigger doesn’t work you could change your approach and use a cron trigger that fires once an hour instead.
Best regards Johannes

Your Item has UoM, Units of Measurement. So it’s effectively 15 °C not just 15, and comparing with just 12 is apples-and-oranges.
This is one of the clumsier parts of UoM.
You can either extract just-the-number or compare with a temperature.

if( (localHourlyForecast12Temperature.state as QuantityType<Number>).intValue <= 12 )

if( localHourlyForecast12Temperature.state <= 12 | "°C" )

3 Likes

Thank you for your help, It works now