Well.. i found out myself... very easy
metadata {
definition (name: "Onkyo Receiver (Family Room)", namespace: "cdallum", author: "Carson Dallum") {
capability "Initialize"
capability "Telnet"
capability "Switch"
command "MAIN"
command "SUB"
command "BOTH"
}
main "switch"
details(["switch","MAIN","SUB","BOTH"])
}
def on() {
log.debug "Powering on receiver"
sendEvent(name: "switch", value: "on")
def msg = getEiscpMessage("PWR01")
return new hubitat.device.HubAction(msg,hubitat.device.Protocol.TELNET)
}
def off() {
log.debug "Powering off receiver"
sendEvent(name: "switch", value: "off")
def msg = getEiscpMessage("PWR00")
return new hubitat.device.HubAction(msg,hubitat.device.Protocol.TELNET)
}
def MAIN() {
log.debug "SET OUTPUT TO MAIN"
def msg = getEiscpMessage("HDO01")
return new hubitat.device.HubAction(msg,hubitat.device.Protocol.TELNET)
}
def SUB() {
log.debug "SET OUTPUT TO SUB"
def msg = getEiscpMessage("HDO02")
return new hubitat.device.HubAction(msg,hubitat.device.Protocol.TELNET)
}
def BOTH() {
log.debug "SET OUTPUT TO BOTH"
def msg = getEiscpMessage("HDO03")
return new hubitat.device.HubAction(msg,hubitat.device.Protocol.TELNET)
}
/* This is where I construct the entire message character by character. Each char is represented by a 2 disgit hex value */
def getEiscpMessage(command){
def sb = StringBuilder.newInstance()
def eiscpDataSize = command.length() + 3 // this is the eISCP data size
def eiscpMsgSize = eiscpDataSize + 1 + 16 // this is the size of the entire eISCP msg
sb.append("ISCP")
// the following are all in HEX representing one char
// 4 char Big Endian Header
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("10", 16))
// 4 char Big Endian data size
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
// the official ISCP docs say this is supposed to be just the data size (eiscpDataSize)
// ** BUT **
// It only works if you send the size of the entire Message size (eiscpMsgSize)
// Changing eiscpMsgSize to eiscpDataSize for testing
sb.append((char)Integer.parseInt(Integer.toHexString(eiscpDataSize), 16))
//sb.append((char)Integer.parseInt(Integer.toHexString(eiscpMsgSize), 16))
// eiscp_version = "01";
sb.append((char)Integer.parseInt("01", 16))
// 3 chars reserved = "00"+"00"+"00";
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
sb.append((char)Integer.parseInt("00", 16))
// eISCP data
// Start Character
sb.append("!")
// eISCP data - unittype char '1' is receiver
sb.append("1")
// eISCP data - 3 char command and param ie PWR01
sb.append(command)
// msg end - this can be a few different cahrs depending on your receiver
// my NR5008 works when I use 'EOF'
//OD is CR
//0A is LF
/*
[CR] Carriage Return ASCII Code 0x0D
[LF] Line Feed ASCII Code 0x0A
[EOF] End of File ASCII Code 0x1A
*/
//works with cr or crlf
sb.append((char)Integer.parseInt("0D", 16)) //cr
return sb.toString()
}
// General App Events
def initialize(){
telnetConnect("192.168.1.220", 60128, null, null)
log.debug "Opening telnet connection"
}
def installed(){
initialize()
}
def updated(){
initialize()
}