I would like to make a Dash button that will ask me a time
for example. I want to turn on a light for 12 minutes. I push a button on the Dashboard. it pops up, I enter the time, then I use that number as a variable to keep that light on for the 12 minute.
right now, I have a If-then statement that when I push a switch, it checks a series of V-buttons to see what one is on.. but that takes up a lot of room for a dash..
You can almost do this with a global or local variable, a variable connector, and a rule that uses that variable to turn on/off a switch (and there's a workaround to get the rest to work if that's a problem). To do that:
-
Create a global variable (from the parent Rule Machine app) or a local variable (from within the rule itself). Either should work, as you just need to create a connector for this variable, which you'll use on the Dashboard. So, also create a connector here. I'd use "Number" as the variable type and "Variable" as the connector type, though you can experiment with other combinations to find what you like on Dashboard.
-
Create a new dashboard tile for the variable connector device (be sure to authorize the device in the child Dashboard app first or you won't see it). I'd recommend the "Variable Number" template, but again, you can experiment with different things here depending on what type of variable/connector you create. As you'll see, this lets you input a value for this variable from a Dashboard tile.
-
Create a rule that goes something like this:
Trigger events: Variable *changed*
Actions to run:
On: Switch
Set variable numberOfSeconds to variable*60
Wait for event: elapsed time --> %numberOfSeconds%
Off: switch
You'll notice one oddity here: you can only use a variable in the seconds fields for waits (or delays), so I'm using a second variable here (set via the "variable math" feature you can use when setting the value of a variable). You can make this a local variable of type Number unless you have a reason to do something else.
- Now, test it out: use the variable tile on your Dashboard, and you'll see that the rule should work: turning on the switch, waiting the specified number of minutes, then turning it off. Because "Waits" are cancelled if a rule retriggers, changing the value while the switch is still on will also "reset" this timer, which I'm guessing is the intended behavior. If not, you could use a "Delay" (not cancelled) instead.
However: the oddity I mentioned above is that this rule only triggers if the variable value truly changes. If you set the Dashboard tile to a certain value and then tap it and "set" it again to the same value, the rule won't trigger. You can get around this by "resetting" the value to 0 after it gets set, assuming you never want 0 as a valid value. Then your rule actions would need to be something like:
IF (Variable is 0) Exit Rule
Cancel Delayed Actions
On: Switch
Set variable numberOfSeconds to variable*60
Set variable to 0 --> delay 0:00:05
Delay %numberOfSeconds% (cancelable)
Off: switch
This uses a delay instead of a wait because you need to control what does (and doesn't) get cancelled and when. I used a simple conditional as the first action to effectively not do anything in the case when the rule resets the variable to 0, which helps you with getting the rule to trigger any time you set the value from the Dashboard (assuming, again, that you never use 0 as a valid value).
1 Like