Last active
February 16, 2021 15:10
-
-
Save nayelyzarazua-bluetrail/adb6cfc9c89b7f87dc58cdd925f6bd87 to your computer and use it in GitHub Desktop.
CompositeDevice_MultiSwitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* VIRTUAL SWITCH - CHILD DEVICE OF multipleSwitchDev | |
*/ | |
metadata | |
{ | |
definition( name: 'Virtual Switch', namespace: 'nayelyz', author: 'Nayely',deviceTypeId:'Switch',ocfDeviceType:'oic.d.switch', mnmn: 'SmartThingsCommunity', vid: '30ad6f88-acb3-3e11-8186-5b7f804b0c71' ) | |
{ | |
capability 'Switch' | |
capability 'Health Check' | |
} | |
preferences | |
{ | |
// No preferences are actually needed. | |
} | |
} | |
// installed() is called when the device is created, and when the device is updated in the IDE. | |
def installed() | |
{ | |
sendEvent( name: "DeviceWatch-Enroll", value: [protocol: "cloud", scheme:"untracked"].encodeAsJson(), displayed: false ) | |
sendEvent( name: 'switch',value: 'on') | |
} | |
def updated() | |
{ | |
} | |
def on(){ | |
sendEvent( name: 'switch', value: 'on') | |
} | |
def off(){ | |
sendEvent( name: 'switch', value: 'off') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* --------------------------------------------------------------------------------- | |
Multi-Component Device | |
* --------------------------------------------------------------------------------- | |
*/ | |
metadata | |
{ | |
definition( name: 'multipleSwitchDev', namespace: 'nayelyz', author: 'Nayely', mcdSync: true,deviceTypeId:'Switch',ocfDeviceType:'oic.d.switch', mnmn: 'SmartThingsCommunity', vid: 'ddbc558e-b968-3745-898a-077f18dd54c3' ) | |
{ | |
capability 'Switch' | |
capability 'Health Check' | |
} | |
preferences | |
{ | |
// No preferences are actually needed. | |
} | |
} | |
def on(){ | |
sendEvent( name: 'switch', value: 'on') | |
} | |
def off(){ | |
sendEvent( name: 'switch', value: 'off') | |
} | |
def installed() | |
{ | |
sendEvent( name: 'DeviceWatch-Enroll', value: [ protocol: 'cloud', scheme: 'untracked' ].encodeAsJson(), displayed: false ) | |
sendEvent( name: 'switch', value: 'on') | |
initChildComponents() | |
} | |
def updated() | |
{ | |
initChildComponents() | |
} | |
def initChildComponents(){ | |
// Child component handler | |
def switches = [ s1: 'Switch1', s2: 'Switch2', s3: 'Switch3' ] | |
if ( ! childDevices ) switches.each | |
{ | |
shortform, longform -> | |
// Probably ought to check for existing child devices. | |
def child = addChildDevice( 'Virtual Switch', "${device.deviceNetworkId}:${shortform}", device.hubId, | |
[ isComponent: true, completedSetup: true, label: "${device.displayName} ${longform}", componentName: shortform, componentLabel: longform ] ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment