Jump to content

Program "If any two devices are on"


Recommended Posts

Posted

Is it possible to create a program what would look at a list of several devices in my house and if the state of ANY two of the devices are ON, then it would execute the program? (Any two or more of the devices must be ON for the program to execute)

 

Thanks,

Chris

Posted

I think you would need at least two programs for this:

 

1. a program that responds to any of the devices turning on and adds '1' to a state variable ... if it turns off then it subtracts '1'

2. a programs that responds to the state variable changing ... if it is greater than or equal to 2 then execute your intended code

Posted

I suspect this can be done with a single program through brute force, but it would get ugly quick if the number of devices gets much beyond three or four. 

 

if

(A and B is on)

or

(A or C is on)

or

(B or C is on)

or

.....

then

do something

 

As the number of devices grow, the approach proposed by bleepborp may become relatively more efficient.

Posted

If you have more than a few devices that you would like, it may work better to use state variables.

If Device_A is On then
     $State_Device_A = 1
Else
     $State_Device_A = 0
If Device_B is On then
     $State_Device_B = 1
Else
     $State_Device_B = 0
If (List all Devices here, we just want them in the IF block to trigger this whenever any of them change) Then
     $State_Device_Count = $State_Device_A
     $State_Device_Count =+ $State_Device_B
Else (Same as Then so it works no matter what the IF conditions are)
     $State_Device_Count = $State_Device_A
     $State_Device_Count =+ $State_Device_B

At this point, $State_Device_Count will reflect how many devices are on and you can run programs from that.

It would also be a good idea to sync Integer versions of the variables to give you program flexibility along with the Init To values for reliability. 

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.5k
×
×
  • Create New...