Anyone write code to create a virtual device that uses a in-wall switch module and smart bulb into 1 virtual device?

devicetype
smartapp
hubv2

(Joshua Rountree) #1

All my light switches have in-wall relay modules for the switches, but instead of swapping them with dimmer modules, I’d love to be able to place a smart bulb like the Sengrel ones with dimmable capabilities, and then group them into a virtual device that Toggles and Dims. The dim control would go to the bulb, the switch would do the toggling.

It would need code to ensure the switch is on before calling the dim settings, but I think this sounds feasible.

Has anyone done this or know of a quick way to get it going?

I’m a developer, and am familiar with Python and many other languages and don’t mind writing this, but if there is something I can use as a template to get started I’d love to have a good jumping off point.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

In this particular case, where you have a specific Device Type of Switch and a specific Device Type of Bulb, I would be tempted to literally combine the DTH code into one DTH.

You would not be able to get automatic selection of this DTH using signature/fingerprint (as there are two different device fingerprints), but you would manually override the assigned DTH using the IDE / My Devices page.

  • By just mixing and matching the code of the two DTHs, you eliminate the requirement for a SmartApp to keep a “Virtual DTH” in sync both both Devices.
  • You lose various bits of flexibility (such as mixing and matching device types), in exchange for simplicity of implementation of your idea.

(Alan) #3

I’m no expert, but it doesn’t seem ideal to cut power to your dimmer bulbs. I’d imagine there would be latency before they come online to be controlled from the hub. Or maybe the hub is able to queue these commands? That would be slick, but don’t know if that works.

One thing you could do is make it so your light switches don’t physically control any circuit. To do this, you’d have to unhook the Load wire from your in-wall switches and cap it to make sure there’s no risk of it shorting to Line. Then, you’d use automation like Smart Lighting with the switches as the trigger.

EDIT: I made a mistake in my recommendation. You want the circuit to be powered at all times, regardless of the state of the switch. So what you’d want to do (with power from the breaker cut, and confirmed to be off with a multimeter) is tie the Line and Load wires together in the switch box, along with a wire to the Line input of your smart switch. Leave the Load input of the smart switch empty. This way, both the switch and your circuit have full-time power, and the switch physically controls nothing.


(Ron Talley) #4

What @acjohnson55 said and maybe try this for grouping.


(Dave Gutheinz) #5

First, I agree. It will not work as a single app unless you can build a delay between “on” and “brightness”. After the switch turns on, the bulb will have to be reacquired by the z-wave, zigbee, LAN, or WAN. This can take seconds, not milliseconds.

Most cost effective option is to buy the smart bulb and control it while leaving the switch on. The cost of a new switch and a non-smart dimming bulb is probably higher than the smart bulb itself. Put in an electrician, even higher.


(Alan) #6

Sounds like the OP already has smart switches. Although, now that you mention it, my original advice wasn’t quite right. I just updated that comment with the corrected idea.


(Joshua Rountree) #7

Actually, these Sengled bulbs are only $8.99 right now on Amazon.
And they remember their dim state when power is cut and are instantly connected when they come back on.


(Joshua Rountree) #8

Thank you so much for your response.

Do you happen to have an example of the code? or do I literally just take both of them, and merge the two files together ignoring similar lines.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #9

No… It’s not quite that simple. You’d have to cut and paste the desired Tiles and methods (Commands), and Attributes, and add a few logic statements here and there to keep everything in sync.


As mentioned above, it is not ideal to use the mains power switch to control the light for several reasons. There’s nothing wrong with exploring the idea, hacking, and experimenting; but in such a case, it’s best you spend a little time with the SmartThings Developer documentation so you can an idea of the pieces that compose a Device Type Handler so you can truly grasp what is going on, and tune and tweak it until you get the desired behavior.


(Joshua Rountree) #10

I may go with your technique. Although more advanced, I wired the in-wall modules myself so I can definitely get them wired in the fashion you mentioned here and just control them remotely. The thing that attracted me to the in-wall switches, however, is if the modules fail, smartthings fails, etc. then the light still comes on.

I guess I’m just trying to get the best of both worlds without fully committing but maybe my reservations aren’t warranted.


(Alan) #11

Fair point on failover. In my house, I don’t exactly have this setup anywhere. All the lights I’m controlling are in lamps, not fixtures. So I could use the switches on the lamps if my automation is failing.

Of course, the bad side of this is that guests who don’t know any better are always toggling my lamp switches!