-
Use MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters to filter to just those messages that have the PA and chain it to a REGEX transformation to extract the number. The Channel should be a Number type Channel.
-
Link the Channel to a Number Item
-
Trigger a Rule when the Number Item changes.
val checkKthBit = [ Integer num, Integer bit |
val n = num.intValue
val k = bit.intValue
if ((n & (1 << (k - 1))) == 1) True else False // shift to the kth bit and check if it's 1
]
if(checkKthBit.apply(MyItem.state, 0)) // device from first bit is ON
if(checkKthBit.apply(MyItem.state, 1)) // device from second bit is ON
...
I am not at all certain that the above will work. I think Xtend will let us use the Java binary shift operators. If not I’m not sure how to do this.
If you use Scripted Automation you can use Python (specifically Jython 2.7), JavaScript (specifically Nashorn), or Groovy. See [beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x) to get started with Python.