Hi Thomas,
I think the problem is that inside of the expression, you want to keep track of the result of the same expression at a different time with valueAtTime, and that’s not how expressions work; they can find out the expression result of a different property at any time, but when looking at their own valueAtTime, they only see the originally-set or keyframed value before expressions.
Because of this, starting/stopping or variably controlling the speed of something using expressions is not straightforward at all.
Dan has written an excellent article about that many years ago: https://www.motionscript.com/articles/speed-control.html
IF your cycle duration and angle A are not also keyframed, then this variation on the hold keyframe method described in the article should work:
spd = thisComp.layer("Spotlight Control").effect("Play (1st key)")("Checkbox");
n = spd.numKeys;
cyc = 360/thisComp.layer("Spotlight Control").effect("Cycle Duration (sec)")("Slider").value;
if (n > 0 && spd.key(1).time < time){
accum = spd.key(1).value*(spd.key(1).time - inPoint)*cyc;
for (i = 2; i <= n; i++){
if (spd.key(i).time > time) break;
k1 = spd.key(i-1);
k2 = spd.key(i);
v2 = spd.valueAtTime(k2.time-.001);
accum += cyc*(k1.value + v2)*(k2.time - k1.time)/2;
}
accum += cyc*(spd.value + spd.key(i-1).value)*(time - spd.key(i-1).time)/2;
}else{
accum = cyc*spd.value*(time - inPoint);
}
thisComp.layer("Spotlight Control").effect("Angle A")("Slider") + accum;
If those parameters (cycle duration and startangle) could be keyframed, especially with easing, then stuff gets a lot more complicated.
Then we’d wind up using the slower brute-force method of stepping through every previous frame by frame to calculate a correct running total (accum) of checkbox.valueAtTime*cyc.valueAtTime + angleA.valueAtTime.