Oh man you are going back in time. I agree, the send event signaling the switch is on even though it may not be, is not a good practice. If I recall correctly, I don’t think I was getting the acknowledgement back from the relay for both switches so I couldn’t parse it and instead of troubleshooting the problem I just left it as is.
Here is what I think is the correct way to do this: My CoopBoss custom device type, has two buttons that turn on and off relays connected to the Aux port on the CoopBoss CPU. When you push the button it changes to “Sent” state, the button truns orange and says Sent. Here is what the tiles look like.
standardTile("aux1", "device.Aux1", width: 2, height: 2, canChangeIcon: true) {
state "off", label:'Aux 1', action:"Aux1On", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"Sent"
state "on", label:'Aux 1', action:"Aux1Off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"Sent"
state "Sent", label: 'wait', icon: "st.motion.motion.active", backgroundColor: "#ffa81e"
}
standardTile("aux2", "device.Aux2", width: 2, height: 2, canChangeIcon: true) {
state "off", label:'Aux 2', action:"Aux2On", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"Sent"
state "on", label:'Aux 2', action:"Aux2Off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"Sent"
state "Sent", label: 'wait', icon: "st.motion.motion.active", backgroundColor: "#ffa81e"
}
As you can see aux1 calls a method called Aux1On to send the on command. Here is the method:
def Aux1On(){
log.debug "Sending Aux1 = on command"
"st cmd 0x${device.deviceNetworkId} 0x38 0x0101 0x14 {}"
}
Short and sweet. Now to change the button tile from the “Sent” state to the “on” state I wait for the CoopBoss to send back an acknowledgement for the on command. Here is that bit from my parse method:
if (cluster.clusterId == 0x0101 && cluster.command == 0x0b) { // This is a default response to a command sent to cluster 0x0101 door control
//log.debug "Default Response Data = $cluster.data"
switch(cluster.data) {
case "[20, 0]": // 0x14 Aux1 On command verified
log.info "verified Aux1 On"
sendEvent(name: "switch", value: "on", displayed: false)
resultMap.name = "Aux1"
resultMap.value = "on"
break
So now the buttons (tiles) always represent the true status of the switches. It looks like your thinking about doing the same thing in your code (keying on the acknowledgement). I think that is the right thing to do! A device should not send an acknowledgment of a command unless that command was actually carried out.