For the past few months I’ve been thinking about how nice it would be to adjust the Sonos-TV volume with Alexa. The specific use case is actually when I’m in the kitchen cooking and want to turn the TV volume up/down/whatever without having to rinse my hands, dry them off, and reach for a remote. I searched in the forums a couple times and didn’t see any case-specific SmartApps, but happened to notice Ask Alexa has this capacity. If nothing else, at least it would be a fun exercise in AWS.
Anyway, I set it up and as-if-it-was-magic, now I could say “Alexa, ask SmartThings to set Living Room Sonos volume to 35” and it worked! After experimenting for a while, I found the utterance was just too danged long. So, I shortened “SmartThings” to a monosyllabic name and “Living Room Sonos” to “TV,” but still found “ask …to set … volume to XX” to be a bit clunky.
With a nod to the folks over in this thread:
I decided to write a purpose-built app to do the job more simply. The idea is to:
- Create a virtual dimmer in the IDE.
- Install the SmartApp and configure it to tie your speaker to the virtual dimmer
- Add the virtual dimmer in Alexa’s list of discovered devices and name it something simple.
Now, I’m controlling the TV volume with “Alexa, set TV to 35.” Yes, I managed to save myself a few syllables, but more importantly, the Alexa integration is more streamlined; the same voice commands control lighting levels and speaker volume.
If you don’t already have a virtual dimmer device type, I’ve been using Michael Struck’s version:
The code itself is ridiculously simple for a SmartApp, but given that I wasn’t able to easily find speaker volume control via Alexa, I thought my virtual dimmer approach might be worth sharing with the community. Hope this helps some folks out there!
/**
* Dimmer-Sonos Bridge
*
* Copyright 2016 Jesse Silverberg
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Dimmer-Sonos Bridge",
namespace: "JLS",
author: "Jesse Silverberg",
description: "Bridge a virtual dimmer to a Sonos for Alexa volume control.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
preferences {
section("Bridge this dimmer...") {
input "myDimmer", "capability.switchLevel", multiple: false, title: "Choose virtual dimmer", required: true
}
section("...to this speaker") {
input "mySpeaker", "capability.musicPlayer", title: "Choose Speaker(s)", multiple: true, required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe(myDimmer, "level", setNewVolume)
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe(myDimmer, "level", setNewVolume)
}
def setNewVolume(evt) {
log.debug "in handler with: ${evt.value}"
def newVolume = myDimmer.currentState("level").integerValue
mySpeaker.setLevel(newVolume)
}