How to clear a state value / attribute?

This is probably an easy one but I can't seem to figure it out..

I'm working on a driver that sets several attributes (side-note -- I'm not sure what the official term is -- attribute/state/event?)

I have a driver setting which controls if HTML attributes are set or not.

Put simply, there's a check in the driver code which will set the attribute/event.. like this:

if (showHtml) {
        sendEvent ( name: "html", value: "some long string value..." )
}

However, I quickly noticed that if I disabled the 'showHtml' setting, the existing attribute will persist and never get cleared.

I'd like to clear/remove it if possible.. so, I updated my code to this:

if (showHtml) {
        sendEvent ( name: "html", value: "some long string value..." )
} else {
        sendEvent ( name: "html", value: null )
}

However, even this doesn't seem to 'stick'. The image below shows the 'html' attribute (notice the "Mon May 29" in there.. that's when it was last updated -- probably when I disabled 'showHtml')

Yes, the value of 'html' will change to 'null'.. but, it'll revert back to this if I refresh the page.

So, is there another way to 'clear' out an attribute?

Perhaps using an empty string "" and adding isStateChange: true ??

device.deleteCurrentState('html')

2 Likes

This worked - thanks!

4 Likes