Hi,
I’m trying to integrate a device which is a lighting Relay Switch who can control 2 lighting.
I would like to have only one display with either 2 buttons which manage the 2 endpoints or an On / Off button and a toggle which juggles between the lights.
For the moment, my code look like this. But the second button takes the action of 1. I don’t understand. Could someone help me?
/*
* Copyright 2019 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
metadata {
definition(name: "Zigbee ON/OFF Lighting Relay Switch", namespace: "SmartThings", author: "NodOn", ocfDeviceType: "oic.d.smartplug", mnmn: "SmartThings", vid: "generic-switch-power") {
capability "Actuator"
capability "Configuration"
capability "Refresh"
capability "Health Check"
capability "Switch"
command "on2"
command "off2"
tiles(scale: 2) {
multiAttributeTile("switch1", "device.switch1", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
attributeState "light1 ON", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#00A0DC", nextState: "turningOff"
attributeState "light1 OFF", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn"
attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#00A0DC", nextState: "turningOff"
attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn"
}
tileAttribute("switch1", "device.switch1", key: "SECONDARY_CONTROL") {
attributeState "light2 ON", label: '${name}', action: "off2", icon: "st.switches.switch.on", backgroundColor: "#00A0DC", nextState: "turningOff"
attributeState "light2 OFF", label: '${name}', action: "on2", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
attributeState "turningOn", label: '${name}', action: "off2", icon: "st.switches.switch.on", backgroundColor: "#00A0DC", nextState: "turningOff"
attributeState "turningOff", label: '${name}', action: "on2", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
}
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label: "", action: "refresh.refresh", icon: "st.secondary.refresh"
}
main "switch"
details(["switch", "refresh"])
}
}
// Parse incoming device messages to generate events
def parse(String description) {
log.debug "description is $description"
def event = zigbee.getEvent(description)
if (event) {
sendEvent(event)
}
else {
log.warn "DID NOT PARSE MESSAGE for description : $description"
log.debug zigbee.parseDescriptionAsMap(description)
}
}
//def off() {
//zigbee.off()
//}
//def on() {
//zigbee.on()
//}
def on() {
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
}
def off() {
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
}
def on2() {
"st cmd 0x${device.deviceNetworkId} 2 6 1 {}"
}
def off2() {
"st cmd 0x${device.deviceNetworkId} 2 6 0 {}"
}
/**
* PING is used by Device-Watch in attempt to reach the Device
* */
def ping() {
return refresh()
}
def refresh() {
zigbee.onOffRefresh() + zigbee.onOffConfig()
}
def configure() {
// Device-Watch allows 2 check-in misses from device + ping (plus 2 min lag time)
sendEvent(name: "checkInterval", value: 2 * 10 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
log.debug "Configuring Reporting and Bindings."
zigbee.onOffRefresh() + zigbee.onOffConfig()
}