Coding help using device states

I’m using WebCoRE to capture some device states (RGBW lights), but the code seems note very compact. I’m sure there is another way to do this, but I don’t know how. Would appreciate some help from folks. Below is the piston; note all of the if/then/else statements. Any ideas of simplification?

I like to streamline my code too, but I usually follow the “if it’s not broken, don’t fix it” mantra. I don’t see any obvious areas for change.

OK. Thanks for the reply. It just seemed to be quite inefficient, but I didn’t know how to make any changes. All of the “switchX” values are listed in the “current states”, and it seemed like setting those could be done easier than 6 if/then/else statements…

I’ll leave it alone…

I don’t have my thinking head on, but as variables are initialised on each run, is there any particular reason for initialising them in the ‘then’ block rather than the definition? That’s assuming there is a reason for using variables.

Otherwise I think it looks fine as it is though. It is clear what it does.

Well, I’ll start by saying my coding skill are rudimentary at best. With that said, I put the capturing of variables in the “then” section as they may change throughout the days (the switches are LED light profiles that run). So the purpose of the piston is a notification piston. When the contact switch opens, set one set of lights to red for a brief time. So, just prior to setting to red, collect the current state (to find out which profile was running), then after changing to red, return the lights to the condition they were in.

Some expert coders could probably write that in a line or two…takes me…well, lots of lines (brute force).