rlkoshak
(Rich Koshak)
8
It probably needs a hint as to what the var’s type is.
var DateTime lightOnStart = null
Forget the milliseconds. We are storing the DateTime object and using the milliseconds only for the calculation.
LightRuntime is an Item, not a variable. You must either postUpdate or sendCommand like my code does.
There was nothing in your original posts or code to indicate that you are trying to calculate the amount of time it has been on for the whole day.
Your easiest solution is to store the Switch Item in persistence once a minute and simply call
LightRuntime.postUpdate(MyLight.sumSince(now.withTimeAtStartOfDay))
That will get the number of minutes the light has been on since midnight. you could use now.minusDays(1) if you really want the past 24 hours.
If you need higher fidelity (i.e. seconds or milliseconds) or for some reason you can’t use persistence for this it gets really really complicated.
I recommend reviewing the following postings: