Live Code Fridays 8/7/2015 8pm EST / 5pm PST

Join Patrick Stuart once again, where he will be live coding SmartApps and DeviceTypes in the IDE using SmartThings. This episode will be broadcast from the new Stuarttech Studios. Special Guests may join throughout the session. Use the comments section on the Youtube page to ask any questions.

If you would like to be part of the broadcast, please send me a private message. We may try to put in a hangouts session into our new livestream studio, or try the remote interview feature (requires chrome browser only, using RTC)

This week, we will tackle improving an existing deviceType and maybe some other topics.

If you want me to code something specific, please don’t hesitate to ask.

You can find past recordings on my website



I’d like to see how to have a group of switches but only one switch within that group can be on at any time.

That’s very doable @Keo and it would be a great thing to code live because it should be fairly straightforward.

@pstuart do you plan on talking about github integration at all?

@Keo I think we can tackle that.

@jodyalbritton I think I’ll try to set up github integration by following the documentation. I think a good git demo is in order.

Maybe we can push up the code for the group of switches but only one switch can be on at any time SmartApp and DeviceType.

This might be a bit trickier then it appears.

I don’t believe most of the physical zwave and zigbee switches can be separated from the load, so if a switch is on, the load will be carried to the bulb or outlet.

Easy to do with virtual switches, but the best I could do is that if one switch is on, then any attempt to turn on another switch would then turn it off, or the others off?

Maybe @Keo can expand on how he wants this to work a bit to see if it is possible.

Yeah this would not work for a z-wave 3-leg setup. But for three independent devices it should be easy enough.

Turn one on and the others off, yes.

If one is on and another turns on, what should happen? Turn first one off or not allow the 2nd to turn on until 1st is turned off?

Lots of iterations to think about, plus what should be the default initialization state? Turn all off at start or update of smartapp?

I would like to have only one switch on at a time. So in a set of 3 switches:
Switch 1: on, Switch 2: off, Switch 3: off
If Switch 2 turns on:
Switch 1: off, Switch 2: on, Switch 3: off

if Switch 3 turns on:
Switch 1: off, Switch 2: off, Switch 3: on

Initial state: I guess all off is fine, However, if there are switches on and the app is reloaded is there anyway to maintain the current state?

Also, what type of switch are you using? Some don’t report instant status back to st so there could be a delay.

So if I preserve initial state of all or some on, what should happen if on is turned off or on, should it then use the programming logic?

If someone turns all three on close to the same time what should happen?

A singularity? I had the same question. A more likely possibility is two people hitting a switch at the same time. I think you might want to build a certain amount of delay into the mechanism. This would allow for checks on each switch. And you could randomize the delay a bit to keep switches from stepping on each other. Whatever switch is pressed needs to pause and check the other two switches, then turn the one that is on - off.

Simple pseudo code.

if all the switches that are not me are off 
   turn me on 
  random delay 
   which switch is on
   turn that switch off
   turn me on

GE Z-WAVE Switch. I don’t know the model

I’m not sure what you mean here. If you mean you preserve the state when the app is reloaded, yes, it should use the app logic.

I see what you’re saying here. I’d be entirely fine with having one switch be a priority switch. This way if multiple switches were turned on at the same time, the priority switch would take precedence over all of the others. Does that make sense?

Sounds good. I think I get the concept…

Define a priority switch, this will be switch one.

Define other switches 1-X

On start or update of smartApp, if any switches are on, keep them on.

On state change of any subscribed to switch.on, turn all other switches off.

Bonus points if we check for all subscribed switches against priority switch. If priority switch was turned on and another switch was turned on since last event, keep priority switch on and turn others off.

Does that solve the issues?

Now we just need a name for this SmartApp… I’m thinking something like, “No Light for You.”

thats about it

How about Aether - I believe he’s the Greek god of atmosphere and light. Lol

One last thing. Can we postpone this one until next week? My wife is going out and I’ll be watching a 9 week old and a 4 year old. Chances are I won’t be able to focus on the call.

Sure. No problems. Always looking for ideas for later shows. Will do it next week.

Unfortunately, I have work tomorrow and will not be in attendance :frowning:.

Here’s an idea for a future project, not sure if possible:
Merge the device type of a motion detector and a presence sensor. If motion is detected, it will emulate a presence sensor. Essentially a room presence detector.