Help with Tiles

I have a 6-zone audio amplifier at home that accepts serial command. So, I bought a ThingShield and am struggling with reverse-engineering examples, trial-and-error, etc. to cobble together a device type I can use to turn the zones on/off, select sources, and volume up/down.

So right now, I’m trying to make a tile that turns green when a zone is on, and gray when off - just like the standard switch tile. I have the following code:

standardTile("zone1", "device.switch", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "z1off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	state "off", label: '${name}', action: "z1on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}

when i press the tile in the phone, it executes the z1on command as expected, but the state of the tile doesn’t change to green nor does it send the z1off command on next press. Can anyone see what I am doing incorrectly here?

Also, I am so confused about in the examples for a switch tile, the action is “switch.on” and “switch.off” which only calls an “on” method. I guess in general I’m confused about commands vs. attributes vs. capability…

The tile state is controlled by events, not actions. That tile decides which state to show by looking up the most recent event of attribute “switch”.

The SmartPower outlet sends us a state update after we change it and we turn that into a “switch on” event. The Z-Wave switches don’t, so we send a state request after the on or off command, then the response to that creates the event.

If there isn’t an on/off response from your device, it may be possible to create the event in the action. It’s not usually done – I’d have to look it up.

There is also the “nextState” option for tiles. We use this to change the dimmer tile to “turning on” immediately because it takes a while for the response to come back.

standardTile("zone1", "device.switch", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "z1off", nextState: "off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	state "off", label: '${name}', action: "z1on", nextState: "on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}

The problem with this is that it is just a local thing on the app. If you leave the app and come back, it might be in the wrong state.

Thanks @duncan. Let me just make sure I understand how to do this. So, want to track the on/off state of a “zone” in my Audio Controller… So, I would:

  1. When I create my device type, I would specify a custom attribute called, say, “zone1_pwr”

  2. I create a tile like so:

standardTile("zone1", "device.zone1_pwr", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "z1off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	state "off", label: '${name}', action: "z1on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
  1. my z1off() and z1on() would send the ‘on’ or ‘off’ command to the ThingShield

  2. my thingshield code would reply with a message, say “zone_1_on”

  3. in my parse() method, I return a Map with name: zone1_pwr and value: on

Do I have that right?

and bonus question: Does that mean, if from a smart app I can turn the zone on and off with device.z1on() and device.z1off()?

Sorry for the basic questions, trying to learn.

Yeah, that looks like it will work to me. I must admit, though, I’m still sometimes wrong about how SmartApps and device types work since the system still has some quirks and I mostly work on the firmware side.

PS. sorry I tried to respond last night but this stupid forum software thinks my home ip is a spambot

Yep, got this working now… is there a list of tile types? I would love to have a tile that takes input - Ideally you press it and it lets you select from some number of choices.