Split one number variable to many bool variables according bits

  • Platform information:
    • Hardware: RPi3
    • OS: Raspbian buster
    • Java Runtime Environment: OpenJDK
    • openHAB version: 2.5
Number XTR3056          "XTR3056 Locking [%.0f]" <solarplant> (Studer)
Contact XTR3056_0       "XTR3056 Bit 0 Forbidden inverter [%.0f]" <solarplant> (Studer)
Contact XTR3056_1       "XTR3056 Bit 1 Forbidden charger [%.0f]" <solarplant> (Studer)
Contact XTR3056_2       "XTR3056 Bit 2 Forbidden boost [%.0f]" <solarplant> (Studer)
Contact XTR3056_3       "XTR3056 Bit 3 Forbidden transfer [%.0f]" <solarplant> (Studer)
Contact XTR3056_4       "XTR3056 Bit 4 Forbidden injection [%.0f]" <solarplant> (Studer)
Contact XTR3056_8       "XTR3056 Bit 8 Forbidden multi [%.0f]" <solarplant> (Studer)
Contact XTR3056_9       "XTR3056 Bit 9 Multi Indep allowed [%.0f]" <solarplant> (Studer)
Contact XTR3056_10      "XTR3056 Bit 10 Standby slave allowed [%.0f]" <solarplant> (Studer)

Please help me to split information according set bits in Number XTR3056. More bits can be set together.
The best way for solution I would prefer is do it directly in variable Number 3056 acquisition python script.
Thanks for help.

You could use Transformations or Profiles, e.g. 8 JavaScript Transformations (see Bitwise AND (&) - JavaScript | MDN). Of course, there might be a more elegant way to dissect your Number …

Thanks. I solved it directly in python script with logical AND for separate bits. Example python code:

s0 = openhab.get_item('XTR3056_0')
if (XTR3056&1 != 0):

s0 = openhab.get_item('XTR3056_1')   
if (XTR3056&2 != 0):

s0 = openhab.get_item('XTR3056_2')      
if (XTR3056&4 != 0):
1 Like