[RELEASE] Switch Bindings

community_app

#1

https://github.com/joelwetzel/Hubitat-Switch-Bindings

Switch Bindings app for Hubitat

An app for Hubitat that binds two (or more) switches/dimmers together. When bound, if either one turns on or off, the binding will make the other one also turn on/off. It will also sync dimmer levels, if any of the devices are dimmers. (It works a lot like a z-wave association, but it happens in the Hubitat hub, so that the hub can know/display the updated device states. Because the Hubitat is local, the binding can happen effectively as fast as z-wave messages can travel.)

Examples of Usage

  • Suppose you have a smart wall switch in your living room that controls the overhead can lights. Now you add a lamp in the room, and you either put a smart bulb in it, or plug it into a smart outlet. (In either case, the controls aren't super accessible.) You can use this app to bind the wall switch and the lamp together, so that all your lights will always turn on and off together. They will stay synced whether you control them using the wall switch, an app, or Alexa or Google Home.
  • 3-way and 4-way lighting controlled by software, not wiring in the walls
  • Sync a fan and a light switch
  • Sync levels across a roomful of dimmers
  • With a 5 button scene controller keypad. My driver exposes the buttons/lights as virtual switches. By using Switch Bindings alongside this, it becomes easy to keep lights synced with the scene controller. See my keypad driver here: https://github.com/joelwetzel/Hubitat-Cooper-Aspire-Scene-Controller

Installation

  1. On the Hubitat hub, go to the "Apps Code" page
  2. Click "+ New App"
  3. Copy in the contents of SwitchBindings.groovy
  4. Click "Save"
  5. Click "+ New App" again
  6. Copy in the contents of SwitchBindingInstance.groovy
  7. Click "Save"
  8. Go to the "Apps" page
  9. Click "Add User App"
  10. Click on Switch Bindings
  11. Click "Done"
  12. Click on Switch Bindings in your apps list
  13. Click on "Add a new binding"
  14. Choose your switches to bind
  15. Click "Done"

3-Way Switch Control
Fan Speed Capability as a Condition/Trigger
Question about grouping switches
Community Apps
Gate Controller
[RELEASE] Dimmer Sync
#2

Does this bind dimming levels as well or only switch state?


#3

Right now, only switch state, not dimming levels. That would be an interesting next step in its development though.


#4

Thanks!, interested in dimming too, also, is this bi-directional?

@Cobra has an app for this too but is unidirectional. I believe when using Z-Wave Plus devices that report physical vs digital state changes it should be possible to do bi-directional sync...


#5

Yes, this is bi-directional.


#6

My Dimmer Sync app does dimmers (on/off and level), but it is intentionally unidirectional (master/slave[s]).


#7

What?!? I'm so confused. What difference does it make if it's z-wave plus or not? It's just syncing two devices with each other. Won't matter what type they are or how they changed, at least from my understanding.


#8

Looking at this code, it needs to know how long it takes for the follower switch to turn on/off and return status - so that state changes are ignored during that period.

Since non-plus devices don't report instant status, you would have to make sure the response time setting is long enough for the non-plus device to report back its status (presumably via polling).


#9

I don't actually have any non-plus devices, so my switches report back very quickly. But I have two dimmer plugs that behave "interestingly". One of them reports its new status right when it starts to dim to it. The other one only reports its new status after it has finished dimming - which could be 3-5 seconds.

So imagine this:

  • I turn on Switch1
  • The binding turns on Switch2 (which is actually this dimmer)
  • After 3 seconds, Switch2 reports its new status

So, should the binding try to do anything on Switch1? It won't hurt switch1 to try to turn it on, since it's already on. The hub won't even send out any z-wave messages to it. BUT... what if you had turned Switch1 off in that time? For example, you turn it on and instantly realize it was the wrong light and you want it off. Then we definitely don't want Switch2's late report to go back and force Switch1 back on again.

That's what the time tracking is for. But it's not a setting you'd need to fiddle with unless all of these were true:

  • One of the switches is slow to report its status back
  • and you regularly physically toggle BOTH switches, one right after the other (which is hard to imagine wanting to do)

Basically the timer just makes the first switch that you interact with into a quasi-"master" for a couple seconds.


#10

There's definitely a lot of ways this could be extended to cover more use cases, and more capabilities than just 'switch'. I don't know if I'll be the one to develop those extensions though. Right now I've optimized it for "simple, reliable, and fast" for just the purpose of bi-directionally linking two switches.

My own use case is to use a Cooper Aspire 5-button Scene Controller to control several lamps in my living room. I used to be on SmartThings, and used webCORE to make it work, but it wasn't simple, it wasn't reliable, and it really was not fast (since everything went out and back to SmartThings servers several times). But now that I'm able to have my code run directly on the Hubitat and stay local, my button controller and lamps are super fast. It's a night-and-day difference.


#11

What does this get you that the built-in Groups and Scenes app doesnt already?


#12

Unless I'm misunderstanding its functionality, Groups and Scenes creates a virtual button that you can press to turn on/off a bunch of stuff at once.

But in my case, I have a button controller on the wall that I want to bind to a floor lamp. With my switch bindings, I can:

  • Push the button on the wall, and the lamp will come on.
  • Say "Alexa, turn on the floor lamp", then when the floor lamp turns on, the indicator light on my button controller will also turn on.
  • And if I have other scenes running on timers (such as turning off all the lights at night), then the indicator lights on my button controller will stay synced with the actual state of the house.

The important part is that it doesn't matter whether physical or virtual events cause one or the other to change. No matter what, they stay synced.


#13

That is what I was thinking. Groups/Scenes does this and dimming PLUS zwave and Zigbee device grouped together. It sure the value proposition here.


#14

This app should work with zigbee. I mention zwave because that's what I have, but there's nothing in the app that's zwave specific. It will work with anything with capability 'switch'.

You say groups/scenes does this? Does it do the bi-directional part?


#15

Ok, I just tested and Groups and Scenes does not perform the same thing I'm doing here. Definitely has its own great uses. But it creates virtual devices, and then on/off commands on the virtual devices are sent out (uni-directionally) to the selected devices in the group or scene.

What I'm doing here is binding two existing devices (physical or virtual, doesn't matter) and bi-directionally syncing them.


#16

Very cool... +1 on the dimming feature. That would be awesome.


#17

Great app! I use a few different ways to operate lights, this keeps them nicely in sync!
Many thanks! :+1:


#18

Update:

In the first version, a binding could only bind two switches together. With this update, each binding can include an arbitrary number of switches. Do 3-way and 4-way lighting via software.

If you've already installed it, you'll need to re-copy in the two groovy files. I'm not sure if you can do that while leaving existing bindings in place. They may stop working. For this reason, I've tried to make it very fast to configure the bindings.

Get it here:

https://github.com/joelwetzel/Hubitat-Switch-Bindings


#19

Imported both, and re-assigned the switches and lights, working a real treat!! Many thanks for the app, I think its great!


#20

New update: Fixed some bugs. Only SwitchBindingInstance.groovy had updates.

(This is one thing I miss from SmartThings. Github integration. Wish it didn't create so much work for users every time I need to make an update.)