IP Control of Amp - Looking for solutions

Excellent. I can make this work for you then. Give me a little bit and I should have something for you to play with.

I can't thank you enough - let me buy you a beer!

ps: What about reseting the telnet connection to keep it alive ? The doc above says:

Sending -r.3 every 2 minutes, will ensure that
the connection is reset in the event of a controller
power reboot; allowing the controller to reconnect.

Go ahead and try it to see what it does, we may need it...

Doesn't seem to do anything that I can tell. Will be great if the state of various items are captured in the hubitat "current states" area - like current source, power status, telnet connection status etc

edit: It seems to have broken the telnet connection ( -r.3). After sending -r.3, I tried to change the source ( -1.4) and got this:

  • statusMessage : send error: Broken pipe (Write failed)

Started working ok after I clicked on "Connect Telnet"

Hmmm. I may need to do a keep alive from the driver, guess we'll see. :slight_smile:

What do the input numbers map to?

1 - Balanced Input (analog?)
...
4 - Coax
...
9 - ??

"1": "Balanced", ->> xlr analog
"2": "Analog 1",
"3": "Analog 2",
"4": "Coaxial",
"5": "Optical 1",
"6": "Optical 2",
"7": "Optical 3",
"8": "USB",
"9": "Network",

1 Like

Okay, let's try creating a driver from this:

Hegal Amp Driver
 /*

 */


@SuppressWarnings('unused')
static String version() {return "0.0.0"}

metadata {
    definition (
        name: "Hegel Amp", 
        namespace: "thebearmay", 
        author: "Jean P. May, Jr.",
        importUrl:"https://raw.githubusercontent.com/thebearmay/hubitat/main/xxxx.groovy"
    ) {
        
        capability "Telnet"
        capability "Switch"
        
        attribute "mute", "ENUM", ["on", "off"]
        attribute "input", "STRING"
        attribute "lastMessage", "STRING"

        command "connectTelnet"
        command "disconnectTelnet"
        command "powerToggle"
        command "volUp"
        command "volDown"
        command "setVolume", [[name:"level", type:"NUMBER", description:"Level to set volume to, % of Max", range:"0..100"]] 
        command "muteOn"
        command "muteOff"
        command "muteToggle"
        command "setInput", [[name:"input", type:"NUMBER", description:"Input Number", range:"1..9"]]


    }   
}

preferences {

    input(name: "ipAddr", type: "string", title:"IP Address", required: true)
    input(name: "portNum", type: "number", title: "Port Number", required: true)
    input(name: "volume", type: "number", title: "Starting Volume Level", defaultValue: 50, submitOnChange: true)
}

@SuppressWarnings('unused')
def installed() {

}
void updateAttr(String aKey, aValue, String aUnit = ""){
    sendEvent(name:aKey, value:aValue, unit:aUnit)
}

def connectTelnet(){
    try{
        telnetConnect([termChars:[10]], ipAddr, (int)portNum, null, null)
    } catch (ex) {
        updateAttr("lastMessage", ex)
    }
}

def disconnectTelnet() {
    telnetClose()
}

def sendMsg(message) {
    sendHubCommand(new hubitat.device.HubAction("""$message\r\n""", hubitat.device.Protocol.TELNET))
}

def on(){
    connectTelnet()
    sendMsg("-p.1")
    updateAttr("switch", "on")
}

def off(){
    sendMsg("-p.0")
    disconnectTelnet()
    updateAttr("switch", "off")
}

def powerToggle(){
    sendMsg("-p.t")
    if(device.currentValue("switch") == "on")
        updateAttr("switch", "off")
    else {
        updateAttr("switch", "off")
        setVolume(volume)
    }
}

def muteOn(){
    sendMsg("-m.1")
    updateAttr("mute", "on")
}

def muteOff(){
    sendMsg("-m.0")
    updateAttr("mute", "off")
}

def muteToggle(){
    sendMsg("-m.t")
    if(device.currentValue("mute") == "on")
        updateAttr("mute", "off")
    else        
        updateAttr("mute", "off")
}

def volUp() {
    sendMsg("-v.u")
}

def volDown() {
    sendMsg("-v.d")
}

def setVolume(level=50){
    if(level == null) level = 50
    sendMsg("-v.${level.toInteger()}")
}

def setInput(input){
    sendMsg("i.${input.toInteger()}")
    iVals = ["1": "Balanced","2": "Analog 1","3": "Analog 2","4": "Coaxial","5": "Optical 1","6": "Optical 2","7": "Optical 3","8": "USB","9": "Network"]
    updateAttr("input", iVals["$input"])
}

def parse(message) {
    updateAttr("lastMessage", message)
}

def telnetStatus(message){
        updateAttr("lastMessage", message)
}

and then change your device type to it. The on command should create the connection and power it on.

ok - thank you! give me a few minutes to implement and test the prior codes. brb.

Everything works except:

  1. Set Input
  2. Set Volume
  3. VolUp
  4. Vol Down

They dont seem to do anything

any thing in the logs or the last message attribute

I dont see anything in the logs ( searched got hegel amp ), but current states shows:

Current States

  • input : Coaxial
  • mute : off
  • switch : off
  • lastMessage : java.net.ConnectException: Connection refused (Connection refused)

Looks like the amp refused the connection request... try clicking the On command, and then the Set Volume with a value of 50

all the buttons are unresponsive now, including powering on / off. Seems to be going back and forth being responsive then offline. I will wait for a minute or so, then click on to see what happens

edit: yep - working now - including volup, voldown . But couldnt try set input , because it became unresponsive again. Possible the telnet connection dropping?

Should be a warning message in the logs if it drops, it may just need some time between commands.

To make things easier, I created a github entry for this code, so to update all you need to do is click import in the driver code and paste

https://raw.githubusercontent.com/thebearmay/hubitat/main/hegelAmp.groovy

into the URL box that comes up. (After the first time it should auto fill.)

Edit: Made a few minor changes so do an import when you get a moment.

1 Like

import done. a bit more responsive but still having periods where none of the buttons work. Still cant get Set Input to work - only one so far. What is the required input there? numbers? e.g. 1,2,4 etc ?

Should be 1 through 9

Yea - still not working ( set input ) and also still having periods where nothing works, then it starts working again.

Not sure what is going on with the Input function, it's getting down there but not handling something right. Parameter ranges aren't working right either, so I have something fubarred there.

Going to have to play a little more.

Made some changes that I hope will help…