Seeking Advice: Same capability (Switch) needed twice in a single driver (Meural Canvas II Device Driver)

I am continuing work on my Meural Canvas II driver and I have a need to have two switches within the single driver. One switch turns the Canvas on / off (actually puts it to sleep). The other switch stops and starts a slideshow. The driver works just fine. I have on /off and slideshowOn/ slideshowOff at present. The difficulty occurs when I go to add the Canvas to a Hubitat OOB dashboard. The template for Switch works well for the on / off but the slideshow switch does not as it is a custom command. There are ways to work around this of course, such a virtual switches and rules, but I want my driver to be easy to use for a non-technical user.

Is there a way in code to expose a command twice? That is, two on / offs in a single driver that would both respond to the standard OOB dashboard switch template. My coding experience tells me No. A command / function can be overloaded but it would require a different parameter signature.

Would it be a best practice to build two separate drivers that would be used for a single physical device? In others words, one driver that handles the on / off sleep functionality of the Canvas and another separate driver that handles the slideshowOn / slideshowOff switch? I hesitate to implement this approach as it would mean two driver setups for the user and that seems a bit cumbersome.

Suggestions please :slight_smile:

Thank you - Norbert

No, a single device can only implement a single capability once--i.e., you can only have one on() and off() command, as you note.

To get what you want, I might suggest a parent/child device. You can either have a parent that is little more than a "container," then two child devices for each function (the "main" device and the sleep thing); or you can put the bulk of the driver in the parent driver, perhaps your existing driver, and then move the sleep on/off functionality to a child device you (optionally?) create for this specific purpose. I'd probably do the latter, but I don't know much about your device, and it's mostly just a matter of preference.

You don't necessarily need to create a separate driver for this. Hubitat has a built-in "Generic Component Switch" driver you could use if you do the second option I mentioned. (This driver implements the Switch capability with on() and off() methods, which, when run, call componentOn() or componentOff() in the parent driver, passing the child device as a parameter.) You can see a generic example by looking at Hubitat's example drivers repo:

Specifically, look at the HubitatPublic/genericComponentParentDemo.groovy at master · hubitat/HubitatPublic · GitHub file. This appears to demonstrate a child dimmer, but your case (with just a switch) would be a bit simpler, and there's no need to implement the "//demo custom commands" things if you don't want to, just the "//child device methods" (these are what the child calls on the parent when child commands are executed).

1 Like

The slideshow on/off is more like a toggle button? Is there a HE capability for that? If not, a contact sensor can be used or just make up your own command 'Slideshow'. Or all of the above.

1 Like

The above post made me think: you could also implement a different capability for one of these functions, like PushableButton, then do something like have push(1) start and push(2) stop, or perhaps push(1) (or push anything if you have no use for other buttons) toggle start/stop. This is perhaps not as intuitive, but this is a standard capability that the Button template on Dashboard would also let you use. (The MusicPlayer capability is probably overkill but might also work; the play() and pause() commands would be of particular interest, but then there's probably more you might not have a good way to actually implement...but, agian, I don't know this device.)

1 Like