[RELEASE] Virtual / Physical Switch Sync


(Eric M) #1

Update (2016-09-10): I have created a new SmartApp that is an upgraded version of this one. It will create the virtual switches for you among some other things. Since it is significantly different from this app, I couldn’t just upgrade this one as it would cause problems. I definitely recommend using the new app with any new dual relays you may install, but if you are currently using this one, there is no big reason to switch over. Here is a link to the new app:

This is a small app to keep Physical and Virtual Switches in sync. Specifically for use with devices such as the Monoprice, Enerwave, Fibaro, and Philio Dual Relays. As well as the Aeon SmartStrip. For best results change your virtual device handler to a Simulated Switch. If your device supports energy reporting like the Philio PAN04 or the Aeon SmartStrip, use my Simulated Energy Switch device type below to have the individual switches report power and energy usage.

Edit 2016-04-05: I have modified the app to get rid of all the clutter in the device notifications. To take advantage, make sure you use the Simulated Energy Switch listed above for energy switches and the Simulated Switch below for normal switches.

On the left is the before and on the right is after:


[RELEASE] Aeon SmartStrip Device Handler
How to automate second relay on ZWN-RSM2S
Create alias to dual-relay switch?
PowerNode plug (GreenWave) to power trigg?
[RELEASE] Enerwave ZWN-RSM2 (v1 & v2) & RSM2-Plus —Smart Dual Relay Switch Module
[RELEASE] Virtual Device Sync - Create Virtual Devices and Keep Them In Sync With a Physical Device
[RELEASE] Aeon DSC17103 Micro Double Switch
Philio PAN04 Dual Relay Device Type
[RELEASE] Enerwave ZWN-RSM2 (v1 & v2) & RSM2-Plus —Smart Dual Relay Switch Module
Question about connecting 12 volt LED lights
[RELEASE] zooZ Power Strip ZEN20
(Gil) #2

Hi @erocm1231,
I’m not sure I understand, correct me if I’m wrong, to my understanding your app is for syncing a number of switches with a specific switch.

What is the different between your app to SmartThings Labs app “Smart Lights”? or just the use of “rule machine” to trigger a number of virtual switches when a physical switch is turned on?

Gil :slight_smile:


(Eric M) #3

This app is only intended to be used with devices that have multiple switch endpoints.

The SmartThings system in general is not yet capable of handling switches with multiple endpoints. Apps like Smart Lighting and really any other standard SmartThings app cannot turn on/off the 2nd/3rd/4th switch of devices like a dual relay or an Aeon SmartStrip. Standard apps also cannot subscribe to the events generated by those switches.

Can rule machine accomplish what this app does? Honestly, I don’t know. I am not really a fan/user of rule machine. Can rule machine subscribe to events from a 2nd/3rd/4th switch on a multiple switch device? Can it use sendEvent(device, Map event) to trigger an update of the virtual switch without actually triggering the switch or leaving static in the switch’s event feed?

It probably can’t or would require some serious configuration. If I am hanging a some sheet rock, I can certainly use my multi-tool to screw in the drywall screws, but I would much rather use a power drill. :wink:


#4

Hello, could you please add bit more explanation what each setting is?
Eg is my assumption correct that “Which Physical Switch” is the switch with two channels, and “Virtual Switch to link to Switch N” is a physical switch what will control channel N on “Which Physical Switch”?

Why are Philips Hue bulbs listed as switches?

Here’s what I’d like to achieve:
I have a two channel relay and I have a Philips Hue switch.
I’d like channel 1 on relay to be switched on when I switch on the Hue switch.


(Eric M) #5

This app has a very specific purpose. You create virtual switches in the IDE and assign them the “Simulated Switch” device type listed in this thread. Then, with this SmartApp, you can “sync” those virtual switches with each corresponding switch on the physical switch. This gets around the limitation of SmartThings that makes it so you cannot control the 2nd, 3rd, 4th, etc. switch from SmartApps. You can add the created virtual switch to automatons and the status of the virtual switch will match the status of the physical switch if you toggle it from the wall.

The Philips Hue bulbs are listed as switches because they have the “switch” capability.

I don’t believe you can achieve what you are trying to do with this app. It isn’t the purpose it was intended for.


(Dale C) #6

Thanks for getting this done for the new switch v2. I just got mine in and loaded up the device handler.

Can I make a suggestion, the name of the device driver is the same as the existing one by SmartThings and I can see some potential confusion. I ended up renaming yours to “Simulated Switch erocm123” to make sure I knew which one to pick in the drop down list


(JZst) #7

It’s been like 2 months since you recommended this solution on some other thread. I just wanted to come back here and thank you. It’s been rock solid and better than stock ST and the manufacturer’s wanna-be ST device handler. Your SmartApp and Device Handler has yet to fail me in any way, turning on/off and reporting accurate status every single time. Friggin awesome and much appreciated!


(Eric) #8

Hey @erocm1231 - I’ve been trying to upgrade my SmartStrip setup to use your code so I can get the power readings tied into the virtual devices, but one thing is hanging on me… I’m using your SmartStrip DH, your Simulated Energy Switch DH from above, and the Switch Sync code from above. I’m not getting any energy readings on the simulated energy switches, and whenever I tap the button, I get an error in the logs. I do get the energy readings in the SmartStrip device. The switch seems to be commanding properly to the right state, but the physical feedback is hanging with the following error:

  • groovy.lang.MissingMethodException: No signature of method: script#####.isChildMessage() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:switch, value:on, type:physical, isStateChange:true, …]]
  • Caught error: Likely caused by not using my specialized Simulated Switches
  • physicalHandler called with event: name:switch4 source:DEVICE value:on isStateChange: true isPhysical: false isDigital: false data: null device: Discus Aeon SmartStrip

Any ideas where to look? Thanks!


(Eric M) #9

I am trying to replicate the problem by trying a few things, but it looks like logging is messed up in my account on the IDE. I sent support a request and waiting to hear back.

I have set up several instances of this app (even one today with the new zooZ Power Strip) and haven’t seen this issue. The physicalHandler is called when the switch is controlled at the wall (or at the strip) or from the actual device (not the virtual devices). It then sends an event in behalf of the Simulated Energy Switch so that its state changes from on to off.

I would just double check that your virtual switches are using the Simulated Energy Switch. Also, since I haven’t seen this one, try again today just to rule out any platform issues that may have been popping up at the time.


(Eric) #10

Hey Eric,

Thanks for helping… I’ve been studying your code and I can’t find anything - it’s all clean. The only thing I can think of is that something is stuck in the backend since I had this physical device using a different device handler before. There’s no “clean build” function in the IDE. I did delete the virtual switches and recreate them without any change, but stopped short of dumping the physical switch since that involves monkey work with the network.

I’ll continue hammering on it from my end. I did validate that I’m using all three pieces of your code:
Simulated Energy Switch
Virtual / Physical Switch Sync
Aeon SmartStrip
I also added your credentials to the end of the names of each so they’re obviously the right ones just by glancing at the tables.

It looks like I actually have two issues going on. The first is the obvious error I’m getting in response to the physical switch changing. The second is that the callbacks for the energy and power are simply not happening. Nowhere in the logs do I see “powerHandler called with event…” or “energyHandler called with event…”, though I do see the power and energy events showing up on the smartstrip DH, and I’m getting those values reflected in the app.

I’ll keep banging. Thanks again for your help.


(Eric) #11

I just backed out the parse map calls back to the onPhysical/offPhysical calls from pre-4/5. That made the errors I’m seeing in the logs go away. I wonder if those calls are no longer supported?

Still no luck on the energy/power though… those handlers are simply not getting called.


(Eric M) #12

Does the simulated energy switch that you have installed have this method? Long shot, but maybe you have an older version . . .

> def parse(Map description) {
> 	//def pair = description.split(":")
> 	//createEvent(name: pair[0].trim(), value: pair[1].trim())
>     def eventMap
>     if (description.type == null) eventMap = [name:"$description.name", value:"$description.value"]
>     else eventMap = [name:"$description.name", value:"$description.value", type:"$description.type"]
>     createEvent(eventMap)
> }

(Eric) #13

Yep, it has that method…


(Eric M) #14

I did some more looking and I am still kind of crippled with the SmartThings IDE not showing errors, but the only way that I can get the SmartApp to break is to change the virtual device Device handler to something other than the Simulated switches I have listed here. The error message you first posted is stating that that is what is going on as well. I’ve installed the app a few times since you posted and my current installed instances of it are still working. It really sounds like you know what you are doing though, so I don’t know what to say.


(Eric) #15

OK well thanks anyway for looking into it for me. I’m still hitting a wall on this end, but I think I’m going to move on to other things at this point. The debugging ability is just too sparse to waste much more time on.

I did get the physical switches working with the map function finally, by specifically naming the passed variables in the smart app, i.e.

sendEvent(Device:settings["virtual${i}"], Map:[name:"switch", value:"$evt.value", type:"physical"])

instead of…

sendEvent(settings["virtual${i}"], [name:"switch", value:"$evt.value", type:"physical"])

The same thing did not work for the power/energy - I’m not getting any errors, but I’m also not getting those values set. I also added some logs to the def parse(Map description) in the simulated energy switch, and it’s just not getting called. Anyways - thanks for your help!


(Mike Rolle) #16

First, I have to say “thank you”! I appreciate all the work you must have put into this. I’d also like to add a suggestion. A simple, step by step process to making this work for those that haven’t done it before. I’ve spent hours just reading post after post, trying to get to the answer. Then when I found an apparent answer, I could not decipher how to get it done. I’m pretty computer literate, including a bit of coding, but I am unfamiliar with this process.
A good step by step might be something like this:
1 - Connect the switch and get it included in the network.
2 - Follow this link to the device handler code, in the upper right, click “raw” to remove extraneous characters.
3 - Select all and copy the code
4 - log into your Samsung account and select the "My Device Handlers"
5 - Click "add new handler"
6 - Click "from code"
7 - Paste the code you copied in step 3
8 - Click "create"
9 - Click “publish” and "for me"
10 - Follow this link to the smart app code, in the upper right, click “raw” to remove extraneous characters.
11 - Select all and copy the code
12 - Go back to your Samsung account and select "My Smart Apps"
13 - and so on and so on

I’ll even write it up and post it if I can ever get everything working. I think it may help many people to get the job done quickly.

Thanks again though, it must have taken some time to get it all figured out.


(Eric M) #17

Just an FYI, there is a great resource on the forums for those new to the SmartThings community:

Also, as mentioned at the very top of this thread, there is an updated version of this app that makes things quite a bit simpler:


(Mike Rolle) #18

Thanks for your reply. It actually helped. My issue was probably related to having read for so long on the topic and trying a couple different versions of things (which had me create the simulated switch) before arriving at your latest release (which I had installed) where I missed your “simulated switch” handler. I saw the energy switch and the dimmer. Anyway, it appears to be working now.

Thanks again!


(MICHAEL MCGLYNN) #19

Sometimes, when I try to turn on one of the two lights attached to this relay, the relay chatters, the light flickers then stays off. When I try the next time it works. If I use the switch that controls both, they go on and off together flawlessly. If I have the one light on and try to turn it off occasionally it will also chatter the relay, flicker the light then stay on. This lasts about three seconds in either scenario. Would this be a relay problem or an issue in the app or device handler? I can live with it but it is a bit annoying.


#20

I’m having the same issue with relay chatter on the second circuit. A few details:

1 - Some “physical” switches have shown up in the event log during this issue, and I don’t have the aux wires hooked up for a switch so I assumed maybe some noise got on those aux lines and make the relay toggle (I had the aux lines floating). Because they are switched to “line” (hot) with the switch (when you have one hooked up) I tied both aux lines to hot, assuming this would fix my problem. It did not, still have the issue. One “physical” switch did show up still…but those aux lines are definitely tied to line (see log below)

2 - It seems to work the first time after changing things (power on/off etc…), so you think you fixed it…but did not!

3 - Did you get yours working? Please note I just received this enerwave switch from Amazon a few days ago…

Log from second virtual switch (relay chattered way more than listed):
2017-01-07 9:56:00.177 AM EST
16 minutes ago
DEVICE switch off
2017-01-07 9:55:54.490 AM EST
16 minutes ago
DEVICE switch on
2017-01-07 9:55:05.912 AM EST
17 minutes ago
DEVICE switch off
2017-01-07 9:54:57.926 AM EST
17 minutes ago
DEVICE physical switch on
2017-01-07 9:54:56.383 AM EST
17 minutes ago
DEVICE switch off
2017-01-07 9:54:51.533 AM EST
17 minutes ago
DEVICE switch on
2017-01-07 9:54:45.569 AM EST
17 minutes ago
DEVICE switch off
2017-01-07 9:54:38.130 AM EST
17 minutes ago
DEVICE switch on
2017-01-07 9:54:35.297 AM EST
17 minutes ago
DEVICE switch off
2017-01-07 9:54:27.085 AM EST
17 minutes ago
DEVICE switch on
2017-01-07 9:52:35.911 AM EST
19 minutes ago
DEVICE switch off
2017-01-07 9:52:27.803 AM EST
19 minutes ago
DEVICE switch on