Jump to content

Binary values to store status of devices - unable to get &= to work


Recommended Posts

From the ' Cookbook '

And(binary) $x&=a

 

If
        'LivingRoomLight' Status is On
 
Then
        $iblights &= 100
 
Else
        $iblights &= -100

Doesn't work ?

I am basically wanting to have a variable represent the status of 4 or more lights so:

given iBLights variable

If device1 is switched on then add 1 to iBLIghts

if device2 is switched on the add 10 to iBlights

With applicable if device1 is switched off the add -1 to iBLights  etc...

Any ideas as what I am doing wrong?
 

 

Link to comment
1 hour ago, Jim P said:

Any ideas as what I am doing wrong?

If you're just wanting to set the variable to a number remove the & part and just leave it = "number"

 

1 hour ago, Jim P said:

If
        'LivingRoomLight' Status is On
 
Then
        $iblights &= 100
 
Else
        $iblights &= -100

But you're trying to add multiple lights to a variable. Other lights would then use +=.

Are you running any programs off the variable? Remember State Variables can send events causing other programs to run. Integer Variables do not trigger events.

https://wiki.universal-devices.com/ISY_Users:V5:Program_Variables

Another note is if any lights are on a dimmer maybe change the IF to "Status NOT off". This way the light could be at a % of brightness, but not "ON" and would increase the value since it wasn't "off". 

 

Link to comment

I really was just experimenting with the logical &  =  as identified in the cookbook ..  if I have to I can just do the simple =+ or  =-  methods..  ( it may just be my not remembering my logic training from 50 years ago as well )

In simple terms.. rather than having a separate variable and separate program to identify the status of a device... such as:

If device1 turns on then iDevice1 variable = 1

if device1 turns on then iDevice2 variable = 1 ....

I was thinking I could do something like this:

If device1 turns on then iBinaryVariable &=  1

if device2 turns on then iBinaryVariable  &= 10

... device3 the  iBinaryVariable &= 100

And for device off status ....   iBinaryVariable &= -1  ...  ,  - 10 ,  -100   etc.. 

So I could verify many devices status using a single variable ...  I haven't  worked out using a single program to determine device status by checking bit status...  1011 =  bit 4 device on, bit 2 device on, bit 1 device on ... 

I have no real justification for doing it this way, but it is a good training for me :-)

Link to comment
29 minutes ago, Jim P said:

I have no real justification for doing it this way, but it is a good training for me :-)

That kind of programming is beyond my need so my use/ability with &= has been limited. Just saw it was "binary". No other examples are given (that I saw with brief search) for that. 

Just keep plugging along and see if you can make something work. Maybe more advanced program gurus can chime in to help.

Link to comment

Jim, maybe a few more words about what you want you are trying to do in the big picture will generate some more suggestions. But I don't think you need eight programs - for example, I do this:

Any zone faulted - [ID 0073][Parent 0071]

If
        'TC2 / Home-IA / Home- BASEMENT DO' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- BASEMENT WI' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- DEN WINDOW' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- EAST FAMILY' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- EAST KITCHE' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- EAST OFFICE' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- FOYER' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- FRONT DOOR' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- KITCHEN WIN' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- LAUNDRY GLA' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- LAUNDRY WIN' Zone Status is Faulted
     Or 'TC2 / Home-IA / Home- LIBRARY DOO' Zone Status is Faulted
    (... more zones removed )
 
Then
        $State_Faulted  = 1
 
Else
        $State_Faulted  = 0
 

Link to comment

I use similar logic to determine when all of my motion detectors are in a particular state, but what I was trying to do was to use a binary variable  as a storage for 8 devices and attempting to parse out the 1 bits for 'on' status for specific devices..

Just an exercise for me mostly , but since I can't see how to parse out each bit without a separate program for each device.. I will simply use a status variable for each device and a program to parse out which device is which ...

No worries thanks for the assistance but I will just drop back and punt. ..

The Logic AND  &=  does work, but variables are not strictly binary so you can get decimal results which makes it easier for me to just drop this for now and go old school ...

Close this as I don't see a need to continue this discussion...

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...