Button for Custom Device Type Handler—help needed

I just installed TriggerCMD a week or so ago and its pretty cool. The only issue i have is that the devices all show up as switches, when i want them to be buttons. The app works with my PC, so whenever the switch is toggled it runs the script. Im using it for spotify control right now, so it looks like 4 playlists and 2 speakers are on, when its just 1 playlist going. if i turn the switch off, though, it sends the command again, which starts that playlist.

Ive got the raw code, but i cant figure out how to change the device type from a switch to a button. Ive looked at some of the docs on the developer pages, i see information about the buttons but ive edited the code and i cant figure out how to change it to a functional button.

Link to the raw code on github:
https://raw.githubusercontent.com/rvmey/SmartThingsPublic/MSA-2199-2/devicetypes/vandermeyconsulting/triggercmd-switch.src/triggercmd-switch.groovy

Ive tried changing parts of the code, but i dont really know what im doing, so it doesnt work.

Ive changed the metadata:

metadata {
definition (name: “TRIGGERcmd -modified button”, namespace: “vandermeyconsulting”, author: “Russell VanderMey”) {
capability “Button”

	command "pushed"
	command "held"
}

and the tiles:

tiles {
	standardTile("button", "device.button", width: 2, height: 2, canChangeIcon: true) {
		state "on", label:'${name}', action:"button.pushed", icon:"st.buttons.button.pressed", backgroundColor:"#79b821", nextState:"off"
		state "off", label:'${name}', action:"button.off", icon:"st.buttons.button.off", backgroundColor:"#ffffff", nextState:"on"
	}
	
	standardTile("refresh", "device.button", inactiveLabel: false, decoration: "flat") {
		state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
	}
	
	main(["button"])
	details(["button", "refresh" ])

when i changed the device type of one of the devices, it changes the icon in the ST app on the left side from a plug to a button, but the indicator icon on the right still shows ON/OFF.

i have no idea where to go from here. I feel like im probably on the right track but i might be completely in the wrong place. Can anyone help me with this?

Have you tried looking at the device type handlers for some of the devices which are treated as buttons? It may be something as simple as missing the appropriate “capability.”

(If you don’t know what a “capability” is and how they are used in smartthings, you should read the developer docs on writing device type handlers. There is a link to the docs at the top right of the first page of this forum.)

You can find quite a few of the DTHs for devices of this device class by looking on the quick browse lists in the community – created wiki in the device type handler section on the list for “remotes and buttons.“

http://thingsthataresmart.wiki/index.php?title=How_to_Quick_Browse_the_Community-Created_SmartApps_Forum_Section

Because I rely on text to speech, I can’t read your actual code (or anybody else’s) but I will note that any button also needs to have the number of buttons field populated or it won’t be able to be used with other smart apps, Including webcore. So look for examples of that in the DTHs as well. :sunglasses:

Ive looked at a couple but im still not getting the syntax right, apparently. Ill dig into some of the examples to see if i can pull what i need from there.

1 Like

You don’t want Capability “Button”. That Capability is a confusing one and really, that causes way too many mistakes… A “Button” (per this Capability definition) is a Sensor, not an Actuator. A Button Control senses when someone is pushing it. A Device of Capability “Button” is not an Actuator and thus has NO Commands!

You want to use Capability “Momentary”.

https://smartthings.developer.samsung.com/develop/api-ref/capabilities.html#Momentary

3 Likes

OK, cool. Thanks terry. Ill mess around with it later, but i guess i just change the attributes from switches to momentary, using the syntax in that link?

That’s probably a good starting point.

If you get stuck, it’s usually best to share the whole code (via a GitHub gist or repo) so anyone who pitches in can see the problem in context and even paste it into their own IDE for debugging.

1 Like

Good Day Do you have a SmartThings Device Hang]dler for ROUTINES ?
Thanks