I'm stuck! I'm trying to use RM to update a variable according to active notifications. This is so I can I have single tile (in SharpTools) display that variable on my dashboard when one or more (up to 3) notifications are active. The crucial part is that when active, I want the variable to update every couple of seconds displaying the next notification, repeating continuously. Once there are none the repeat should stop.
If I turn all 3 switches on, the rule fires and the variable will update correctly for 1 cycle. But it will remain set at "hh:mm - Switch 3 On" When it repeats the actions, although the switches are all still on, RM ignores their status and does not update the variable on each pass.
If I trigger the rule again by switching a switch on or off, again it runs just once. When it runs again the %time% is changed on the notifications for the switches that are still on. It appears that %time% is not the time that the switch was turned on but is actually %now%
I'm not convinced the END-REP is needed (but I'm happy to be corrected) The repeat is set for "repeat while variable notificationOn is True". As soon as all of the switches are turned off "notificationOn" goes false and the repeat ends successfully. It's just that the logs show the actions being repeated but ignoring the current on status of the switches.
Well, like you, Iām happy to be corrected, because Iāve never left a REPEAT unterminated. But there are two possibilities, one as you mention, and another where the WHILE does an implied āend ruleā, which falls off the end immediately. Iāve never seen the āmissing END-REPā behavior definitively defined.
Everything between the WHILE and the END-REP will be repeated. In your example nothing is between the WHILE and the END-REP. Nothing will be repeated even if you add the end-rep.
Here's an example... RM evaluates the condition at the time of the WHILE. If the condition is true it will repeat all actions until the END-REP. If not it skips the whole block. In this example it will attempt to send disarm commands to envisalink every 5 seconds up to 10 times as long as the status does not contain Ready.
More to come, but the Repeat, including "While..." syntax, is documented. You can also see this thread for some older examples, which let you do the same thing with a slightly different syntax (but it will still work): How to get Repeated Notifications using Rule Machine
@johnwill1 what you could do is put the WHILE statement at the beginning of the rule and the END-REP at the end... but in that case you need something to manipulate notificationOn... otherwise it will just loop forever every 10 seconds. Unless it's a hub variable manipulated outside of this rule.
That seems to sort it out so that the tile representing the variable "scrolls" through the switches that are on and it does now repeat though it doesn't seem quite right. Switches 1, 2 & 3 are all on and it is scrolling 1,2,1,3,1,2,1,3. Maybe altering a switch while the repeat is active is firing multiple instances - it's difficult to see from the logs. Perhaps there's a better way of achieving the same end result...
With regard to the time - I was hoping that %time% would give me the time that the specific switch was turned on and that the time would stick if another switch was turned on. However lets say I turn switch1 on at 19:15 - the variable will show that; However if I subsequently turn on switch2 at 19:25, the time for switch1 is also updated to 19:25. So it is displaying the time the rule was triggered last even if it is not that particular switch that triggered it. As such the %time% is unusable as it becomes "incorrect" as soon as the status of another switch changes. These virtual switches are intended to show the time the event happened that caused the virtual switch to operate.
It is - notificationOn goes false when all 3 switches are turned off via another RM url that also sets the votificationActive variable to null, so that I get a blank tile when nothing is active.
Yes. Any change to any of the three switches will spin up a concurrent instance of the rule. This can be prevented with some logic involving the "private boolean" function if you want to go there.
Anything I can do to advance your cause I am happy to.
Private Boolean is - wait for it - a boolean variable private to the rule. By default it is true. But it can be used to prevent a rule repeating, as in the example below... if private boolean is false it means the rule is already running so abruptly exit the rule. Otherwise set it false so a second trigger will just exit harmlessly. And at the end don't forget to set it true again!