[NEEDS UPDATING] Assistant Relay V3.3 Beta

No worries, I appreciate your time and effort. I updated my DTH code with the original preferences.

One thing that had me confused in setting up the DTH was the entry of a specific device IP or name in the Name for the Default device. Since I have 3 mini’s and 1 display I wasn’t sure what to put in this field. Do I need a separate smartthings device for each speaker? So I tested one without ANY value in the Default device since I was calling the device in Webcore in the cast content parameter and it worked perfectly. So I’m not sure that that field is necessary.

Again thanks for the work to make this driver.

What is the settings for establishing a set volume for the announcement? I have added the the “set device volume” and two string parameters, the volume level number and then another string parameter for the device, I’ve also listed the device first and then the volume level but I am unable to change the volume level. The mute and unmute commands work fine.
Any suggestions for the proper format to change the volume in the piston?

@Danabw I wouldn’t beat yourself up about it at all, it’s not your fault but the lack of clear instructions!

1 Like

@Alwas - Thanks, appreciate it. I ended up w/out any bruises. :wink:

1 Like

@smartxray - I tried the volume setting as an interger value before and after the device identifier, and that didn’t work either. Just to confirm, I used the GH IP address as the device identifier. Is that what you’re using?

We just need a little more info from @Ryan780 to have even more fun with this… :slight_smile:

Yes, I have tried multiple methods. The integer before and after. I used the device name, IP, global variance, but I see no changes in volume. Mute and unmute work fine but I cannot change the volume from what is was before. Here is the piston I’ve been testing this with.

1 Like

Thanks, @smartxray, my test piston is even simpler. :slight_smile: BTW, I also tried setting the value to 80 (String) and .80 (decimal).

2020-05-18 12_42_10-webCoRE Dashboard

I had to change the volume command from the normal (setVolume) to setDeviceVolume because webCoRE was set to only send one parameter with setVolume. At some point when I was trying to add a couple of other commands that I had to back out, the change for setDeviceVolume was lost. In the DTH, on the 6th line from the bottom, change it from this:

def setVolume(castDevice, value){

to this:

def setDeviceVolume(castDevice, value){

You can then pass an integer, a string, whatever you want, as long as it is a whole number and not a decimal. Also, don’t pass any units (like %)…just the number. And you have to pass the device name first, in parameter one and the volume in parameter 2. After you make the change, be sure to save and publish the DTH and then wait 10-15 seconds before trying the command again.

I made the change in the DTH code, saved and published for me. But even after waiting a while after adding, the volume still is not changing. Here’s the piston I’m using.
Any thoughts as to why the command to adjust the volume is ignored?
I did check the logging in the IDE and the device volume is shown triggering unlike earlier with the previous volume code.

Confirmed also not working for me after the DTH code change, @Ryan780.

BTW - I’m assuming that the volume control does not require that you mute the device before setting the volume.

No, it does not require that you mute it. If you mute it, setting the volume will unmute it automatically.

Can you post exactly what code you changed because it is working for me.

You can’t issue two commands to GAR that close together. They are going to crash over top of each other. You have to put a wait in between them. Try this by JUST changing the volume. You will be able to hear that the volume changed because the speaker will beep at the new volume you just set.’

Here is the code for the device handler. I copied your first post in a text editor then made the volume code adjustment. If I only have the set volume in the piston, there is no sound at all. I added a 5 sec wait but still no change in the volume.
EDIT: I am running GAR 3.31

/*

  • Google Home Assistant Relay v3
  • Copyright 2020 Ryan Casler
  • 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.
  • Change History:
  • Date Who What

  • 2020-03-13 Ryan Casler Initial Release
  • 2020-05-15 Ryan Casler Adpoted for SmartThings
  • Based on the Google Assistnt Relay driver from Daniel Ogorchock
  • Orignal Software License:
  • 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.
  • Credit goes to Greg Hesp’s work on the SmartThings platform as a starting point for this version!
    */

metadata {
definition (name: “Google Home Assistant Relay v3”, namespace: “ryan780”, author: “Ryan780”) {
capability “Actuator”
capability “Notification”
command “mute”
command “unmute”
command “stop”
command “muteDevice”, [“string”]
command “unmuteDevice”, [“string”]
command “stopDevice”, [“string”]
command “castContent”, [“string”,“string”,“string”]
command “setDeviceVolume”, [“string”,“number”]
}
tiles(scale: 2) {
valueTile(“main”, “------”, width: 2, height: 2) {
state “val”, label:’-----’, defaultState: true
}
}
preferences {
input(name: “serverIP”, type: “string”, title:“Server IP Address”, description: “Enter IP Address of your Assistant Relay Server”, required: true, displayDuringSetup: true)
input(name: “serverPort”, type: “string”, title:“Server Port”, description: “Enter Port of your Assistant Relay Server (defaults to 3000)”, defaultValue: “3000”, required: true, displayDuringSetup: true)
input(name: “user”, type: “string”, title:“Assistant Relay Username”, description: “Enter the username for this device”, defaultValue: “”, required: false, displayDuringSetup: true)
input(name: “defaultDevice”, type: “string”, title:“Display Device IP or Name”, description: “Enter the IP address or name of your dispplay device”, required: false)
}
}

def installed() {
updated()
}

def updated() {
}

def initialialized(){
updated()
}

def parse(String description) {
//if (logEnable) log.debug “Parsing ${description}”
}

def speak(message) {
message = message.replaceAll("%20", " “)
message = message.replace(“Å”, “\u00C5”)
message = message.replace(“å”, “\u00E5”)
message = message.replace(“Ä”, “\u00C4”)
message = message.replace(“ä”, “\u00E4”)
message = message.replace(“Ö”, “\u00D6”)
message = message.replace(“ö”, “\u00F6”)
message = message.replace(“Ø”, “\u00D8”)
message = message.replace(“Æ”, “\u00C6”)
message = message.replace(“æ”, “\u00E6”)
message = message.replace(“ø”, “\u00F8”)
def myJSON = “”
if(message.startsWith(”[CC]")){
message = message.minus("[CC]")
if (user) {
myJSON = “{ “command”: “{message}\",\"user\": \"{user}” }”
} else {
myJSON = “{ “command”: “{message}\" }" } } else if(message.startsWith("[CCC]")){ message = message.minus("[CCC]") if (user) { myJSON = "{ \"command\": \"{message}”,“user”: “{user}\",\"converse\": \"true\" }" } else { myJSON = "{ \"command\": \"{message}”,“converse”: “true” }”
}
}
else if(message.startsWith("[P]")){
message = message.minus("[P]")
if (user) {
myJSON = “{ “preset”: “{message}\",\"user\": \"{user}” }”
} else {
myJSON = “{ “preset”: “{message}\" }" } } else { if (user) { myJSON = "{ \"command\": \"{message}”,“user”: “{user}\",\"broadcast\": \"true\" }" } else { myJSON = "{ \"command\": \"{message}”,“broadcast”: “true” }”
}
}
httpPostJSON(myJSON)
}

def deviceNotification(message) {
speak(message)
}

def httpPostJSON(myJSON) {
try {
if (logEnable) log.debug “Sending {myJSON} to {serverIP}:{serverPort}" def headers = [:] headers.put("HOST", "{serverIP}:{serverPort}") headers.put("Content-Type", "application/json") def method = "POST" def path = "/assistant" def result = new physicalgraph.device.HubAction( method: method, path: path, body: myJSON, headers: headers ) return result } catch (Exception e) { log.error "Error = {e}”
}
}

def muteDevice(castDevice){
log.debug “Muting {castDevice}." def message = "Mute {castDevice}”
def myJSON = “{ “command”: “{message}\",\"user\": \"{user}” }”
httpPostJSON(myJSON)
}

def mute(){
if(defaultDevice){
log.debug “Muting default device.”
muteDevice(defaultDevice)
}else{
log.warn “No default device speficied. Sepcify device in command parameter or driver properties.”
}
}

def unmuteDevice(castDevice){
log.debug “Unmuting {castDevice}." def message = "Unmute {castDevice}”
def myJSON = “{ “command”: “{message}\",\"user\": \"{user}” }”
httpPostJSON(myJSON)
}

def unmute(){
if(defaultDevice){
log.debug “Unmuting default device.”
unmuteDevice(defaultDevice)
}else{
log.warn “No default device speficied. Sepcify device in command parameter or driver properties.”
}
}

def castContent(castDevice, type, source){
log.debug “Casting {source} of {type} to {castDevice}" def myJSON = "{ \"type\": \"{type}”,“source”: “{source}\",\"device\": \"{castDevice}” }"
try {
if (logEnable) log.debug “Sending {myJSON} to {serverIP}:{serverPort}" def headers = [:] headers.put("HOST", "{serverIP}:{serverPort}") headers.put("Content-Type", "application/json") def method = "POST" def path = "/cast" def result = new physicalgraph.device.HubAction( method: method, path: path, body: myJSON, headers: headers ) return result } catch (Exception e) { log.error "Error = {e}”
}
}

def stopDevice(castDevice){
log.debug “Stopping {castDevice}" def myJSON = "{ \"device\": \"{castDevice}” }"
try {
if (logEnable) log.debug “Sending {myJSON} to {serverIP}:{serverPort}" def headers = [:] headers.put("HOST", "{serverIP}:{serverPort}") headers.put("Content-Type", "application/json") def method = "POST" def path = "/cast/stop" def result = new physicalgraph.device.HubAction( method: method, path: path, body: myJSON, headers: headers ) return result } catch (Exception e) { log.error "Error = {e}”
}
}

def stop(){
stopDevice(defaultDevice)
}

def uninstalled(){
}

def setDeviceVolume(castDevice, value){
log.debug “Setting volume of {castDevice} to {value}.”
def message = “Set volume of {castDevice} to {value} percent.”
def myJSON = “{ “command”: “{message}\",\"user\": \"{user}” }”
httpPostJSON(myJSON)
}

You should be using setDeviceVolume, not setVolume.

I am using the setDeviceVolume and have it set to a volume of 4 and a wait of 5 sec. for a local mp3 to cast.

Try using a valid value. The scale is 0-100. So, 4 would probably not be able to be heard at all. Try 40.

The way that this works is that a command is constructed and send to the Google Assistant. Dealing with decimals is a pain in the ass, so the message gets build with “percent” after it. You can see in the code:
def message = “Set volume of {castDevice} to {value} percent.”
So, the percent was changing your value to 4%. So, it was working, you just can’t hear it that quietly. But you should have seen that the speaker woke up and the light came on, that should have let you know that the volume was in fact changing.

I changed to 50 and still no change. Here’s the log, so it’s going across but the google device is not receiving it.

You cannot use the IP address for set volume. You must use the device name. Did you not see what I just posted?

The assistant doesn’t know or care what the device IP is. The IP is only used for casting.

Are you using global variables that end up equaling the device IP? Don’t do that. If you’re going to do that have it equal the device name in the Google Home App. That will work everywhere.

Thanks, @Ryan780 and @smartxray, for forging ahead.

Victory!

OK, so I’ve done:

  • Corrected DTH
  • Use device name, not GH IP
  • Use 0-100, not 0-10 scale - I used 80
  • Add a pause between commands - I used 2 seconds
  • Added broadcast

Worked - broadcast came out loud and clear w/a 2 second pause. Even worked w/out a pause between the volume setting and the announcement (only tried it twice, though).

Only thing I see now is that when I set volume to 80 and asked GH what the current volume setting was, it said 88%. When I set it to 30, GH said it was set to 33%. So it’s repeating the digit on the volume setting when the second digit is a zero. When I set it to 35, GH reported volume was 39%, so not sure how GH got to that volume from 35 setting. Minor issue. Example below shows piston after I added second volume command to change the volume after the broadcast.

2020-05-19 14_43_59-webCoRE Dashboard

Very cool.

Don’t forget to set the volume back to a reasonable number if you try 80 like I did. :slight_smile:

Thanks. The change in both volume value and device name (not an IP) worked for me also.
Please understand that some of use are not as skilled as you. I’m just a noob in a lot of this but I’m willing to put in the work.

Maybe an update to the forum with the corrected code and instructions to help guide beginners like me.

The updated code has been posted.

And I’m not getting paid to put this out either. Please remember that.