A Satisfying Solution for Philips Hue Scenes, SmartThings, and the Amazon Echo

project_lighting
project_voice

#1

Here follows a tale of blood and sweat and tears… and ultimately - sweet, sweet triumph that made it all worthwhile.

[I’m going link to this post from a few places where I asked for advice over the past few weeks, so that anyone researching those threads discovers the solution that worked, at least, for me. **And if you don’t want to read the step by step story, the quick solution is: Hue (Re)Connect** (and probably Hue Lights & Groups & Scenes (OH MY!) but I didn’t test it) **and a special “stateless” momentary button tile device type and super simple smartapp developed by** @Sticks18 ]

While there are many other things I want to start digging into now, the primary reason I first bought SmartThings was to bridge access between my Amazon Echo and the scenes I created with Philips Hue. Not only to bridge the two, but to do so elegantly (by which I mean, when I changed from one scene to another, I wanted the lights to respond immediately, simultaneously, and reliably).

I ran into two major hurdles… First, the immediate, simultaneous, and reliable requirements. Part of the problem is that I have 40+ Hue bulbs, and I have many scenes that incorporate most or all of them. The other part of the problem is that few of those bulbs share the same settings (color/saturation/level) with any others in the scene. It’s not that I have gaudy color configurations with reds and blues and purples and greens; it’s that the lamp on the bookshelf gives a more pleasing light when set at a slightly warmer color temperature than the lamp on the table, or that the lamp in the corner gives a nice splash of color while others do the heavy lifting of lighting the room.

When you have a scene that requires that many settings, most SmartApps fail to make the switches reliably. More than 50% of the time, a bulb or two would not change at all, or else would change partially but not completely. That may be fine for some, but it’s eminently frustrating to me, as it mars the beauty of the house lighting that I worked diligently to create. So, Smart Lighting was out, and while Rule Machine is absolutely exceptional at so many things, this wasn’t one of them.

And this is where I give a shout out to the incredible helpfulness of the community. So many people worked with me, and had recommendations for me, and took the time to help me when I grew confused. First of all, @MichaelS wrote a stripped down app that was my first go at things; it was based off of a lighting app he wrote, but I asked for his help with something bare bones. This ran into the same reliability problems (which I think have to be due to either the ST hub or the Hue Bridge trying to process so many commands at once).

Next, it was @Fuzzyligic, @SBDOBRESCU, and @bamarayne who pointed me toward Hue (Re)Connect. Some had issues with it in the past, but others said it had worked nigh flawlessly for them, and with a large number of Hue bulbs. So I gave it a shot, and I am thankful that I did! (During installation, I realized that the directions for installing it and using it could be much better… I got confused a few times. Now that I’ve done it, if anyone is looking into it and gets lost like I did, just let me know and I’ll share what I learned.)

Hue (Re)Connect makes the transition from one scene to another absolutely flawlessly. Thus far, I think I’ve had 1 missed bulb in some 100 or so scene changes. And beyond that, all the bulbs change at once, and it happens without any lag or latency. It’s just been a glorious experience.

The app saves each scene as a momentary button tile, which in my opinion, is ideal. And it just left bridging the gap from Amazon Echo to these various devices.

Now, I could have shared the devices directly with Alexa. And then I could say, “Alexa, turn on the ambient lights.” But I wanted the functionality of being able to have an “On” and an “Off” option for each phrase. And direct linking to a momentary button tile wasn’t going to give me that option.

I also could have used a simulated switch, but this raised another problem. If I turned Scene A on, later turned on Scene B, and finally wished to return to Scene A again (or alternatively, if I turned Scene A on, someone used the physical light switch, and I wished to turn Scene A on once more), a simulated switch wouldn’t allow me to do that, as it would continue to read Scene A’s state as having remained On the entire time. Thus, I’d issue the command to my Echo, “Alexa, turn on Scene A,” she would respond with, “Okay,” but nothing would happen.

The solution came by way of @Sticks18 who created a “stateless” switch device type, sort of a hybrid between a momentary button tile and a simulated switch, and a simple SmartApp that would allow that device to have two actions linked to it, one for On and one for Off. No matter whether I just turned Scene A on 5 seconds before, I can issue the command to do so, and Alexa sends the command. It doesn’t check for what state the switch is in. The same is true with Off commands.

Finally, for my lights that aren’t Hue bulbs, I used that program that @MichaelS wrote to tie them to momentary button tiles as well, and then use those tiles in @Sticks18’s program just like the Hue scenes. I group them in in Amazon Echo’s app, so that a single command calls that group name, and they all function seamlessly.

And now, I have a beautifully functioning system. It’s lightning fast and incredibly reliable. Not only that, but it’s built to be simple. Which, to my mind at least, means there are fewer points of possible failure. I don’t have to rely on polling the lights to see what their status is already, or on delays to mark switches’ states as off or on. It just works.

I’m thankful to everyone who helped me discover it, and I hope that this may help anyone else who’s in the same boat that I was.


Brand new and requesting help with an idea for Philips Hue lighting "scenes"
Philips Hue, Scenes, and SmartThings - A request to the community
[RELEASE] Alexa Helper
#2

Great stuff! I’m a recent Vera 3 --> ST convert and have been struggling with my hue lighting scenes - particularly since every hue bulb is also on a z-wave physical switch. I don’t have 40+ bulbs, but do have nearly 20 and have been stumbling around unsuccessfully for a sanitary and reliable solution Cant wait to try this one out.


(Scott G) #3

Thanks for the shout out! Linked below is the Github repo for this solution. It has a pretty narrow focus, but essentially it allows for triggering separate scenes for an on or off command and is stateless; so you can always trigger either one. The best use cases are for 3rd party integrations like Echo or Harmony to gain additional functionality from a single virtual button.

For instance, in Sebastian’s case, he has scenes in Hue for both Turning On a room and Turning Off that room. Each would have its own momentary button tile to trigger from the Hue (Re)Connect SmartApp. With this solution, he can link the Turning On to the On action in my stateless switch and the Turning Off to the Off, then link the stateless button with Echo.

Another good use that I plan to use is for the Harmony Home Control remote. With only 4 HA buttons, it limits the number of scenes you can activate, but the remote supports short and long press actions to turn a switch on and off, respectively. I tried using this at one point with virtual switches, but the states would cause issues with it firing correctly. With this, I can have a short vs long press each trigger a particular scene and not worry about switch states, just what lighting I want at the time.

It’s pretty narrowly defined at this time, in that it only triggers momentary buttons; but if users find uses for it, then I will be happy to expand it. If you’re using it with Echo, I also highly encourage you to check out the Alexa Helper SmartApp and it’s upcoming enhancements. They may solve the same issue with more robust options and flexibility.

The Stateless Repo (3 items. Parent and Child SmartApp, plus the special Momentary Button devicetype. You will currently need to manually create the momentary buttons after loading the devicetype. I plan to convert it to a child device created dynamically by the app in the future if it gains traction.)

@MichaelS great SmartApp for Echo control


(Cyril Peponnet) #4

Feel free to enhance the Readme :smile:


(Cyril Peponnet) #5

This will work now I added the on/off as well. (and the off is really working if you take the time to understand the trick).


#6

I’ll be happy to update it with what little I know. :slight_smile: Thanks Cyril!


(Jonathan David) #7

@Sticks18 I’m very eager to try this out, but is ‘Momentary-to-Trigger-OnOff-Scenes.groovy’ specifically made for Echo or can I use this as a normal toggle switch? What I plan to do is assign my hue scenes to an Enerwave SC7 scene controller, and I want each button to be an on/off toggle switch.

I previously planned using a hue dimmer switch (purely for the on/off function), but it’s obviously limited to controlling 1 scene only. What I want is a hue tap functionality, so the Enerwave SC7 is perfect if I can assign an on/off toggle to each of it’s 7 buttons.


(Scott G) #8

It’s not made specifically for Echo (I use it with Harmony), but it won’t work in a toggle situation. The special momentary button will always be in an off state, so a typical toggle functionality will always try to turn it on. It’s intended to be used where the controlling mechanism can initiate a discrete on or off based on what the user intends regardless of what the last command was.

You could use it to get 3 on/off scenes with the SC7, by linking the row pairs to on and off, respectively. That way the left button will always turn on a scene and the right will always turn it off. Then use the big 7th button as a wildcard All Off scene or something. But you can do that without this solution too.

If you want each of the 7 buttons to be able to turn a scene on and off in a toggle fashion, I think you’ll need a custom button controller SmartApp because I imagine you’ll want to keep track of which scene(s) are on/off and trigger the correct action on a button press.


(Jonathan David) #9

I just installed your app, so do you mean you should only assign the same action to ‘Trigger this scene tile if master momentary is turned on/off’ inputs - either the same 2 on states or the same 2 off states?


(Scott G) #10

Not typically. The app is designed to have a different scene tile for each one of the on/off inputs and ideally you’d have the scene ‘on’ tile as the ‘on’ input and the scene ‘off’ tile as the ‘off’ input.

But what would be your ideal world? You have 7 buttons. How many scenes do you want to control? Do you want to be able to trigger those scenes on and off?


(Jonathan David) #11

On that, so do you mean if I create a master momentary switch and assign it with your app, and also assign an on scene and an off scene within that same instance of the app, that the master momentary switch will toggle between the on scene and off scene alternately?


(Scott G) #12

Not really. The master momentary tile isn’t meant to be toggled like that. It’s meant to be triggered by another SmartApp that would call either the on or off command. If the on command is called, then my SnartApp will trigger the scene tile set as the ‘on’ input and vice verse if off is called.


(Jonathan David) #13

Can you clarify? So how is your app meant to behave if I assign 2 scenes to it - I mean, how will assigning 1 master momentary button trigger each of the 2 scenes assigned?


(Scott G) #14

Do you follow the Echo example?

Master momentary named: Movie Scene
"On" input momentary tile: Movie On
"Off" input momentary tile: Movie Off

“Alexa, turn on Movie Scene” - result is Movie Scene button is sent an on() command causing Movie On to be triggered.

“Alexa, turn off Movie Scene” - result is Movie Scene button is sent an off() command causing Movie Off to be triggered.


#15

hey sticks, i’m trying to get this to work, but when trying to save the child app i get this error in the IDE:

startup failed: script14587528741871194595512.groovy: 6: expecting ‘)’, found ‘description’ @ line 6, column 1. description: “Use a stateless momentary to allow voice commands to avoid sync issues”, ^ 1 error

basically what i’m tying to do with this is be able to tell alexa “turn on everything” that will run your stateless momentary button, which triggers my ‘all lights on’ routine via alexa helper … and then “turn off everything” that will run my ‘all lights off’ routine via alexa helper.

i created the device type using your code and made a device, then added the parent app (saved, published for me), then trying to add the child app gives me that error.

am i on the right track with being able to make this do what i want? thanks so much!


#16

looks like it was just missing a comma… now to see if i can get this working the way i want…


(Scott G) #17

I just went to check and saw a pull request for that exact typo. Fixed on Git now too.

You should be able to use this to do what you’re looking. Also, I think Alexa Helper added this type of stateless switch feature directly, so you might not need my code. It’s been a while since I checked in on Alexa Helper, but @MichaelS might be able to help.


(Micheal ) #18

Correct…I have what I call an “Alexa Switch” that sends dimmer and on/off commands regardless of the state of the virtual switch. At the end of the day, it ends up being a passthrough to the devices you are attempting to control.

Information about this switch is here: http://thingsthataresmart.wiki/index.php?title=Alexa_Helper#Virtual_Switch_Setup


(John) #19

@Sticks18 @MichaelS

While Alexa Helper does have the Alexa Switch, will it work with Hue Scenes? My understanding is the Alexa Switch will send the On/Off command regardless of the state, however, @Scott’s switch allows you to map On and Off to different scenes. Therefore, if you’re relying on Phillips Hue Scene control, you would still need Scotts’s device type, correct?


#20

ok i got sticks code working, but when i say ‘turn off Test’ nothing happens and alexa just swirls blue. if i put the virtual switch Test in a group and say turn off Test it works, but alexa says ‘that command doesnt work with this device’ but it works anyhow…

for Alexa Switch, should i make it be a momentary switch or virtual switch? if it’s a virtual switch, the state will get confused and if the lights are on that i want to turn off, but the virtual switch is off, then alexa wont do anything because it thinks they are already off. that’s why i was trying to use Sticks’ code.