Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide how to power off/on onkyo/integra receivers automatically
#1
Hi,
I've just started using Moode and in the process of setting it up and getting it going I've done a few things that I thought I'd share.

In my place I've got a Rpi4 connected to my Integra AVR over HDMI. I wanted the AVR to turn on, change to the proper input and set the volume when Moode started playing audio. I also wanted it to turn off after nothing had been playing for a bit.

Here's how I did it:

- installed onkyo-eiscp (github for that project is here: https://github.com/miracle2k/onkyo-eiscp)
Code:
$ sudo pip3 install onkyo-eiscp


- then I made sure it was working. My Integra AVR is an older unit so it isn't auto-discoverable by eiscp
Code:
$ onkyo --discover
(returns nothing, not a shock.)

- But I know the IP address I've given the AVR so these work
Code:
$ onkyo --host 192.168.0.125 power=on
unknown-model: system-power = on

$ onkyo --host 192.168.0.125 source=query
unknown-model: input-selector = video2,cbl,sat

I found here on the forum that someone had written a bit of python to control relays when moode started / stopped playing - so I adapted that script. Thanks to the person who wrote that one! (original script was here: https://gist.github.com/michaelfdeberry/...1a7e09f3de)

Code:
#!/usr/bin/env python3

import os
import time
import eiscp.script

defaultDelay = 5 #seconds
playbackDelay = 300 #seconds
currentState = False # the current state



def isRunning():
   return "RUNNING" in os.popen('cat /proc/asound/card0/pcm*/sub*/status | grep RUNNING').read().split()

while True:
   if isRunning() and not currentState:        
       receiver = eiscp.eISCP('192.168.0.125') # 125 = integra
       receiver.command('power on')
       receiver.command('volume=40')
       receiver.command('input-selector=video2')
       receiver.disconnect()
       currentState = True
       print("onkyo Activated")
       time.sleep(defaultDelay)
       
   elif not isRunning() and currentState:  
       # delay again on playback stops to account for track changes
       #time.sleep(defaultDelay)
       # we wait longer to shut down, in case there's a device swap or whatever
       time.sleep(playbackDelay)
               
       if isRunning():
           # if it's running don't deactivate the realay  
           print("Playback resumed, cancelling deactivation")
           continue
       else:
           # deactivate the relay
           receiver = eiscp.eISCP('192.168.0.125') # 125 = integra
           receiver.command('power off')
           receiver.disconnect()
           currentState = False
           print("Onkyo Deactivated")                                    
           
       time.sleep(defaultDelay)
   else:
       print("No State Change...")
       time.sleep(defaultDelay)


(this is also in the attached zip file)

This worked fine from the command line, so I then added it as a system service, as the relay controller did:

- Save the contents of onkyotoggle.service script to /lib/systemd/system/onkyotoggle.service
Code:
[Unit]
Description=MoOde Onkyo Toggle Daemon

[Service]
Restart=on-failure
WorkingDirectory=/home/pi
ExecStart=python3 onkyotoggle.py
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

(this is also in the attached zip file)

- set it going in systemd
Code:
$ sudo systemctl enable onkyotoggle
Created symlink /etc/systemd/system/multi-user.target.wants/onkyotoggle.service → /lib/systemd/system/onkyotoggle.service.
$ sudo service onkyotoggle start


Attached Files
.zip   onkyotoggle.zip (Size: 1.08 KB / Downloads: 1)
Reply


Forum Jump: