Within a Device Handler I can/could capture the previous value by including
previousValue = device.currentValue(“energy”) ?: cmd.scaledPreviousMeterValue ?:` 0
How do I do this within a smartapp? At this moment, my smartapp gets the currentValue of “energy” every hour and, while I could codethe following:
def curEnergy=sensor1.currentValue("current").toDouble()
def hourlyUsage=curEnergy - state.previousEnergy
state.previousEnergy=curEnergy
I have little faith that state.previousEnergy (or atomicState) will retain its value hour after hour. Besides, the device already apears to have this value so why not use it? But how??