Can we extend "device." attributes

What I was trying to do was very simple:
To have two switches that would turn on/off two led lights. But I’ve recently got to know that it’s currently not possible to have multiple switches in one device. Then I found out that the work around for this problem is to have separate virtual devices and somehow use them through a smart app(to be honest I have no idea what’s really going on). So I’ve found someone who actually has done something similar and took a look at his code. But there’s one thing that makes me crazy. Please see the code below taken from this link.

standardTile("relay1", "device.relay1", canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "RelayOff1", icon: "st.switches.switch.on", backgroundColor: "#79b821",  nextState:"switching"
    state "off", label: '${name}', action: "RelayOn1", icon: "st.switches.switch.off", backgroundColor: "#ffffff",  nextState:"switching"
    state "switching", label: '${name}', action: "RelayOff1", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
    
}
standardTile("relay2", "device.relay2", canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "RelayOff2", icon: "st.switches.switch.on", backgroundColor: "#79b821",  nextState:"switching"
	state "off", label: '${name}', action: "RelayOn2", icon: "st.switches.switch.off", backgroundColor: "#ffffff",  nextState:"switching"
    state "switching", label: '${name}', action: "RelayOff2", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}

Now what is that “device.relay1” and “device.relay2”? Where do they come from? There’s nothing called relay1 or relay2 in the list of possible values. I’d very much appreciate if someone would explain this in detail.

1 Like

Not to be unhelpful, but let me know if the Documentation helps (the docs are steadily improving, thanks to @Jim), and the Community can help fill in the blanks in the meantime.

This page describes the standardTile (etc.) methods to some degree…

http://docs.smartthings.com/en/latest/device-type-developers-guide/index.html

Believe me I’ve chewed the documentation many times, but couldn’t find anything that would help me understand how any attribute else than the ones listed is recognized by the code.

1 Like

OK… Regarding the currently sparse Documentation, many of us just slog through lots and lots of code examples to try to figure things out for now. But we try to be a helpful bunch of folks in the Community and shorten that process, so your question is very welcome here…

I can give some quick answers, and/or you can Private Message me – I’ve done several little Skype screen share sessions to explain things and answer questions as they come up during a one-one demo.


In the example you link, I think a few things are worth noting:

  • The metadata{} section doesn’t declare any extended (“ad hoc”) Attributes, though it does declare extended Commands. I think this is just a style problem (i.e., the Platform doesn’t currently verify that all Attributes are declared).

  • Regardless, there are event creation events that effectively create these Attributes on the fly… See “relay2”, “relay3”, etc.,

...
    if (value == "relayon2") {
	   	createEvent (name:"relay2", value:"on", isStateChange:true)
    } else
    if (value == "relayoff2") {
	   	createEvent (name:"relay2", value:"off", isStateChange:true)
    } else 
    if (value == "relayon3") {
	   	createEvent (name:"relay3", value:"on", isStateChange:true)
    } else
...

Does this take us a step closer to figuring it out?

1 Like

Umm, yeah, it does. So, just a final quick question. Did you understand the code in the link? What goes where and stuff…

It’s hard to be sure I understand it correctly without having any comments or description as to what the device is supposed to do, and without having the device to test with. I don’t believe in excess comments, but there an overall description along with a few comments for the methods are always helpful.

If there is a section of code that isn’t clear, we can discuss our assumption of their purpose and see if we agree … and/or test that assumption with some debugging, tweaking, etc…

The device handler guide is in the process of a rewrite, and is currently in the review process.

That doesn’t help much now, I know. Here’s some of the updates to the tiles documentation that may be helpful (these are in review as mentioned, so aren’t necessarily final): https://github.com/SmartThingsCommunity/Documentation/blob/update-device-type-guide/device-type-developers-guide/tiles-metadata.rst

1 Like