Onkyo

From Domoticz
Jump to: navigation, search

Purpose

With this script you can control a Onkyo device that is connected to your local network. On this page there are two versions. There is a PHP-version made by user 'kraades' on the Tweakers.net forum (proven to work with TX-NR-609).
Second is a Lua script made by user 'RasPi2'. This Lua versions has been confirmed working with a TX-NR616.
Which script you use depends on you. Maybe they are both able to control your receiver.

You could use these scriptsfor example to mute your receiver when the doorbell is being pressed. Or include a call to your Onkyo device into a Domoticz-scene so that the receiver will switch to a predefined radio preset when a scene in Domoticz is being activated.

PHP variant

The PHP-script

This script needs a webserver with PHP-enabled.
The instructions are quite easy, but are different on each platform, so search for this yourself ('Raspberry PHP webserver' or something like that).

Create a new file on your webserver, name it something like onkyo.php. Copy the contents from the script on this page to the file you just created, and save the file.

<?php
    $command = $_GET['command'];
    $params = $_GET['params'];
 
    $hostname = '192.168.0.115';
    $port = 60128;
 
    switch ($command)
    {
        case 'PWR':
        case 'AMT':
        case 'SLI':
        case 'TUN':
            $message = '!1' . $command . $params;
            break;
        case 'MVL':
            if ($params > 60)
                exit(1);
            $message = '!1' . $command . strtoupper(str_pad(dechex($params), 2, '0', STR_PAD_LEFT));
            break;
        default:
            exit(1);
    }
    print $message;
 
    $fp = pfsockopen($hostname, $port);
    $packet = "ISCP\x00\x00\x00\x10\x00\x00\x00" . chr(strlen($message) + 1) . "\x01\x00\x00\x00" . $message . "\x0D";
    fwrite($fp, $packet);
    fclose($fp);
?>

Instructions for usage

When you have put the script on your webserver and changed the parameters (IP-address of your receiver) to reflect your situation, you can call the script like this:

http://ip_address_of_webserver/path/to/script/onkyo.php?command=PWR&params=00 (Off)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=PWR&params=01 (On)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=MVL&params=55 (Set volume at level 55)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=AMT&params=01 (Mute on = sound off)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=AMT&params=00 (Mute off = sound on)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=SLI&params=00 (Change to input ???)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=SLI&params=24 (Change to input 'Tuner')
http://ip_address_of_webserver/path/to/script/onkyo.php?command=TUN&params=5 (FM-radio preset #5)
http://ip_address_of_webserver/path/to/script/onkyo.php?command=TUN&params=3 (FM-radio preset #3)

More commands can be found in this Excel-document.

Lua variant

If you don't want to use the PHP-variant, you could also use the Lua variant below. Tested on a TX-NR616. Name the script something like script_device_onkyo.lua and put it in /domoticz/scripts/lua/

Setup:

1. install python-setuptools

sudo apt-get install python-setuptools

2. then do

sudo easy_install onkyo-eiscp

3. test if your receiver is detected with

onkyo --discover

list of all commands (for zone main)

onkyo --help-commands main

possible values for command system-power for example

onkyo --help-commands main system-power

Lua script

-- Title: script_device_onkyo
-- Date:  10-07-2015
 
commandArray = {}
 
-- function to get information from receiver
function onkyo_status(command)
  local result = {}
  local output = io.popen ('onkyo '..command)
  for line in output:lines() do
    table.insert(result, line)
  end  
  output:close()
  return result
end
 
-- function to change settings receiver
function onkyo_change(command)
  os.execute('/usr/local/bin/onkyo '..command)
end
 
 
-- turn the receiver on/off with dummy switch 'Versterker' 
if devicechanged['Versterker']=="On" then
  onkyo_change('system-power:on')
else
  if devicechanged['Versterker']=="Off" then
    onkyo_change('system-power:standby')
  end
end
 
-- get status information
if devicechanged['test']=="On" then
  status = onkyo_status('system-power:query')
  print(status[2])
else
  if devicechanged['test']=="Off" then
    status = onkyo_status('system-power:query')
    print(status[2])
  end
end
 
return commandArray

List of commands and possible values

 system-power - System Power Command
   standby - sets System Standby
   on - sets System On
   query - gets the System Power Status
 audio-muting - Audio Muting Command
   off - sets Audio Muting Off
   on - sets Audio Muting On
   toggle - sets Audio Muting Wrap-Around
   query - gets the Audio Muting State
 ('master-volume', 'volume') - Master Volume Command
   None - Volume Level 0 - 100 (In hexadecimal representation)
   None - Volume Level 0 - 80 (In hexadecimal representation)
   level-up - sets Volume Level Up
   level-down - sets Volume Level Down
   level-up-1db-step - sets Volume Level Up 1dB Step
   level-down-1db-step - sets Volume Level Down 1dB Step
   query - gets the Volume Level
 display-mode - Display Mode Command
   selector-volume - sets Selector + Volume Display Mode
   selector-listening - sets Selector + Listening Mode Display Mode
   02 - Display Digital Format(temporary display)
   03 - Display Video Format(temporary display)
   toggle - sets Display Mode Wrap-Around Up
   query - gets The Display Mode
 input-selector - Input Selector Command
   ('video1', 'vcr', 'dvr') - sets VIDEO1, VCR/DVR
   ('video2', 'cbl', 'sat') - sets VIDEO2, CBL/SAT
   ('video3', 'game', 'tv', 'game') - sets VIDEO3, GAME/TV, GAME
   ('video4', 'aux1') - sets VIDEO4, AUX1(AUX)
   ('video5', 'aux2') - sets VIDEO5, AUX2
   ('video6', 'pc') - sets VIDEO6, PC
   video7 - sets VIDEO7
   07 - Hidden1
   08 - Hidden2
   09 - Hidden3
   ('dvd', 'bd', 'dvd') - sets DVD, BD/DVD
   ('tape-1', 'tv', 'tape') - sets TAPE(1), TV/TAPE
   tape2 - sets TAPE2
   phono - sets PHONO 
   ('cd', 'tv', 'cd') - sets CD, TV/CD
   fm - sets FM
   am - sets AM
   tuner - sets TUNER
   ('music-server', 'p4s', 'dlna') - sets MUSIC SERVER, P4S, DLNA
   ('internet-radio', 'iradio-favorite') - sets INTERNET RADIO, iRadio Favorite
   ('usb', 'usb') - sets USB/USB(Front)
   usb - sets USB(Rear)
   ('network', 'net') - sets NETWORK, NET
   usb - sets USB(toggle)
   universal-port - sets Universal PORT
   multi-ch - sets MULTI CH
   xm - sets XM
   sirius - sets SIRIUS
   up - sets Selector Position Wrap-Around Up
   down - sets Selector Position Wrap-Around Down
   query - gets The Selector Position
 audio-selector - Audio Selector Command
   auto - sets AUTO
   multi-channel - sets MULTI-CHANNEL
   analog - sets ANALOG
   ilink - sets iLINK
   hdmi - sets HDMI
   ('coax', 'opt') - sets COAX/OPT
   balance - sets BALANCE
   arc - sets ARC
   up - sets Audio Selector Wrap-Around Up
   query - gets The Audio Selector Status
 listening-mode - Listening Mode Command
   stereo - sets STEREO
   direct - sets DIRECT
   surround - sets SURROUND
   ('film', 'game-rpg') - sets FILM, Game-RPG
   thx - sets THX
   ('action', 'game-action') - sets ACTION, Game-Action
   ('musical', 'game-rock') - sets MUSICAL, Game-Rock
   mono-movie - sets MONO MOVIE
   orchestra - sets ORCHESTRA
   unplugged - sets UNPLUGGED
   studio-mix - sets STUDIO-MIX
   tv-logic - sets TV LOGIC
   all-ch-stereo - sets ALL CH STEREO
   theater-dimensional - sets THEATER-DIMENSIONAL
   ('enhanced-7', 'enhance', 'game-sports') - sets ENHANCED 7/ENHANCE, Game-Sports
   mono - sets MONO
   pure-audio - sets PURE AUDIO
   multiplex - sets MULTIPLEX
   full-mono - sets FULL MONO
   dolby-virtual - sets DOLBY VIRTUAL
   dts-surround-sensation - sets DTS Surround Sensation
   audyssey-dsx - sets Audyssey DSX
   whole-house - sets Whole House Mode
   straight-decode - sets Straight Decode
   dolby-ex - sets Dolby EX
   thx-cinema - sets THX Cinema
   thx-surround-ex - sets THX Surround EX
   thx-music - sets THX Music
   thx-games - sets THX Games
   ('thx-u2', 's2', 'i', 's-cinema', 'cinema2') - sets THX U2/S2/I/S Cinema/Cinema2
   ('thx-musicmode', 'thx-u2', 's2', 'i', 's-music') - sets THX MusicMode,THX U2/S2/I/S Music
   ('thx-games', 'thx-u2', 's2', 'i', 's-games') - sets THX Games Mode,THX U2/S2/I/S Games
   ('plii', 'pliix-movie') - sets PLII/PLIIx Movie
   ('plii', 'pliix-music') - sets PLII/PLIIx Music
   ('neo-6-cinema', 'neo-x-cinema') - sets Neo:6 Cinema/Neo:X Cinema
   ('neo-6-music', 'neo-x-music') - sets Neo:6 Music/Neo:X Music
   ('plii', 'pliix-thx-cinema') - sets PLII/PLIIx THX Cinema
   ('neo-6', 'neo-x-thx-cinema') - sets Neo:6/Neo:X THX Cinema
   ('plii', 'pliix-game') - sets PLII/PLIIx Game
   neural-surr - sets Neural Surr
   ('neural-thx', 'neural-surround') - sets Neural THX/Neural Surround
   ('plii', 'pliix-thx-games') - sets PLII/PLIIx THX Games
   ('neo-6', 'neo-x-thx-games') - sets Neo:6/Neo:X THX Games
   ('plii', 'pliix-thx-music') - sets PLII/PLIIx THX Music
   ('neo-6', 'neo-x-thx-music') - sets Neo:6/Neo:X THX Music
   neural-thx-cinema - sets Neural THX Cinema
   neural-thx-music - sets Neural THX Music
   neural-thx-games - sets Neural THX Games
   pliiz-height - sets PLIIz Height
   neo-6-cinema-dts-surround-sensation - sets Neo:6 Cinema DTS Surround Sensation
   neo-6-music-dts-surround-sensation - sets Neo:6 Music DTS Surround Sensation
   neural-digital-music - sets Neural Digital Music
   pliiz-height-thx-cinema - sets PLIIz Height + THX Cinema
   pliiz-height-thx-music - sets PLIIz Height + THX Music
   pliiz-height-thx-games - sets PLIIz Height + THX Games
   ('pliiz-height-thx-u2', 's2-cinema') - sets PLIIz Height + THX U2/S2 Cinema
   ('pliiz-height-thx-u2', 's2-music') - sets PLIIz Height + THX U2/S2 Music
   ('pliiz-height-thx-u2', 's2-games') - sets PLIIz Height + THX U2/S2 Games
   neo-x-game - sets Neo:X Game
   ('pliix', 'plii-movie-audyssey-dsx') - sets PLIIx/PLII Movie + Audyssey DSX
   ('pliix', 'plii-music-audyssey-dsx') - sets PLIIx/PLII Music + Audyssey DSX
   ('pliix', 'plii-game-audyssey-dsx') - sets PLIIx/PLII Game + Audyssey DSX
   neo-6-cinema-audyssey-dsx - sets Neo:6 Cinema + Audyssey DSX
   neo-6-music-audyssey-dsx - sets Neo:6 Music + Audyssey DSX
   neural-surround-audyssey-dsx - sets Neural Surround + Audyssey DSX
   neural-digital-music-audyssey-dsx - sets Neural Digital Music + Audyssey DSX
   dolby-ex-audyssey-dsx - sets Dolby EX + Audyssey DSX
   up - sets Listening Mode Wrap-Around Up
   down - sets Listening Mode Wrap-Around Down
   movie - sets Listening Mode Wrap-Around Up
   music - sets Listening Mode Wrap-Around Up
   game - sets Listening Mode Wrap-Around Up
   query - gets The Listening Mode
 network-usb - Network/USB Operation Command (Network Model Only after TX-NR905)
   play - PLAY KEY
   stop - STOP KEY
   pause - PAUSE KEY
   trup - TRACK UP KEY
   trdn - TRACK DOWN KEY
   ff - FF KEY (CONTINUOUS*)
   rew - REW KEY (CONTINUOUS*)
   repeat - REPEAT KEY
   random - RANDOM KEY
   display - DISPLAY KEY
   album - ALBUM KEY
   artist - ARTIST KEY
   genre - GENRE KEY
   playlist - PLAYLIST KEY
   right - RIGHT KEY
   left - LEFT KEY
   up - UP KEY
   down - DOWN KEY
   select - SELECT KEY
   0 - 0 KEY
   1 - 1 KEY
   2 - 2 KEY
   3 - 3 KEY
   4 - 4 KEY
   5 - 5 KEY
   6 - 6 KEY
   7 - 7 KEY
   8 - 8 KEY
   9 - 9 KEY
   delete - DELETE KEY
   caps - CAPS KEY
   location - LOCATION KEY
   language - LANGUAGE KEY
   setup - SETUP KEY
   return - RETURN KEY
   chup - CH UP(for iRadio)
   chdn - CH DOWN(for iRadio)
   menu - MENU
   top - TOP MENU
   mode - MODE(for iPod) STD<->EXT
   list - LIST <-> PLAYBACK
 internet-radio-preset - Internet Radio Preset Command
   no-1-40 - sets Preset No. 1 - 40 ( In hexadecimal representation)
   set - preset memory current station
 --the possible values for the next commands you have to look up yourself--
 speaker-a - Speaker A Command
 speaker-b - Speaker B Command
 speaker-layout - Speaker Layout Command
 tone-front - Tone(Front) Command
 tone-front-wide - Tone(Front Wide) Command
 tone-front-high - Tone(Front High) Command
 tone-center - Tone(Center) Command
 tone-surround - Tone(Surround) Command
 tone-surround-back - Tone(Surround Back) Command
 tone-subwoofer - Tone(Subwoofer) Command
 recout-selector - RECOUT Selector Command
 dimmer-level - Dimmer Level Command
 setup - Setup Operation Command
 memory-setup - Memory Setup Command
 audio-infomation - Audio Infomation Command
 video-infomation - Video Infomation Command
 sleep-set - Sleep Set Command
 speaker-level-calibration - Speaker Level Calibration Command
 subwoofer-temporary-level - Subwoofer (temporary) Level Command
 center-temporary-level - Center (temporary) Level Command
 12v-trigger-a - 12V Trigger A Command
 12v-trigger-b - 12V Trigger B Command
 12v-trigger-c - 12V Trigger C Command
 video-output-selector - Video Output Selector (Japanese Model Only)
 hdmi-output-selector - HDMI Output Selector
 hdmi-audio-out - HDMI Audio Out
 monitor-out-resolution - Monitor Out Resolution
 isf-mode - ISF Mode
 video-wide-mode - Video Wide Mode
 video-picture-mode - Video Picture Mode
 late-night - Late Night Command
 cinema-filter - Cinema Filter Command
 audyssey-2eq-multeq-multeq-xt - Audyssey 2EQ/MultEQ/MultEQ XT
 audyssey-dynamic-eq - Audyssey Dynamic EQ
 audyssey-dynamic-volume - Audyssey Dynamic Volume
 dolby-volume - Dolby Volume
 music-optimizer - Music Optimizer
 tuning - Tuning Command (Include Tuner Pack Model Only)
 preset - Preset Command (Include Tuner Pack Model Only)
 preset-memory - Preset Memory Command (Include Tuner Pack Model Only)
 rds-information - RDS Information Command (RDS Model Only)
 pty-scan - PTY Scan Command (RDS Model Only)
 tp-scan - TP Scan Command (RDS Model Only)
 xm-channel-name-info - XM Channel Name Info (XM Model Only)
 xm-artist-name-info - XM Artist Name Info (XM Model Only)
 xm-title-info - XM Title Info (XM Model Only)
 xm-channel-number - XM Channel Number Command (XM Model Only)
 xm-category - XM Category Command (XM Model Only)
 sirius-channel-name-info - SIRIUS Channel Name Info (SIRIUS Model Only)
 sirius-artist-name-info - SIRIUS Artist Name Info (SIRIUS Model Only)
 sirius-title-info - SIRIUS Title Info (SIRIUS Model Only)
 sirius-channel-number - SIRIUS Channel Number Command (SIRIUS Model Only)
 sirius-category - SIRIUS Category Command (SIRIUS Model Only)
 sirius-parental-lock - SIRIUS Parental Lock Command (SIRIUS Model Only)
 hd-radio-artist-name-info - HD Radio Artist Name Info (HD Radio Model Only)
 hd-radio-channel-name-info - HD Radio Channel Name Info (HD Radio Model Only)
 hd-radio-title-info - HD Radio Title Info (HD Radio Model Only)
 hd-radio-detail-info - HD Radio Detail Info (HD Radio Model Only)
 hd-radio-channel-program - HD Radio Channel Program Command (HD Radio Model Only)
 hd-radio-blend-mode - HD Radio Blend Mode Command (HD Radio Model Only)
 hd-radio-tuner-status - HD Radio Tuner Status (HD Radio Model Only)
 net-usb-artist-name-info - NET/USB Artist Name Info
 net-usb-album-name-info - NET/USB Album Name Info
 net-usb-title-name - NET/USB Title Name
 net-usb-time-info - NET/USB Time Info
 net-usb-track-info - NET/USB Track Info
 net-usb-play-status - NET/USB Play Status
 net-usb-list-info - NET/USB List Info
 net-usb-jacket-art - NET/USB Jacket Art (When Jacket Art is available and Output for Network Control Only)
 net-service - NET Service(for Network Control Only)
 net-keyboard - NET Keyboard(for Network Control Only)
 net-popup-message - NET Popup Message(for Network Control Only)
 ipod-mode-change - iPod Mode Change (with USB Connection Only)
 cd-player - CD Player Operation Command
 tape1-a - TAPE1(A) Operation Command
 tape2-b - TAPE2(B) Operation Command
 graphics-equalizer - Graphics Equalizer Operation Command
 dat-recorder - DAT Recorder Operation Command
 dvd-player - DVD Player Operation Command (via RIHD only after TX-NR509)
 md-recorder - MD Recorder Operation Command
 cd-r-recorder - CD-R Recorder Operation Command
 universal-port - Universal PORT Operation Command
 ipod-artist-name-info - iPod Artist Name Info (Universal Port Dock Only)
 ipod-album-name-info - iPod Album Name Info (Universal Port Dock Only)
 ipod-title-name - iPod Title Name (Universal Port Dock Only)
 ipod-time-info - iPod Time Info (Universal Port Dock Only)
 ipod-track-info - iPod Track Info (Universal Port Dock Only)
 ipod-play-status - iPod Play Status (Universal Port Dock Only)
 ipod-list-info - iPod List Info (Universal Port Dock Extend Mode Only)
 ipod-mode-change - iPod Mode Change (Universal Port Dock Only)
 tuning - Tuning Command (Universal Port Dock Only)
 dab-preset - DAB Preset Command (Universal Port Dock Only)
 preset-memory - Preset Memory Command (Universal Port Dock Only)
 hd-radio-channel-program - HD Radio Channel Program Command (Universal Port Dock Only)
 hd-radio-blend-mode - HD Radio Blend Mode Command (Universal Port Dock Only)
 hd-radio-artist-name-info - HD Radio Artist Name Info (Universal Port Dock Only)
 hd-radio-channel-name-info - HD Radio Channel Name Info (Universal Port Dock Only)
 hd-radio-title-info - HD Radio Title Info (Universal Port Dock Only)
 hd-radio-detail-info - HD Radio Detail Info (Universal Port Dock Only)
 hd-radio-tuner-status - HD Radio Tuner Status (Universal Port Dock Only)
 dab-sation-name - DAB Sation Name (Universal Port Dock Only)
 dab-display-info - DAB Display Info (Universal Port Dock Only)