# RM variable math best practices

I’m setting up some rules with a variable delay. Each time the rule is run it increments a counter. I wait a time interval based on this counter with a base of 30 seconds. A count of 1 would be 30 seconds, 2 would be 33 seconds, 3 is 36, and so on. The math would look like this:

You can accomplish this in RM as:

This works but requiring four steps makes me cringe a bit. Is there a better way to handle this?

The handwritten formula doesn't seem to agree with your text description. The formula should be:

DELAY = 30 (1 + (x-1)/10)

Therefore, I am confused by what you are doing in RM. What am i missing?

EDIT: If my formula is what you want, it can be reduced to 3x+27. Is that easier to achieve in RM? I never have used the Math portion of RM

1 Like

You are correct. It should be 1 not x. Otherwise that’s how the code evaluates.

I could simplify it by not being OCD about the numbers.

It is easy in code but feels messy in RM. It might morph into an app but for now I’m leaving this part in RM. I’m reworking some core automation and still getting a handle on all the moving parts.

For any variable math beyond the basics, seek out WebCore, which is now a built-in app, and can handle your (and far more complex) formula with ease.

I’m not ready to learn WebCore yet.

I have moved the motion event and resulting calculation into my core app. I wasn’t ready for that yet but it went better than expected. Now the RM piece is just a widget that handles the delayed and cancelable pieces.

Thanks for the suggestions.

1 Like

So the rule ended up being a bit odd.

In this picture the motion sensor has been triggered 7 times. This results in the lights remaining on for 9 minutes and 36 seconds if the sensor doesn’t get tripped again.

The counter cools down by 1 every 6 minutes. It caps out at 40 which will give an on time of 5x the base duration (6 minutes in this example).

These numbers need to be adjusted. Previously the duration was static and would vary based on time of day (morning: 180 seconds, day: 300, evening: 240, night:180). I see that 6 minutes should have been 5. Now that I have some logic in there I’ll play with the formula and values.

This started out as a rewrite of the color temp and dimmer level logic. I wasn’t quite ready to tackle the triggers but what ya gonna do?

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.