Skip to content

Commit

Permalink
Install instructions and variable naming
Browse files Browse the repository at this point in the history
Tidying up install instructions and compatibility text and tests.

Simple formatting and renaming in the daemon script to make a bit more
sense.
  • Loading branch information
Dom committed Nov 5, 2014
1 parent c7332ee commit 452c3e6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 37 deletions.
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,65 @@
hyperion-config-switch
======================

Scripts to switch Hyperion Ambilight config files based on external factors, such as a change in AVR power or input.
This script was created to allow an [Hyperion](https://github.com/tvdzwan/hyperion/) Ambilight configuration to be altered in reaction to external factors, such as a change in AVR power or input. This was something I desired to be able to do myself, but was also spurred on by requests for such features in the [Hyperion Issues forum](), specifically issues [#177](https://github.com/tvdzwan/hyperion/issues/177) and [#186](https://github.com/tvdzwan/hyperion/issues/186).

### Pioneer
My own AVR is a network connected [Pioneer VSX-1028-K](www.pioneerelectronics.ca/POCEN/Home/AV-Receivers/FutureShop/VSX-1028-K). Upon investigation I found the AVR could be controlled using basic ASCII commands issued over a telnet connection. Not only that, but if a socket was left open, the AVR could be monitored through ASCII 'event' codes it writes for each behaviour.

### AVR Compatability

Tested and working with Pioneer VSX-1028, but should work with all compatible series such as 82X, 102X, 112X and others compatible with IP commands as listed in [Pioneer Home Custom Install documentation]( http://www.pioneerelectronics.com/StaticFiles/PUSA/Files/Home%20Custom%20Install/VSX-1120-K-RS232.PDF)
After learning this about my own AVR, I researched further and found almost-identical systems also employed by Denon and Onkyo, just with different event codes. If your AVR is network connected, you can easily tell if it is compatible using some basic steps.

**NOTE:** The Pioneer file is old so just because your AVR is not listed does not mean it is not supported. It is easy to test if you know the IP address of your AVR:
Example codes for testing are listed below for known manufacturer specifications. Note however the specification files are old so just because your AVR is not listed does not mean it is not supported. Some specs have also changed over time so just because a manuf code doesn't work, doesn't mean it's not possible, you just need to find the correct codes.

`printf "?P\r" | nc xxx.xxx.xxx.xxx 23 -w 1`
- Replace `EVENT` in each of the following commands should be replaced with a compatible 'event' for your AVR manufacturer
- Replace `avr.ipa.ddr.ess` and `port` with values for your AVR

Which should return either `PWR1` or `PWR0`, where 1 means is the AVR is powered off and 0 is on (backward I know).

If that doesn't return a result, try this instead
`printf "EVENT\r" | nc avr.ipa.ddr.ess port -w 1`

`{ echo "?F"; sleep 1; } | telnet xxx.xxx.xxx.xxx 23`
or

`{ echo "EVENT"; sleep 1; } | telnet avr.ipa.ddr.ess port`

Which will return a lot more, but in amongst it should be the same result

```
Trying xxx.xxx.xxx.xxx...
Connected to xxxxxxxxxxxx.local.
Escape character is '^]'.
PWR1
EVENT
Connection closed by foreign host.
```

Using the latter telnet command, if you don't get anything the first time just try a couple more times. The telnet responses are inconsistent for some reason.

### Pioneer
Tested and working with Pioneer VSX-1028, but should work with all compatible series such as 82X, 102X, 112X and others compatible with IP commands as listed in [Pioneer Home Custom Install documentation]( http://www.pioneerelectronics.com/StaticFiles/PUSA/Files/Home%20Custom%20Install/VSX-1120-K-RS232.PDF). The included example configuration for Pioneer is based on this specification.

Compatability test event: `?P`.
Response: `PWR1` or `PWR0`, where 1 means is the AVR is powered off and 0 is on (backward I know).


### Denon
**Testers wanted**
Codes in provided config file taken from this document

The included example configuration for Denon is based on this specification.
http://openrb.com/wp-content/uploads/2012/02/AVR3312CI_AVR3312_PROTOCOL_V7.6.0.pdf

Compatability test event: `?PW`.
Response: `PWSTANDBY` or `PWON`.


### Onkyo
**Testers wanted**
Codes in provided config file taken from this document

The included example configuration for Onkyo is based on this specification.
http://www.epanorama.net/sff/Audio/Products/Receivers/Onkyo%20-%20TXDS989-rs232-codes%5B1%5D.pdf

Compatability test event: `?PWR`.
Response: `PWR00` or `PW01`, where 1 is on and 0 is off.


## Suggested Installation

Move your existing config file and creating a symbolic link as the file Hyperion will look for. This makes it easier to switch scripts without anything getting overwritten.
Expand All @@ -53,11 +74,14 @@ cd
git clone https://github.com/Hwulex/hyperion-config-switch.git
cd hyperion-config-switch/
chmod a+x hyperion-config-switch.daemon.sh
sudo mv /etc/hyperion.config.json hyperion.config.default.json
ln -s hyperion.config.json hyperion.config.default.json
ln -s /etc/hyperion.config.json hyperion.config.json
ln -s hyperion.config.default.json hyperion.config.json
sudo ln -s hyperion.config.json /etc/hyperion.config.json
initctl restart hyperion
```
The final command may need to be run as `sudo /etc/init.d/hyperion restart`

At this point you will want to open the `hyperion-config-switch.conf` file in your favourite editor and put in your AVR IP address, port, etc, and make sure the Raspbmc paths are configured correctly. Then:
```
ln -s avr.YOUR_AVR_MANUFACTURER.conf avr.conf
Expand All @@ -71,14 +95,15 @@ SSH as **root** to your installation using `ssh [email protected]`. The defau
```
cd /storage/hyperion/config/
mv hyperion.config.json hyperion.config.default.json
ln -s hyperion.config.json hyperion.config.default.json
ln -s hyperion.config.default.json hyperion.config.json
killall hyperiond
/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &
curl -L --output hyperion-config-switch.sh --get https://raw.githubusercontent.com/Hwulex/hyperion-config-switch/master/hyperion-config-switch.pioneer.sh
curl -L --output hyperion-config-switch.sh --get https://raw.githubusercontent.com/Hwulex/hyperion-config-switch/master/hyperion-config-switch.pioneer.conf
curl -L --output hyperion-config-switch.sh --get https://raw.githubusercontent.com/Hwulex/hyperion-config-switch/master/avr.YOUR_AVR_MANUFACTURER.conf
chmod a+x hyperion-config-switch.pioneer.sh
```
At this point you will want to open the `hyperion-config-switch.conf` file in your favourite editor and put in your AVR IP address, port, etc, and make sure the Raspbmc paths are configured correctly. Then:
```
Expand All @@ -88,15 +113,17 @@ ln -s avr.YOUR_AVR_MANUFACTURER.conf avr.conf

## Per-Input Configuration

If you wish (or need) to run different Hyperion configurations for different AVR inputs (different black crops, colour casting, etc) then that is very easy. Simply copy the default hyperion.config.json file to another with the name of the corresponding AVR input code inserted. Next, ensure it is also listed in the avr.MANUF.conf file under `src_custom` and you're reading to go.
If you wish (or need) to run different Hyperion configurations for different AVR inputs (different black crops, colour casting, etc) then that is very easy. Simply copy the default hyperion.config.json file to another with the name of the corresponding AVR input code inserted. Next, ensure it is also listed in the `avr.MANUF.conf` file under `src_custom` and you're reading to go.

Example:
````
ln -s hyperion.config.json hyperion.config.FN20.json
cp hyperion.config.json hyperion.config.FN20.json
````
Where FN20 is the HDMI2 input on my Pioneer AVR. Find the code for your input using the linked documents for your manufacturer and substitute in to these commands.

There is no need to restart the hyperion-config-switch.sh process. As long as the corresponding code was present in the avr.MANUF.conf src_custom section before loading, it will start using the file immediately.


## TODO

- [ ] Create a system-dependant install script for all this crap
Expand Down
41 changes: 20 additions & 21 deletions hyperion-config-switch.daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,33 @@ set -u
# Check for and load config
config="hyperion-config-switch.conf"
if [ ! -e "$config" ]; then
echo "Fatal error: Config file not found"
echo "Fatal error: Script config file not found"
fi
source "$config" &> /dev/null

# Check for and load AVR parameters
avrconf="avr.conf"
if [ ! -e "$avrconf" ]; then
echo "Fatal error: Config file not found"
echo "Fatal error: AVR config file not found"
fi
source "$avrconf" &> /dev/null


# Remote durations are in miliseconds but bash sleeps in seconds so do some conversion
off_sleep=$(((off_duration+1000)/1000))

# Kick things off
{
echo "[$(date "+%F %T")] Starting loop"

while :
do
echo "[$(date "+%F %T")] Starting netcat"

nc $avr_ip $avr_port | while read line
nc $avr_ip $avr_port | while read event
do
match=$(echo "$line" | grep -c "^$src_prefix\|$pwr_prefix")
match=$(echo "$event" | grep -c "^$src_prefix\|$pwr_prefix")
if [ "$match" -eq 1 ]; then
# clean the input
line=${line//[^a-zA-Z0-9]/}
event={$event}//[^a-zA-Z0-9]/}

# Pull in config-saved previous state of AVR. Supress output in case doesn't already exist
if [ ! -e $tmp ]
Expand All @@ -55,13 +54,13 @@ off_sleep=$(((off_duration+1000)/1000))
echo "[$(date "+%F %T")] Setting POWER=$POWER"

# Switch dependant on reult of power-query
# case "${line:0:2}:$line" in
case "$line" in
# case "$(echo $line|head -c2)" in
# case "{$event}:0:2}:$event" in
case "$event" in
# case "$(echo $event|head -c2)" in

# power is off
"$pwr_off")
echo "[$(date "+%F %T")] Power state changed: $line"
echo "[$(date "+%F %T")] Power state changed: $event"

# Visual effect, if wanted, to confirm power off
# Remember 1 is off, 0 is on
Expand All @@ -83,7 +82,7 @@ off_sleep=$(((off_duration+1000)/1000))

# power is on!
"$pwr_on")
echo "[$(date "+%F %T")] Power state changed: $line"
echo "[$(date "+%F %T")] Power state changed: $event"

# Remove the channel block by clearing selected channel
# Again suggested by tvdzwan, see above for link
Expand All @@ -105,26 +104,26 @@ off_sleep=$(((off_duration+1000)/1000))

# Invalid option, query or result must have failed
"$pwr_prefix"*)
echo "[$(date "+%F %T")] Power detection failed. Invalid option: $line"
echo "[$(date "+%F %T")] Power detection failed. Invalid option: $event"
;;

# Input specific config file: What each of these correspond to can be found on the github readme/wiki
"$src_prefix"*)

# Read previous input of amp from last query and see if changed, otherwise don't bother
if [ "$line" != "$INPUT" ]
if [ "$event" != "$INPUT" ]
then
echo "[$(date "+%F %T")] Input changed: $line"
echo "[$(date "+%F %T")] Input changed: $event"

# Input specific config availability, otherwise will default
if [[ "$line" =~ "$src_custom" ]]
if [[ "$event" =~ "$src_custom" ]]
then
# Check to see if a valid config file for switched input actually exists
if [ -e "${path_config}hyperion.config.${line}.json" ]
if [ -e "${path_config}hyperion.config.{$event}}.json" ]
then
# Change config file to input-specific one
echo "[$(date "+%F %T")] Switching to $line config file"
new_config="${path_config}hyperion.config.$line.json"
echo "[$(date "+%F %T")] Switching to $event config file"
new_config="${path_config}hyperion.config.$event.json"
else
# Input is setup but config file is not found, default it
echo "[$(date "+%F %T")] Input specific config file not found, switching to default"
Expand All @@ -151,12 +150,12 @@ off_sleep=$(((off_duration+1000)/1000))

# Write current input to config for next check
echo POWER=$POWER > $tmp
echo INPUT=$line >> $tmp
echo INPUT=$event >> $tmp
;;

# Nothing matched, somehow something unrecognised slipped through
*)
echo "[$(date "+%F %T")] Bad request, unsupported AVR code: $line"
echo "[$(date "+%F %T")] Bad request, unsupported AVR code: $event"
;;

esac
Expand Down

0 comments on commit 452c3e6

Please sign in to comment.