Passing paramaters to rules

I'm probably asking too much from rule machine but I want to see what is possible. I'm new here. The use case is that I'm automating a hydroponic farm. Currently I'm focusing on watering schedules. We vary the water from 2x a day to 4x a day based on weather and I want to make it easy to switch between these. I have set up a basic rule with triggers that turns on the watering, checks to see if the switch turned on, waits, turns the watering off and then checks to see if the switch turned off. Here is a picture of the rule.

This rule currently has to be replicated 8 times (this will be increasing) with the things changing are trigger times (and button #), the switch and the rackName (a local variable) and notification device. The logic is all the same. What I would like to do is just pass all of these variables in as parameters and and let things run.

Of course I'm open to a completely different approach. I have still not gotten into the head of Rule machine.

Thank you.

I realize I didn't have the logic set right to checking if the switch is on or off. Here is the updated screenshot.

What are you looking to "parameterize"? From your rule and the description, it sounds like maybe just triggering your actions to run twice a day sometimes but four times a day other times? If so, here's one trick you can use: keep your actions in their own rule (probably one like the one above) and just don't use any triggers. Then, these actions will only run when called from another rule (or if you do it manually), and you can use another rule with whatever complexity you want in the actions to run this original rule as often as you need. You'll likely be able to set up something with just one or two more rules--easier than trying to do it in the triggers (and actions) for a single rule, most likely, particularly given the flexibility you'll have in the actions section for the rules that "call" this one.

If you're looking to automate different devices--like if %trackName% corresponds to some switch/valve you need to send a command to--then it's a bit trickier. Rule Machine doesn't have devices as variables, so you'll need to work something else out. It won't be pretty given this fact, but something like:

IF (Variable %myDeviceName% is "Device1") THEN
  On: Switch 1
ELSE-IF (Variable %myDeviceName% is "Device2") THEN
  On: Switch 2
ELSE-IF
 ...
END-IF

...would work, and would still let you keep everything in the same rule. An alternative approach is just re-creating or cloning (still technically beta; make a backup beforehand) the rule, then just swapping out the desired devices and making whatever other modifications you need. The advantage here is that each individual rule is likely easier to edit; the disadvantage is that if you want to change something, you'll have to change it in all of them, since the rules are no longer linked. Otherwise, I would in general recommend multiple, simpler rules over single, large rules.

1 Like