Getting rid of old/unused State Variables

Any chance that could change? Or is it more complicated than it seems to provide? I think the reason for the ask is at least valid, right?

It would allow a device driver to handle multiple device models potentially without messing up how they are viewed on dashboard. My biggest use case is a motion sensor that can have a battery or can be plugged in or a motion sensor driver that covers many motion sensors, some of which don't support batteries.

Mike,

I performed this test:

My Inovelli had a State Variable: " oldLabel: Garage Flood "

  1. I added the highlighted code to your "Basic Z-Wave Tool" (see below)
  2. Replaced my Inovelli NZW31 with the Basic Z-Wave Tool
  3. All the state variables could be seen with the Basic Tool as the driver
  4. l asked for a Parameter Report

Results:

The "oldLabel: Garage Flood" was no longer shown.

I reverted back to the Inovelli Driver and the removed State variable did not reappear.

Perhaps the driver did not try to recreate the "oldLabel:" as I did not try to change the Label.

Was what I did just suppressing the display?

John

No, I've muddied the water a little. There are two places referred to as state in drivers:

  • state (which this post was originally about and you've shown
  • device.getCurrentStates() which is what I've introduced and stores attributes

Removing anything from state works. Removing attributes is what doesn't.

That's OK. From my standpoint the state.variables (correct term?) is all I care about. Sometime back I switched from one driver to another. The old driver left a bunch of state.variables on the device page which annoyed me (I think it's a personality disorder :slight_smile: ) . I was able to remove them using the above method.
Hence my original question: Is it possible to create an driver like the "Basic Z-Wave Tool" to wipe out the current state values for the reason I stated above?

Thanks for the explanation on the two "state" types.

John

4 Likes

It is more complicated than that.
We have discussed dynamic device capabilities, however it's not something we expect to entertain.

I don't think I'm asking for fully dynamic capabilities though it would be nice. I want to remove an attribute value which I guess means I want to delete the event.

Do you still have a copy of this?

Probably but it's incorporated into the Device driver.

Temporarily change your device to use the Device driver, click Save Device and then you get:

Click the Delete buttons, then swap back to your actual driver and it's all good.

8 Likes

it would appear that simply calling currentState.remove() removes all current states / (attributes) and then they will repopulate as and when they are sent as new events... enjoy :+1:t3:

1 Like

Can you share a code snippet that uses this? I get a missing method exception.

One from my stash that has similar capability

Code
/*

 */

static String version()	{  return '0.0.0'  }
definition (
	name: 			"Quick and Dirty", 
	namespace: 		"thebearmay", 
	author: 		"Jean P. May, Jr.",
	description: 	"Allow killing of current states",
	category: 		"Utility",
	importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/xxxxx.groovy",
    installOnOpen:  true,
	oauth: 			false,
    iconUrl:        "",
    iconX2Url:      ""
) 

preferences {
   page name: "mainPage"
   page name: "deviceCharacteristics"
   page name: "dumper"
   page name: "Tesla"
}
def installed() {
//	log.trace "installed()"
    state?.isInstalled = true
    initialize()
}

def updated(){
//	log.trace "updated()"
    if(!state?.isInstalled) { state?.isInstalled = true }
	if(debugEnable) runIn(1800,logsOff)
}

def initialize(){
}

void logsOff(){
     app.updateSetting("debugEnable",[value:"false",type:"bool"])
}

def mainPage(){
    dynamicPage (name: "mainPage", title: "", install: true, uninstall: true) {
      	if (app.getInstallationState() == 'COMPLETE') {   
	    	section("Main")
		    {
                input "qryDevice", "capability.*", title: "Devices of Interest:", multiple: false, required: true, submitOnChange: true
                if (qryDevice != null) {
                    input "stateStr", "string", title:"Current State to Remove", submitOnChange: true
                    if (stateStr != null)
                        input "removeState", "button", title: "Remove"
                }
                input "debugEnabled", "bool", title: "Debug?"
                if(state?.btnPush) {
                    qryDevice.deleteCurrentState("$stateStr")
                    state.btnPush = false
                }
		    }         

	    } else {
		    section("") {
			    paragraph title: "Click Done", "Please click Done to install app before continuing"
		    }
	    }
    }
}

def appButtonHandler(btn) {
    switch(btn) {
          case "removeState":
            state.btnPush = true
            break
          default: 
              log.error "Undefined button $btn pushed"
              break
      }
}
1 Like

Thank you, but I am hoping to remove Event history, not State variables.

@Baz2473 used some terms (attributes, events, etc) that lead me to believe he found a method to do that.

Currently on my mobile so here’s the best I can do for you.

Create the command so a new button appears in the driver.

Use that button to call the function.

I have 2.

deleteAllStates = deletes all stored states and atomicStates

&

delectAllCurrentStates = deletes all current states in the event / attribute side. They will then repopulate as and when they get sent again.

A few screenshots for ya.

2 Likes