Rules Machine Symbols

I know that rules machine allows you to use variables such as %time%, %device%, %date% and %now%. My question is if it is possible to report on a value of a field on a device. For example, I am using the NUTS UPS Device driver code to define a virtual device that reports that status of my UPS.

In the "Power Source" option of Rules Machine, I can examine if the device is on MAINS or on UPS easily. However, I want to query Battery, which is a percentage and a field in the driver.


It is easy to extract and test such values in Webcore. How is this done in Rule Machine?

If you want a conditional action, "Battery" as a standard attribute is available as capability you can choose when creating the condition. If you want power source, you'll have to use the option for a custom attribute and choose this one. Both are otherwise similar. Both are also available for triggers. If you have a specific rule you're trying to create and aren't sure how to use whichever of these you need, feel free to ask!

It's not really the creation of the condition. I'd like to amend this rule to include how much battery percentage was left at the time power came back.

So, in the push notification, I'd like %battery% of the battery was remaining. That's easy in Webcore. My question is how do I get a %battery-percentage-left% variable for rule machine?

In that case, I'd create a local variable, assign the battery percentage to that, then embed the variable in your string (since you can't directly embed an expression to get the level).

PS - also make RM happy by adding the END-IF. :slight_smile:

Point well taken. I added the End-if's. My bad.

I have been trying to do the simpler things in RM. I wrote a Webcore piston to do what I want. I am not sure how to get the variable into the message with RM as I have done with Webcore below.

To do this in RM, I'd first create a local variable. Use the "Create local variables" link/button towards the bottom of the rule. Afterwards, it will look something like this:

Then in your rule, create a new trigger with the "Custom attribute" capability (you'll need this because RM doesn't have a direct way to use the powerSource attribute otherwise, though in the course of trying this I learned that it is in fact part of a standard, if not-often-used, capability). Either choose or type (depending on whether your driver does indeed use the standard capability) "mains" here:

"Custom attribute" trigger with "powerSource" attributes and "mains" attribute value selected

Then, set the local variable to the battery percentage:

.

Finally, use that variable as part of your string when sending the notification (you can use local or global variables inside the % symbols in the same way you can use RM built-in variables). When you're done, the rule should look something like:

Robert, this is a really great guide. I did not realize that the set variable to attribute was buried in here. That made all the difference. It seems like I have an equal number of Webcore and RM routines. I like doing the simpler things in RM, but Webcore is easier when it comes to more involved logic or formatting. Your example is going to help a lot of people. Thanks again.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.