@bravenel
I did a few searches and didn't see anything directly related to my question. Apologize if this has been covered before, or if it's available in another trigger I missed.
I'd like to schedule a periodic trigger based on a variable. I'm using the ping function as an internet test, this would allow me to set a regular test interval, or increase the frequency when the internet is down.
Ideally this would appear as an option in the Periodic Schedule, under 'every n seconds (or minutes/hours with >n enabled). That would also allow me to define the time unit I want the variable to represent.
I am doing the same thing using a repeat loop, however this defaults as a variable in seconds, and I still have to set some type of trigger to get the loop started. Ultimately it results in a continuous repeating rule.
I also tried a repeat by CHRON, however it didn't like the variable in the string, unless there is a different syntax for inserting the variable. I just replaced the number with %PingRate% (a hub variable).
Perhaps a simpler (maybe) option would be to look at restrictions. I haven't used them much myself, but I am thinking you could introduce the logic you want into the restriction and enable / disable the rule based on that?
I will look at your suggestion, but it's most likely too late for the 2.2.9 release. There's a fair amount of effort required for this one.
I could sneak in being able to use a variable in the Cron string. That's a start.
The cron string could be built up using more than one string variable, allowing you to construct it however you want.
2 Likes
Thanks no problem. I can work around it several different methods, including two separate apps, one for normal polling and one for increased polling when the network is down, then select with a predicate. Believe that's what this was referring to.
I didn't think about using separate Cron string variables, could accomplish that with the existing conditionals that set the ping rates. I may even be able to set the Cron string with the different rate variables I have now - will look at that more.
Right now I'm using a repeat rule with variable length that works well, just need to figure the right trigger to get it started. I also have an "auto reset" switch that acts as a predicate for the series of rules, but can't use that in the same rule with a trigger. Also put in a daily trigger, and 'run actions' in the rule that actually does the pinging to capture when the PingRate is changed. Not the cleanest, but it's working. Will probably change those out and add some triggers based on variable changes instead.
The variable for Cron string is available now in release 2.2.9.140.
However, this is not dynamic. Subscriptions to those variables are not created. I will look into that possibility.
4 Likes
Dynamic Cron schedules will be in next release.
1 Like
Thanks - working with it now, understand not dynamic.
Not sure if a variable change trigger to run the rule actions is sufficient to pick up the new Cron. I'm using that to build a new Cron string based on a change in the PingRate.
However, I'm having a hard time building the string based on a variable using SET STRING. It just inserts the variable name vice the value. Not sure what the syntax should look like. Figured my attempt was 'over simplified!' Below are a couple rules to test the trigger and make the changes.
Recognize I'm trying to add a number to a string, probably a mismatch there. Also realize I need to change from seconds to minutes in the Cron syntax. I planned to make that change when I get it to work.
Realize that I will probably have to wait for the next release for the Cron to work completely.
Thanks!!
Test Rules
This is in next build.
Use %variable-name% to put the variable into string.
2 Likes
Yup - that part is working. Understand next release.
Separately, I'm trying to build the CronString variable by inserting a number variable in the minutes position. That one still escapes me, or the Set String (under Set Variable) doesn't allow you to insert another variable in the string. Replace String I think may work, but it doesn't recognize the number type as a valid variable. I haven't used the RM string operators to that extend. My sample rules were hidden above.
That is not supported. The only place in Periodic that variables will work, for now, is Cron string.
There are so many constraints on Cron Strings that I don't think variables for things like Every n minutes makes sense. You will notice that there is a pull down for the selection of minutes, as not every value works. So a variable number could have unexpected results.
If you are really into dynamic Periodic triggers, best bet is to learn how to construct Cron strings, and use those.
Here's one I constructed in pieces, including a number variable for the hour.
1 Like
Understand they are not supported in Periodic. I'm trying to build the string variable (a Hub variable) in a separate app using Set Variable. Old school "concatenate".
"0 0 " + %PingRate% + "? * * *".
I can't get the string variable to build correctly, probably just don't understand the proper syntax. Also recognize I'm trying to add a number type into a string.
Understand if Set String also doesn't support that.
No quotes.
No plus signs either. It's just a text entry field. Only thing special is %something%.
2 Likes
Thanks Bruce - I see now, it works. What was confusing is that I'm used to seeing the value behind the variable in the rule once added, and I interpreted that as the rule recognizes the value and not just the text. Set String doesn't show the variable values the way they are depicted elsewhere in rules.
I should have actually completely tested it first!!
Thanks for the turn on these changes and the help!!
1 Like
UPDATE - seems I can work around the variable subscription issue using a predicate. I tried pause/resume/run actions, and reset timers (long shot) which didn't work. However I noticed that when I stopped and started the rule in the APP, that captured the latest Cron String.
I ended up creating a virtual switch 'CronReset' with a 2 sec auto off, then used that switch as a predicate: 'CronReset is OFF' for my rule which triggers on the Periodic Cron. In a separate rule where I capture the change to the PingRate and update the Cron String, I set CronReset ON.
The predicate condition FALSE then TRUE seems to be sufficient to capture the new Cron periodicity until the string variable subscription is fully implemented.
@bravenel
Since the latest releases, 139, and now 140, I'm having problems with CRON triggers stopping when I update the cron string based on a variable.
I've been using the Cron string trigger for my network reset routine. When you added the string variable feature, a variable subscription was not released, therefore I incorporated a work-around where I used a predicate (required condition) based on a 2sec auto-off virtual switch 'CronReset'. The predicate is that the switch is off. CronString is set through a second cron update routine that updates the string based on polling rate, 15 minutes when the network is up, 1 minute when the network goes down. The update routine is triggered by a change in the polling rate, then sets the new string, and turns on the CronReset switch.
The cycling of the predicate condition was sufficient to capture the new cron string and continue polling, it worked great when I originally put it in place.
I'm not sure if you have added the variable subscription to Cron where the predicate is no longer required. I noticed, however, that when the string updates, it stops triggering until I go in and open= the app.
I tried adding a resume at the end of the update routine, that still didn't work. The 5 sec delay was to allow the 2 sec CronReset switch to reset to off.
Below are screenshots of the two primary, trigger and update, routines.
Thanks!
This seems like an oversight. I will look into it.
2 Likes
There was a bug. This will be fixed in the next release.
2 Likes
That's great - thanks! Is it subscribed to variable changes or will I still have to trigger a restart each time I update the Cron string?
Yes,. The problem was that it failed to reschedule after the variable changed. There had been a different bug with Periodic Schedule where it got rescheduled by mistake every time there was a Wait for Event in the rule -- resulting in many identical schedule events. The fix for that bug inadvertently prevented the variable changing from causing it to reschedule. That's been fixed, and it will work as it's supposed to in the next release.
2 Likes
Bruce - any update on when the next release will be out that incorporates this fix? It's still not working in .142, but I think that was the day before you posted the last update. When the cron variable changes, the rule fails to initialize and still stops triggering. Thanks!