Dynamic timer limit calculation (open windows/doors reminder)

I am on OH 3.2 on a RPi4 and trying to have a dynamic calculation in a rule.
The rule sets timers individually per Door/Window contact once opened and issues a message to my phone and has Alexa remind me if the door/window has been open for x minutes.
So far I have only managed to set a hard value here like 5 minutes.
However I would like to have this value calculated depending on the outside temperature to set a very short time if it is freezing and longer times during warmer seasons (only up to say 15 °C).

So I came up with following formula but could not find the correct syntax for a variable in a rule:
Basically it should be 2 to the power of (outside temp. divided by 3) and its result rounded down to the next integer.
This gives some progressively rising minute values from 0 upwards.
(WeatherandForecast_OutdoorTemperature.state includes °C so must be first converted to number for the calculation)

I tried the following below but the logs say Math.IntDigit does not exist in Java (I found this in an xtend doc.). And I assume other stuff might be wrong too.

var Timer_Limit = Math.IntDigit ( 2.operator_power ( (WeatherandForecast_OutdoorTemperature.state as QuantityType<Number>).doubleValue/ 3 ) )

Can anyone help me here what the correct mathematical expressions in the rule would be?
Many thanks.

Did you get this code from here: Xtend IVR Help File | IVR Tutorial | IVR Scripting Language | IVR Programming | Online IVR Guide

I do believe that’s another XTend than the DSL in openHAB, since it is a company with the name XTend

Note that the openHAB rules documentation points you to:


Your code might be something like

var Timer_Limit = Math.Round(...)


I have exactly this for my roof windows. But I would suggest that you use a separate rule to calculate the time, and then another rule where you use the item previously calculated. That way it is easier to debug.
I’ll try to post my code here, but I’m on the phone so maybe copying it from the shell will look weird…

rule "Adaptive_Window_Open_Time"                                                
        Item DELTA_TEMP_IN_OUT changed                                          
var Number openTime                                                             
var Number a                                                                    
var Number b                                                                    
        if((DELTA_TEMP_IN_OUT.state as Number) > 0.0){                          
                a = 0.0875 * (DELTA_TEMP_IN_OUT.state as Number).doubleValue    
                b = Math.exp(a.doubleValue)                                     
                openTime = 30 - 4 * b                                           
                openTime = 30                                                   
        //logInfo("math.rules","Recalculated adaptive window opening time to: " 
+ openTime)                                                                     

Note that I use an exponential function with empirical constants. It gets really cold in Germany and then you want the window to shut quickly (mine are automated)

1 Like

Thanks, right, it seems DSL does not have a ‘round down’ function. I have to do it differently I think.

Thanks for your example. I did not think of calculating an indoors/outdoors delta but that’s probably more exact than just the outside temp.

Anyway I will have to learn the math. functions syntax first from the links above.