I have a problem with calculating the time the light is on. The problem is that my device sends information on status change. So for example it sends data when device is turned on or turned off. Is it possible to calculate the time the light is on?
We have to assume that no information means previously reported state.
Subtract the time of the last ON value from the time of the last OFF value,
and if that result is positive, that’s how long the light was on, starting
from the ON time, and the light is now OFF.
If the result is negative, the light is now ON, and it’s been on for now()
minus the ON timestamp.