currentValue not working for playbackType

Hi,

Strange issue when porting over a working app from ST, I have a custom musicPlayer device type, which has an attribute of "playbackType" which is being reflected in the current states screen for the device, but can't seem to get the value by code?.

There is then a field in my app called playerDT, with multiple set to false:
input(name: "playerDT", type: "capability.musicPlayer", title: "Media Player Device", multiple: false, required:false)

However both of these generate 'null':

log.debug playerDT.currentValue("playbackType")
log.debug playerDT.currentplaybackType

I'm sure it's something really basic, pussting in "state" returns the expected play state, so it's finding the device, any ideas?

Driver Code Below:

metadata {
	definition (name: "Plex Communicator Device", namespace: "jebbett", author: "jebbett") {
	capability "Music Player"
    command "playbackType", ["string"]
	}
}

// External
def playbackType(type) {
	sendEvent(name: "playbackType", value: type);
    log.debug "Playback type set as $type"
}

def setPlayStatus(type){
    sendEvent(name: "status", value: "$type")
	log.debug "Status set to $type"
}

def play() {	        
    sendEvent(name: "status", value: "playing");
}

def pause() {
    sendEvent(name: "status", value: "paused");
}

def stop() {
    sendEvent(name: "status", value: "stopped");    
}

Not sure if this is your issue but I initially had issues retrieving currentStates when the attribute was explicitly defined.

Try adding this above you command definition:
attribute "playbackType", "string"

1 Like

You might also need to set an initial value when the driver is installed. If the above doesn't work, also add an installed() method with a sendEvent for the playbackType attribute.

1 Like

Thank you @stephack !!! This solved my problem!

1 Like