Calculate runtime in rule for timer - rounded values?

Hi experts,

I´m struggling with a rule regarding rounded values. I want to calculate a dynamic runtime for my pool pump with my rule:

if (Poolautomatik.state == ON) 
{
var temperature = OneCallAPIweatherandforecast_ForecastToday_Maxtemperature.state as Number
var stopPumpTime = if(OneCallAPIweatherandforecast_ForecastToday_Maxtemperature.state > 27 | "°C") now.plusHours(2) 

                   else now.plusHours(Math::round(0.07 * temperature))

My problem is, that the result for the timer (stopPumpTime) is a rounded value and can be 1 hour, 2 hours or 3 hours.

I want my rule to be more precise and calculate absolute values with 1 decimals. So e.g. 1,5 hours runtime.

How to achieve this? I know that the math::rounded function is responsible for the rounded values…but how to replace this?

Thanks and best regards,
Mario

If you need smaller steps use .plusMinutes or .plusSeconds instead of .plusHours (or combine all).

Thx for your reply. What do you mean with “sm”?

I tried .plusMinutes instead but the error warning message in visual studio code remains the same.

Thx

Sorry for the unnoticed typo ( writing on a smartphone). I corrected the reply.

What error are you getting?

Thank you - of course I need to switch from hours to minutes. I wanted to make things complicated… .:slight_smile:

Calculating with minutes is working as expected.

Cheers

1 Like