Generic way to test "time since state became X" for device attributes?

This may help not sure haven't looked into it myself yet: