I've currently achieved the 3 following value reading:
-On or Off (dummy switch)
-Volume (dummy Sound Level)
-Input (dummy text)
it's a loop running 30 times with 10 seconds sleep.
So I start it every 5 min in CRON
*/5 * * * * /home/pi/domoticz/scripts/YamahaRXV.py >/dev/null 2>&1
This avoid to reload the script and libraries every time.
A lots of other options are available from phone app, like choosing DSP and so on. I don't know if it's setup in rxv library.
I will see if I can make another script to send commands but I managed to manually set volume and input with rxv library.
I still think a good logitech harmony hub is a better choice for sending commands.
YamahaRXV.py
Code: Select all
#!/usr/bin/python
import rxv
import time
from urllib2 import urlopen
# change these values
yamaha = "http://192.168.0.190:80"
domoticz = "http://127.0.0.1:8080"
idx_Volume = 6
idx_Input = 7
idx_On = 8
# End
rx = rxv.RXV(str(yamaha)+"/YamahaRemoteControl/ctrl", "RX-V671")
LastVolume = 100
LastInput = "none"
LastState = "unknown"
i = 0
numbers = []
while i < 30:
numbers.append(i)
i = i + 1
Volume = rx.volume
Input = rx.input
State = rx.on
# Volume
if Volume != LastVolume:
response = urlopen(domoticz+'/json.htm?type=command¶m=udevice&idx='+str(idx_Volume)+'&nvalue=0&svalue='+str(Volume))
response.read()
# Input
# List your custom names with if, elif
if Input != LastInput:
if Input == "HDMI2":
InputR="TV"
else:
InputR=Input
response = urlopen(domoticz+'/json.htm?type=command¶m=udevice&idx='+str(idx_Input)+'&nvalue=0&svalue='+str(InputR))
response.read()
# STATE ON
if State != LastState:
if State == True:
print('On')
StateR="On"
else:
print('Off')
StateR="Off"
response = urlopen(domoticz+'/json.htm?type=command¶m=switchlight&idx='+str(idx_On)+'&switchcmd='+str(StateR))
response.read()
LastVolume = Volume
LastInput = Input
LastState = State
time.sleep(10)
print('end')