MustangChris04 Posted July 7, 2014 Share Posted July 7, 2014 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 Link to comment
bleepblorp Posted July 7, 2014 Share Posted July 7, 2014 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 Link to comment
oberkc Posted July 8, 2014 Share Posted July 8, 2014 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. Link to comment
MustangChris04 Posted July 9, 2014 Author Share Posted July 9, 2014 Thanks guys. Both great suggestions! Link to comment
MaddBomber83 Posted July 9, 2014 Share Posted July 9, 2014 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. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.