# Global variable as delay?

Is it possible to use a variableās value as a delay?
I actually would like to take the variable and multiply by 1.05 and use the new value as a delay? How would I go about it? Any help would be appreciated

First do the variable math through the normal way you do that. Then in the delay field just substitute in your %variablename%. Variable math is under the set variable. Obviously it has to be a number variable for that option to come up.

what you can't see here is that after you select the operator, you have a drop down that you have to pick constant from.

Thanks for your help, It got me started in the right direction.
I must be missing something......
I have a global variable N1FM set to 15 as a decimal
It does not look like it is picking up on the *1.05 as the delay is still 15.0
(I also tried to create another global variable and use that in the variable math instead of hard coding the constant 1.05 but it did the same thing as well)

also it does not turn the switch off at all.

That's because delayed actions get set at the beginning of the rule before the other actions. So you here's what's happeing:

Turn off after delay of 15 seconds scheduled.
Variable math
Switch on
Variable math.

You need to but in a Delayed Action in between the on and off.

1 Like

Like this? same result

Well, #1, delays have to be in whole numbers. so, when it does the math of 15*1.05 that comes out to 15.75. It might round or it might truncate.
Try not resetting the variable at the end and see what the variable changes to. Then also change your factor to something like 2. Why would you multiply 15 by 1.05?? A 16 second difference is that much different than 15?

not changing the variable results in the variable changing to 15.75.

In my case I wanted it to be as accurate as possible as I'm using it to measure out ml of liquid from a pump. I am using the offset to "calibrate" each pump.

Hubitat messaging is not that accurate. If 1 second difference can mean the difference between the correct amount of fluid and the wrong amount of fluid then this isn't the proper system to be doing that. It should be locally controlled with a timer at the point that it is pumping.

in my testing when I manually specify the delay it is spot on and is + or - about a ml at 100ml
but a second off will have to do.
Thanks for your help

That's only if the hub isn't busy when it does either function. I wouldn't be surprised if it might be off by as much ad 5 depending on the device and the hub's load. I'm telling you, this is not the right way to do what you want to do. You should trigger a device which has a timer built into it that will shut off when the correct amount is dispensed.

I must be a moron. for the life of me i cannot find or understand how to set delay with a variable. the hours/minutes/seconds fields are numeric only. for switch off:

simply trying to set a global var to 10 for 10 minutes. and apply to a delay statement to turn off switch after 10 minutes. it's a nice to have as i CAN just type the duration into the rule but would sure be nice to be able to just change 1 var in 1 place instead of updating 4 rules... DRY!! :>

You can put a variable in the seconds field, with %variable-name%.

For Delay Actions, you can do it more explicitly.

1 Like

I have a question about how the math works out with variable math used in a delay.
I have N4CM set to 20 (Number) and OffsetN4CM set to .92 (Decimal)
N4CM after the rule runs is set to 19 instead of being set back to 20
Does it round or truncate?

Also the actual delay doesn't update based on the variable math in either the log or the rule, but I'm not sure if it is supposed to update. (doesn't update after pressing update rule either)
The delay based on variable math is in fact correct in real life.

When going from a decimal value to number, it truncates. There is a round function available also if that is needed.

I'm not sure what you are referring to, the parenthetical value shown for N4CM? (Update Rule has nothing to do with this, btw.) Could you also show the variable as it's displayed on the main page of the rule (for local variable) or main page of Rule Machine (for global variable). As displayed in the rule (Select Actions to Run) the value would be as of that moment when the rule was displayed, not reflecting things that might happen when it runs. It could be that the logs are pulling that same value. I'll have to look into when it gets that value. There are two different relevant time periods -- when the rule is created, edited or displayed, and when it runs.

1 Like

correct the 10 was from when I created the rule? because it hasn't updated at all not a big deal though I changed both variables to decimals and now I get the desired result.

From the main page as it is a global variable:

Thank you for this (putting the variable in the seconds field)! I was trying to make it work in the minutes field :-).

Between Hubitat design and this user community, I'm starting to think there is nothing Hubitat CAN'T do!