[RELEASE] Switch Bindings 2.0

Switch Bindings 2.0 Release!

Today I release Version 2.0! This is a major overhaul with some great new features. (Thank you for the suggestions!)

  • Toggles to let you choose which attributes/events to sync
  • Syncing of Held/Released events on dimmers and switches. For example, it can start ramping the other dimmers up/down as soon as you hold the paddle on another dimmer. You don't have to wait for the Level attribute to update at the end.
  • Now can sync Hue, Saturation, and Color Temperature
  • Includes a fix specifically for supporting Hue smart bulbs
  • Miscellaneous bug fixes
  • Refactored code for cleanliness and readability
  • Full unit test suite, to ensure quality control while adding new features.

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

The best way to install this code is by using Hubitat Package Manager.

However, if you need to install manually:

  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"
24 Likes

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

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

1 Like

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...

Yes, this is bi-directional.

1 Like

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

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.

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).

1 Like

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.

1 Like

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.

1 Like

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

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.

3 Likes

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.

1 Like

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?

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.

5 Likes

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

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

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

1 Like

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

1 Like

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.)

1 Like