Alexa Helper - Change mode or phrase with a switch toggle

There is a new version available that uses a Parent/Child structure. Search the forums for the official Re-Release of Alexa Helper

All,

Here is a variation on my “Switch changes mode/phrase” app published by SmartThings. Right now, this is just a re-packaged version of the app that was approved about a month ago…just with an Echo/Alexa icon and wording; however, I plan to expand on this app later.

This app allows you to trigger a mode change or execute a Hello, Home Phrase with the toggling of a switch. For example, if you create a virtual switch called “good night”, and tie that within the app to a “good night” phrase that locks the doors, turns off all of the lights and sets the temperature, simply saying “Alexa, turn on Good Night” would activate that phrase, doing multiple actions and things the Alexa could not do before (like lock the door).

There are multiple ways to create a virtual switch within the IDE, so I won’t go into that here; however, you can also designate a physical switch as the ‘master’ switch as well.

Enjoy!

https://github.com/MichaelStruck/SmartThings/blob/master/Other-SmartApps/AlexaHelper/Alexa%20Helper.groovy

8 Likes

Great work, thanks for jumping in on this! :sunglasses: I’ll give it a try when I have someone to help with the cut and paste.

Does this work with virtual momentary switches as well as binaries?

Binary switch is like a regular light switch. Stays on until flipped off, stays off until flipped on.

A momentary switch is like a doorbell button. It is off most of the time. When you activate it, it turns on for just a moment, and then returns to the off state.

They fit different use cases. Sometimes a binary switch is better, sometimes a momentary switch is better. :bulb:

1 Like

I am testing it now…chose a ZWave Virtual momentary, but that didn’t work. One of the things I may do it is actually create an action within the app for any virtual switch to be momentary. So, you could define whether the switch is in a normally open or normally close state, and when it ‘toggles’ it would switch back to that state within a certain amount of time.

Will post my results later today.

edit…I do see the app registering a ‘push’ command to the switch but no action seemed to occur. When you mention a momentary switch, which one are YOU referring to in the device list?

I use the device type “momentary button tile” for Echo integration, think it’s the simplest of the virtual momentary switches. But I still use some binary switches as well, mostly so I can say “Alexa, turn off the TV.”

From the coding standpoint, your app is going to still just subscribe to the “on” event for a momentary switch. The switch is going to throw an on followed by an immediate off. But as long as you don’t subscribe to the “off” and just subscribe to the “on” it should be the same as a binary switch like “simulated switch” being turned on.

You just have to make sure that you’re not requiring the person to specify an action for the “off.” Because every “on” on a momentary switch is going to be followed by a “off,” but it’s the on that the person wants the system to respond to.

Yeah…this was put together from my other app, but I may add a section for JUST momentary buttons, and regular switches.

Edit-The momentary switch DOES work. I will update the in-app instructions to differentiate that to the more novice users and start thinking of other options this app can have. If anyone has ideas, just let me know…I love my Alexa!

Edit 2-On…the app is updated. The plans for the next version will include multiple slots for different switches to do different actions (i.e. Good morning, good night, etc). Right now I am planning for 4 slots, and each one will have a toggle to remove the off action should you designate the switch as a momentary tile. No ETA yet for this app…maybe one week? Stay tuned

3 Likes

All,

I have the basic framework completed on the app. Currently here are its features…I am open to suggestions as I am testing it this week and plan to release it by the end of the week. Anything that can make it better I am open to!!

  • 4 slots to designate different scenarios
  • Within each scenario, you chose a name, a switch, whether the switch is momentary, and the actions to occur when the switch is on or off
  • The scenarios can have different restrictions. This was put in so you could have one switch (let’s say “good night”) perform different phrases or modes depending on the day, time, or the current mode the home is in.

While I could put in fancy things such as light switches, door locks, etc, those items can be performed with the Phrases, so unless there is an overwhelming demand, I will leave those out.

I really wish Alexa could give voice feedback; for example, if you perform "good night’ and the garage door is open, have it say something “Hey…the garage is open”. This IS possible to do with a Sonos speaker, but now you have to have two specialized devices to perform this function. Again, if there is a huge demand for voice feedback (through the Sonos) I can do it, but am hoping Alexa can do it eventually. And, the Sonos TextToSpeech function is currently broken, so I would have no way to test this at the moment.

Again, any suggestions on what I have so far will be welcome. Otherwise, this is the release feature set scheduled for next weekend.

Wow, great work! I’m sure a lot of people will use this once it’s out. :tada:

Just want to check on a couple of things…

So we could set up four virtual switches with the app, and then we would have to install a new instance of the app to do more than that? Because right now my echo has like 27 virtual switches. :stuck_out_tongue_winking_eye: (Once you start adding TV channel favorites, it adds up fast.) and I know a lot of people have more than four modes.

You can set up 4 different scenarios with 4 different switches, or like in my case, 4 scenarios with 2 different switches depending on the day/time/mode restriction. You can add multiple instances of the app, but let me see how many ‘slots’ I can add to this app before it gets too unwieldy to manage from a programming standpoint.

Stand by…

edit: Ok…not too bad to add more slots…at 600 lines of code so far…wouldn’t want to get more than a thousand as I have seen large apps slow down execution. Outside of JD (who I could create a special version for) what is the sweet spot of controls?

2 Likes

A by-the-book Device with Capability Momentary only has to provide a push() Command, and thus many SmartApps won’t be able to do anything with it, as most SmartApps (including Alexa) only support on() / off(). Of course a Device Handler can also be written to also have Capability Switch and do something “reasonable” when sent on/off, but it’s technically a kludge.

That is the preferred model in SmartThings; i.e., SmartApps should do one event with various conditions, instead of several things… The latter is a Hello Home Routine.

It’s not so much for execution efficiency, but for simplicity… The best way to observe this is looking at the way Shortcut Solution SmartApps are handled (i.e., the user is presented with a list of scenarios to apply to a single Light Shortcut (which could be a group of bulbs) and then they fill in the config with time and mode restrictions and trigger devices that apply to that Shortcut and nothing else. Next Shortcut = new SmartApp instance.

Inferring the philosophy, since this guideline is not documented.

But in this case we’re choosing a virtual switch type to use with Alexa, so we can choose whichever type we want. And “momentary button tile” issues the on followed by the off.

The simulated switch approach has stopped working for me and fails to trigger “goodnight” hello home action via Echo. So, Alexa, turn on Night mode has now started failing.

Understood…not that I agree with the ‘only one thing per app’ philosophy. We do run into execution time as we increase lines of code, but at the same time, I would fill out 2 or 3 pages of apps just to do what a few of them do now. Bottom line, as you said, unless it is hard code limited I like to have one app that has a bit more dynamic possibilities instead of the same app multiple times.

Good discussion, however…I am sure everyone has their point of view on this.

1 Like

Just now it stopped working? Just tested mine and it still works…

I don’t think it’s your code failing or the echo but the hues failing to turn on and off as well as polling and the status in dashboard. I have serious doubts that even the v2 will be able to handle hue integration unless they fix the integration. I guess what we have in v1 (horrible integration) will be the same behavior we will see in v2. This was working well for a day or two…

@MichaelS your superb code works as echo understands it perfectly fine but the hue integration fails as it fails to turn off the bulbs via the goodnight hello home.

1 Like

Ron,

Thanks…sorry for the issues you are having; here’s to hoping ST can fix the integration a bit better…I live in Seattle and work just up the street from Amazon, so very little in technology impresses me or shows long term potential. However. I see the Echo being one such item and hope that it isn’t dropped as a technology and is expanded to be more interactive and useful.

I control my Hue bridge through Echo, not through smartthings anymore. Just can’t keep integration going.

You can do this:

One) in echo, create a group called “good night”

Two) put the Hue bulbs that you want to turn off in that group. These bulbs should be associated with a hue bridge, but not identified to echo as smart devices.

Three) also put the virtual switch from smart things in that group that you want to use to turn on the mode good night. Or that you want to run a good night hello home action. Just associate it in reverse so that when the switch goes off, The action runs.

One of the nice things about echo is that you can set up groups however you want to, you could have the same device in multiple groups, and you can mix-and-match devices from multiple controllers in one group.

So let Echo tell the hues to turn off, and let SmartThings handle everything else. :sunglasses:

2 Likes

Fill follow your directions!

You may have to experiment a little bit to get the combination the way you want with the voice commands you want. You may even end up with two groups and two voice commands, one for the Hues and one for Smartthings. You know:

“Alexa, turn All Lights off.”
“Alexa, turn Goodnight Mode on”

Just depends what feels natural to you.

All,

I have used this app for a couple days, and while I will call it beta at this point, I am releasing it so you all can test and give feedback. As mentioned, here are the features:

  • 4 slots to designate different scenarios
  • Within each scenario, you chose a name, a switch, whether the switch
    is momentary, and the actions to occur when the switch is on or off
  • The scenarios can have different restrictions. This was put in so you
    could have one switch (let’s say “good night”) perform different
    phrases or modes depending on the day, time, or the current mode the
    home is in.

Let me know what your experience is with this. Right now, I have 3 slots set up in my app…two to turn off lights when I go do bed (weekdays it sets the Asleep mode, weekends it sets the Asleep, Sleep in mode). The other is the morning mode, which I tied to one of the groups in Alexa so it not only does a phrase change, but turns on lights within the house that are separate from the phrase. Hope that makes sense.

If everyone likes this, I will submit it to be published.