Jump to content

Program "If any two devices are on"


MustangChris04

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...