Considering your stated application for sunscreencontrol, think about a strong&long hysteresys, because otherwise the screens may be jumping up and down!
2 General approaches, which can be combined (or not):
1) timing of the script loop, which causes the script to be executed with intervals
2) filtering of data, which 'smooths' the incoming data
1) is rather simple with many examples.
General approach:
if <time-check> then
[script-actions]
end
2) is slightly more complicated.
General approach:
a. make user-variable output_var and set default value
b. (in the script) set value alpha for 'speed' of filter. 1 = 100% of actual data (= quick reaction), and 0.1 is 10% of actual data (~ lazy reaction)
c. read actual data
d. read user-variable output_var
e. calculate output = output_var + alpha * data
f. check value of output to take action (or not)
g. save output as user-variable output_var
h. repeat c. till g. in which 1) may set the rythm of the input & output.