How can I implement one’s complement in OH rules? I’ve seen bitwiseOr and bitwiseAnd operators, but haven’t found a way to implement one’s complement (eg bitwiseNot, or ~)
OH4.0.2 / Linux
How can I implement one’s complement in OH rules? I’ve seen bitwiseOr and bitwiseAnd operators, but haven’t found a way to implement one’s complement (eg bitwiseNot, or ~)
OH4.0.2 / Linux
Can you use JavaScript? I tried this in JavaScript and it matches what I see here: Bitwise NOT (~) - JavaScript | MDN
var a = 5;
console.log(a);
console.log(~a);
2023-12-08 16:04:34.440 [INFO ] [nhab.automation.script.ui.ce69891350] - 5
2023-12-08 16:04:34.441 [INFO ] [nhab.automation.script.ui.ce69891350] - -6
Thank you - yes, I can see this seems to work using the scripting type available through the OH3/4 interface for creating rules. I hadn’t realised this (too may different scripting lanuages avialable?)
If I wanted to do the same via the OH2 style of text file rules/items etc, can this be done? I haven’t been able to make the full transition fron the OH2 style of items/rules text files, nbut maybe need to bite the bullet.
Someone with more rules DSL experience would have to comment. I think this comes from Xtend, but I can find no mention of a bitwiseNot or bitwiseXor. I did see this mentioning And and Or: Bitwise operators unavailable or limited? · Issue #511 · eclipse/xtext-xtend · GitHub
You could probably write a function that walked through the bits individually and reassemble as a complete word later, but instead of that I would recommend going to a new language. JS and JRuby appear to be quite popular now.
Rules DSL is not OH 2 style and other rules languages are available in OH 2.5. You have to install the Experimental Rules Engine (in OH 3+ that just became the rules engine) and then use Nashorn JS Scripting for this or install the Jython add-on and use that. Note that both of these are kind of unofficially deprecated in OH 3 and 4 due to lack of upstream support in the Jython case and having been replaced with the better GraalVM JS in the Nashorn case.
Thanks @jswim788 and @rlkoshak - Your replies made it suddenly clear how complex life can be with the myriad of langauges available with OH and how they have changed over time.
I’ve now got the leg up I required and far better understanding of the differences in scripting languages available. Thank you.