4 condition

Hi Gentlemen

How to write code if there are 4 conditions.

I made presets for Input PC, Input DJ, Input MiniJack, Input Projector, and All Off

Input PC, Input DJ, Input MiniJack, and Input Projector I get feedback ON, I mean if I run the Input PC preset the feedback is ON

But for All Off I get the feedback all (Input PC, Input DJ, Input MiniJack, and Input Projector) OFF.

How to write the code? I've tried writing it but it doesn't work.

if (Input PC == Off && Input DJ == Off && Input Mini == Off && Input Proj == Off ){
sendEvent(name: "MediaInputSource", value: "ALL OFF")
}

Please enlighten me, thank you.

Have you got it as a custom capability at the beginning of your code?
Also check your use of Off vs off and On vs on
Also your if's need "" round the string to check

Also you need
Else{
sendEvent(name: "MediaInputSource", value: "somthing on")
}

fancy version (cant remember if is it += or =+)

if (Input PC == "Off" && Input DJ == "Off" && Input Mini == "Off" && Input Proj == "Off"){
sendEvent(name: "MediaInputSource", value: "ALL OFF")
}
else{
string ON = ""
if (Input PC == "on"){ ON += "PC, "}
if (Input DJ =="on") { ON += "DJ, "}
if (input ..... you get the idea){}
sendEvent(name: "MediaInputSource", value: "$ON is on")
}
1 Like

I looked at this earlier and think, even though @mark.cockcroft has likely answered your question, it may be worth confirming some terminology to make sure we are speaking the same language....

What you refer to as "pre-sets" for "Input PC", "Input DJ", "Input MiniJack" and "Input Projector".... Like @mark.cockcroft , I assume you are referring to Attributes (displayed as State Variables on the device page)?

On a side note.... what may be easier, if you prefer... would be to setup virtual switch devices for each input device, e.g. PC, DJ, MiniJack and Projector, then use a Community app to provide the logic you are trying to setup here.... Probably not the best description of what I am thinking... but others may be able to flesh this out if it is of any use....

depends on the order you are looking for

a=" it "
b="is"

a+=b --> " it is"
a=+b --> "is it "
2 Likes