Simple math--help needed

This thing is driving my crazy. I have searched all over the web but can’t find the answer to my question…

state.currentLevel = "${devices*.currentValue("level")[0]}"

log.debug "${state.currentLevel}"
state.nextLevel = state.currentLevel + 1

log.debug "nextLevel"
log.debug "${state.nextLevel}"

currentLevel 's value is 7. Then I want to add 1 to the value for nextLevel. Should be 8, but it becomes 71. :confused: Why??

In the smartapp developers guide they have exactly the same code.

state.switchCounter = state.switchCounter + 1

What am I doing wrong?

State is a bit weird. use some temp variables
def aa = state.currentLevel.toInteger()
aa = aa + 1
state.nextLevel = aa


Thank you! :slight_smile: