No, I didn’t get it to work as I wanted to and haven gotten around to fix it yet.
My current solution is that I have a raspberry pi that has a python script to control the NAD and connected it to the NAD with a cheap Chinese usb to serial converter.
I then use the exec binding to send commands to it and poll data.
If you have a computer next to the NAD the extra pi won’t of course not be necessary.
Script that wraps the command script :
#!/usr/bin/python
import nad757.nad_757_new as NAD
import sys
args = sys.argv
cmd = args[1].lower()
value=args[2].lower()
nadCom = NAD.NadCom()
if(cmd == 'power'):
if(value == '?'):
print(nadCom.powerState())
else:
print(nadCom.power(value))
elif(cmd == 'mute'):
if(value == '?'):
print(nadCom.muteState())
else:
print(nadCom.mute(value))
elif(cmd == 'source'):
if(value == '?'):
rsp = nadCom.source()
print(rsp)
else:
print(nadCom.setSource(value))
elif(cmd == 'volume'):
if(value == '?'):
print(nadCom.getVolume())
else:
print(nadCom.setVolume(value))
The script that does the acrual communitaction with the nad:
#!/usr/bin/python
import sys
import serial
import io
class NadCom:
def __init__(self):
self.nad = serial.Serial ("/dev/Nad")
self.nad.baudrate = 115200
self.nad.parity = serial.PARITY_NONE
self.nad.bytesize = serial.EIGHTBITS
self.nad.stopbits = serial.STOPBITS_ONE
self.nad.xonxoff = False
self.nad.rtscts = False
self.nad.dsrdtr = False
self.nad.timeout = 5
self.nad_read = io.TextIOWrapper(io.BufferedRWPair(self.nad, self.nad, 1000),
newline = '\r',
line_buffering = True)
if(self.nad.isOpen() == False):
self.nad.open()
def send(self, command):
self.nad.flushOutput()
self.nad.write("\r" + command + "\r")
def read(self):
rsp = self.nad_read.readline()
return rsp[:-1]#Strip the trailing '\r' character.
def power(self, state):
self.send("Main.Power=" + state)
return self.getOnOffState("Main.Power")
def powerState(self):
self.send("Main.Power?")
return self.getOnOffState("Main.Power")
def mute(self, state):
self.send("Main.Mute=" + state)
return self.getOnOffState("Main.Mute")
def muteState(self):
self.send("Main.Mute?")
return self.getOnOffState("Main.Mute")
def getOnOffState(self, field):
value = self.getValue(field)
if (value == "Off"):
return 'OFF'
if(value == "On"):
return 'ON'
return 'Fail'
def source(self):
return self.getValue("Main.Source")
def setSource(self, source):
self.send("Main.Source=" + source)
return self.getValue("Main.Source")
def getVolume(self):
return self.getValue("Main.Volume")
def setVolume(self, volume):
self.send("Main.Volume=" + volume)
return self.getValue("Main.Volume")
def getValue(self, field):
return self.getValue2(field, 10)
def getValue2(self, field, count):
if(count == 0):
return "Fail"
self.nad.flushInput()
self.send(field + "?")
resp = self.read().split("=")
while (len(resp) == 2):
if (resp[0] == field):
return resp[1]
resp = self.read().split("=")
return self.getValue2(field, count - 1)
def close(self):
self.nad.close()
My items:
Switch nadPower "Nad power" (bio_controls) ["Switchable"] {exec="<[ssh automation /usr/share/openhab/python/nad.py power ?:5000:REGEX((.*?))] >[ON:ssh automation /usr/share/openhab/python/nad.py power on] >[OFF:ssh automation /usr/share/openhab/python/nad.py power off]", autoupdate="true"}
Switch nadMute "Mute" (bio_controls) {exec="<[ssh automation /usr/share/openhab/python/nad.py mute ?:5000:REGEX((.*?))] >[ON:ssh automation /usr/share/openhab/python/nad.py mute on] >[OFF:ssh automation /usr/share/openhab/python/nad.py mute off]", autoupdate="true"}
Number nadSource "Source" {exec="<[ssh automation /usr/share/openhab/python/nad.py source ?:5000:REGEX((.*?))] >[*:ssh automation /usr/share/openhab/python/nad.py source %2$s]", autoupdate="true"}
Number nadVolume "Volume [%ddB]" <soundvolume> {exec="<[ssh automation /usr/share/openhab/python/nad.py volume ?:5000:REGEX((.*?))] >[*:ssh automation /usr/share/openhab/python/nad.py volume %2$s]", autoupdate="true"}
My sitemap settiongs:
Selection item=nadSource icon="source" mappings=[1="Xbmc", 2="AppleTv", 3="Wii", 4="PS4"]
Setpoint item=nadVolume icon="volume" minValue=-99.0 maxValue=15 step=1 visibility=[nadMute==OFF]
Setpoint item=nadVolume icon="mute" minValue=-99.0 maxValue=15 step=1 visibility=[nadMute==ON]
Switch item=nadMute icon=""
Switch item=nadPower icon="power"
Edit: That said I might take up work on the NAD binding again as I will have some time on my hands now.