I’m new and playing around. In particular I’ve been using an intermittent problem with an iris smart button as my stepping stone to development. While reading a custom attribute two different ways I intermittently get different values. is there a preferred method that is more deterministic?
the log below shows .value returning the correct value while .date.getTime() does not
note that the usage of currentState and lastState is that I’m trying to understand how they differ as they never seem to for me.
the log shows:
10:55:14 AM EST: debug Button 1 pushed
10:55:14 AM EST: debug device.latestState('lastPress').value=1457711714107 //right
10:55:14 AM EST: debug device.latestState('lastPress').date.getTime()=1457711713819 //wrong
10:55:14 AM EST: debug device.currentState('lastPress').value=1457711714107 //right
10:55:14 AM EST: debug device.currentState('lastPress').date.getTime()=1457711713819 //wrong
10:55:14 AM EST: debug startOfPress=1457711713819
17910:55:14 AM EST: debug +++++ PRESS OUT
10:55:14 AM EST: debug Parsing 'catchall: 0104 0006 01 01 0140 00 ED22 01 00 0000 00 00 '
10:55:14 AM EST: debug setting state and attribute time to =1457711714107
10:55:14 AM EST: debug +++++ PRESS IN
10:55:14 AM EST: debug Parsing 'catchall: 0104 0006 01 01 0140 00 ED22 01 00 0000 01 00 '
on a button push-in a createEvent sets the attribute:
def curTime = now() //get the current time to use as debug
log.debug "setting state and attribute time to =${curTime}"
return createEvent([name: 'lastPress', value: curTime, data:[buttonNumber: button], displayed: false])
on button release the following:
def curLastPressDate = device.currentState('lastPress').date.getTime()
log.debug "device.currentState('lastPress').date.getTime()=${curLastPressDate}"
def curLastPressValue = device.currentState('lastPress').value
log.debug "device.currentState('lastPress').value=${curLastPressValue}"
def latestLastPressDate = device.latestState('lastPress').date.getTime()
log.debug "device.latestState('lastPress').date.getTime()=${latestLastPressDate}"
def latestLastPressValue = device.latestState('lastPress').value
log.debug "device.latestState('lastPress').value=${latestLastPressValue}"