
Is a nice exercise related to a lua-script with application of uservariables and display of such uservariable's value!

Challenge: for the realisation look around for examples at internet (starting with this forum)!!
You
might use the following general structure
(given just as an example, because there are many ways to setup such calcs):
1) make 3 uservariables:
Time_previous_check
On_time
Cumulative_energy
2) make lua-script with (approx.) following contents:
a. Read Time_previous_check
b. Read On_time
c. Read Cumulative_Energy
d. Check actual_systemtime
e. Check whether device is ON
f. if ON then deltaT = (actual_systemtime - Time_previouscheck) else deltaT = 0
g. On_time = On_time + deltaT
h. Cumulative_Energy = Cumulative_Energy + (deltaT) * (Power)
h1 (alternative for h). Cumulative_Energy = On_time * (Power)
i. Time_previous_check = actual_systemtime
j. Save Time_previous_check
k. Save On_time
l. Save Cumulative_Energy
3) make display for On_time and Cumulative_Energy
Very simplistic explanation for the aspect:
Why uservariables?
A script
internally applies local variables, which are not saved at the end of the script.
Therefore when starting a new run of the script you cannot call back the values of such local variables as existed at the end of the previous run.
Uservariables are stored outside the schript and can be called back as reference.