Skip to content

Instantly share code, notes, and snippets.

@nayelyzarazua-bluetrail
Last active February 16, 2021 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nayelyzarazua-bluetrail/adb6cfc9c89b7f87dc58cdd925f6bd87 to your computer and use it in GitHub Desktop.
Save nayelyzarazua-bluetrail/adb6cfc9c89b7f87dc58cdd925f6bd87 to your computer and use it in GitHub Desktop.
CompositeDevice_MultiSwitch
/*
* 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')
}
/*
* ---------------------------------------------------------------------------------
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