Gets previous value

i want to set the updated value to be send to string. when i change it and run the command it sends the old value to the address teh first time and only when i run it again it sends the correct one how do i make it send the new value

def setint(integerValue) {
    try {
        sendEvent(name: "integerAttribute", value : integerValue);
        String  sended =""
        sended += device.currentValue("integerAttribute")


I'm not exactly sure what problem you're describing, but from your code, I'd guess any problem you have might be related to retrieving the new value of a device attribute immediately after setting it. While that should happen pretty fast, it's essentially asynchronous, and the device is also cached when the app is loaded (for that particular wake/execution) by default either way.

If you want the "previous" value (the current one before you set then new value), use currentValue() like you are, just before you set the new value. If you want the value you just set, use your integerValue variable instead. That's what you're setting it to, so you already know that without needing to read it back from the device.

I think that second change will fix your problem if I am interpreting your question correctly, and both parts of my explanation above contribute to why.

1 Like

thank you im new to the language that hubitat uses