Absolute number creation

I have a numeric variable representation of a sensor value.
It varies positive and negative.
How do I make it an absolute value?
Thanks!

You could do this algorithmically yourself (if less than 0, then set to 0 minus the value--which was my first thought before I tested to see if the thing I'm about to mention existed), but Rule Machine has this feature built-in as an operation you can perform on a variable:

You do have to put the value from your sensor into a variable first, if you aren't already. That can be done by the "Set Variable" action and choosing to set it to "Device Attribute," then choosing your device. You must, of course, also have a variable already created for this purpose (local or hub variable would both work; for this attribute, you probably want the "Number" type).

3 Likes

I am 99% sure this is what I was looking for.
Thank you!

It will not work only because...
RM4 shows many device attributes for an Aeon HEM, and RM5.1 only exposes "energy" and "power". I am using a non-stock driver, and am able to get the readings (powerL1,powerL2) from RM4, but not RM5!
So I could not get the clamps as individual variables.

Created a 5.1 rule
Created some variables
Set variable action
Set from device attribute
2 item list for attributes
Many item list in RM4

Confusing.

Would you show a screenshot of the right side of the device page, where it shows "Current State". Custom Driver should not matter. Would like to figure out why you aren't seeing those attributes.

Thanks. Now if you would try something:

In Rule 5.1, start to create an IF-THEN, and for the first condition select Custom Attribute. That will prompt you for a device (select the HEM), and then offer a pull down. See if all of those attributes are there or not in that pull down list.

Oh, what is the type of the variable you are trying to assign those attributes to? It probably is of the wrong type. It filters the attributes based on the type of the variable. If you are using a Decimal, try a String instead (or vice versa).

You could look at the driver, or I could. This is probably what your problem is. If you are looking for a number, but the attribute it actually a String, that value will have to put in a String variable and then converted to a number, then have the Absolute value taken on it.

A link to the driver you're using would probably also be helpful, unless you're able to figure the above out yourself from the code. My suggestion to use "Number" probably won't work if the attribute is declared as "Decimal," and it certainly won't directly if it's a string, but it's not clear to me why a driver author might do that for numeric values (unless they really want the unit as part of the value and not just part of the event).

They are all there.

It is coming back as a string!!!!!

Yep, that's the issue. Easy to get around.

Please expound, string to number int or dec!

And thank you, and all!!!!

I am not sure which I find more baffeling, the help here, or, the fact that the answers are already in the program.

WOW.

Thanks again, this worked so well...