I’m not sure what you mean by that, what is the -1 integer?
This part tells them all to turn off.
If motion turns on the lights, State is set to 2, that’s in the first trigger.
If nothing is done, and motion stays inactive for 5 minutes and motion turned the lights on (state = 2) then the second trigger turns off all the lights.
But if you turn one of the lights off manually then back on again, so that you can keep them on, then the third trigger should run. The state should be at 2 initially because motion turned on the lights. Then when you turn off one light, the value in the state variable changes from 2 to 1. Then when you turn off the switch the last time, state should now be equal to 1, so subtracting 1 from it again should get you down to 0 and once at zero the command is sent to turn off all three lights.
I’m not seeing where the problem is in the logic part of the piston. You even posted some logs previously and when I traced through those it looked to me like it was working just fine.
The only suggestion I’d have would be to add in a bunch of log to console commands to this piston so that you can show what the value of the state variable is as it moves along. I realize that lines 48, 55, and 57 set up a recursive process…but the piston just needs the value for state to be at 1 in order for it to turn off all the lights when it hits that section. The logs you posted previously show that it did that.
But it all boils down to what’s the value of the state variable as the piston goes along. So I’d add a bunch of logging to the piston to gain an insight into how that variable is being set.