Denon AV Reciver - plugin

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Sunday 03 April 2016 18:18

Ah ok I defo don't have it installed. Maybe I need to install that but I think I have to install Apache also?


Sent from my iPhone using Tapatalk

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Denon AV Reciver - plugin

Post by Egregius » Sunday 03 April 2016 23:34

Not nescessary. You can run php from cli.
But with apache you can host php sites and that enables a lot of possibilities, leke my denon page etc.

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Sunday 03 April 2016 23:36

Going to backup install PHP5 soon. Once it is installed I should be able to run your script right? Thank you

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 20:45

Egregius wrote:Not nescessary. You can run php from cli.
But with apache you can host php sites and that enables a lot of possibilities, leke my denon page etc.

Ran your script mate and got this error, had a quick look and I can't make heads or tails out of it

First Error:-
pi@raspberrypi ~ $ php /home/pi/domoticz/scripts/Denon_Airplay_Check.php
PHP Parse error: syntax error, unexpected '');' (T_CONSTANT_ENCAPSED_STRING) in /home/pi/domoticz/scripts/Denon_Airplay_Check.php on line 14

I had two different ' in there and changed them and fixed that but now I get

pi@raspberrypi ~ $ php /home/pi/domoticz/scripts/Denon_Airplay_Check.php
PHP Notice: Undefined variable: ctx in /home/pi/domoticz/scripts/Denon_Airplay_Check.php on line 12

Got no idea how to fix that. Any ideas?

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 20:53

Dnpwwo wrote:simon_rb, the interface you have mentioned in your post is very functional and much easier to use programatically that the web interface which (IMHO) is complicated and slow.

I use that interface from a Denon AVR 4306 to turn the amp off & on and change input sources from a Python script and map functionality to a number of dummy devices
Untitled.jpg
calling the Python script is done from the selector device:
Untitled2.jpg
While this does not do exactly what you want you could trigger a script from a ping device.

The Python to control the device is pretty simple, this script controls power and source (and turns power on prior to setting source):

I plugin could be developed if there was sufficient demand
Just reading your code, all I need to do is query the PW? and act on the response with a virtual switch in Domoticz. Looks like your code could do this? Is am right?

Cheers

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 21:16

Egregious... Success! I thought I'd check Domoticz on the off chance and the dummy button had updated! Whoohoo! Still comes up with the error each time it runs but I'm sure I can get rid of that. But most importantly it works! Thank you.

Update:-
Added this which ignores the notice error

error_reporting( error_reporting() & ~E_NOTICE ).

Cheers
Last edited by simon_rb on Thursday 07 April 2016 21:19, edited 1 time in total.

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Denon AV Reciver - plugin

Post by Egregius » Thursday 07 April 2016 21:18

simon_rb wrote:
Egregius wrote: PHP Notice: Undefined variable: ctx in /home/pi/domoticz/scripts/Denon_Airplay_Check.php on line 12

Got no idea how to fix that. Any ideas?
Oops, didn't think of that.
It's a variable I have included in every PHP script I use:

Code: Select all

$ctx = stream_context_create(array('http'=>array('timeout' => 3,)));
Whithout that option file_get_contents has a extreme long timeout.

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 21:23

Ha, we messaged at the same time. Very thankful its working now as Its been a couple of years and I've always wanted to sort this little issue and now it is. The wife will love it.

Just adding it to a cron job then all should be good to go.

Thanks again!

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Denon AV Reciver - plugin

Post by Egregius » Thursday 07 April 2016 21:39

Once you get the cron up and running you can do lots of crazy stuff in just one file/script.
Glad I could help ;)

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 22:39

Egregius wrote:Once you get the cron up and running you can do lots of crazy stuff in just one file/script.
Glad I could help ;)
Cron job done - shame the amp doesn't turn itself off once the airplay connection is broken. But thats Denons fault. Just showed the wife how to play her music from her phone and she admits even she can do it. Happy days :)

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Denon AV Reciver - plugin

Post by Egregius » Thursday 07 April 2016 22:42

Isn't auto standby functioning for airplay?

http://IPDENON/SETUP/GENERAL/AUTOSTANDBY/f_general.asp

simon_rb
Posts: 711
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb » Thursday 07 April 2016 23:12

No, once the stream is terminated the amp stays on. I believe the auto standby only works as a timer 30 or 60 mins of no activity.

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Denon AV Reciver - plugin

Post by Egregius » Thursday 07 April 2016 23:54

I would think it goes to standby after 30 mins of no input. Never tried it. Maybe I will soon...

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Denon AV Reciver - plugin

Post by trixwood » Thursday 28 April 2016 1:00

Denon

TRiXWooD Scripts viewtopic.php?f=23&t=12145&p=87422#p87422


I have these scripts running with a lot of virtual devices for denon av1912. It will also run for any other denon, marantz if you change some value's. It's fun in progress. Almost had the bass/treble working. But a selector switch with more then 10 buttons does not work in Version: 3.4978 of domoticz.
still... have phun...

Update Changed it so it only updated values when changed... v0.2a
Update Fixed AirPlay & Mute bug v0.2b
Update v3 of script with volume Control can be found here http://domoticz.com/forum/viewtopic.php ... 421#p85421
Update example xml files from av1912 for comparison http://domoticz.com/forum/viewtopic.php ... =60#p91937, and domotixs had selector switches support!!! (thanks!)

Todo:
  • not write to filesystem first... (i'm still learning bash, day 3 ;-)
    tuner support?
    back menu button...
denon.telnet.sh

Code: Select all

#!/usr/bin/expect
set timeout 3
set dencmd [lindex $argv]
log_user 0

spawn telnet 10.0.0.91
expect "Trying"
expect {
  timeout {
    send_user "\rTimeout waiting for Denon response.\r"
    send_user "$expect_out(buffer)\r"
    exit
  }
  "Connection refused" {
    send_user "UNABLE\n"
    exit
  }
  "BridgeCo AG Telnet server\r\n"
}
send "$dencmd\r"
expect "$dencmd\r\n"
expect "*\r"
send_user "$expect_out(buffer)\n"
exit
you can telnet to the device example:

Code: Select all

./denon.telnet.sh PSBAS ?
gets the bas value (between 44 and 56)

Code: Select all

./denon.telnet.sh MV80
volume to 80... etc..

remember you can only use one telnet connection...!!!!

https://www.google.nl/search?q=protocol ... ocol+denon for descriptions or other controls...

Ok, now the basics... we want to get some value's like volume, source input, power status, airplay and we want some control, like source select, mute, standby, individual speaker volume control, the works. Preferably without telnet, due to the one connection restriction. So our first try ended up like this (bass/treble work in progress):
2.jpg
2.jpg (77.78 KiB) Viewed 4829 times
1.png
1.png (88.42 KiB) Viewed 4829 times
then my main script is

denon.sh
v0.2b fixed Airplay and Double Mute

New version here: http://domoticz.com/forum/viewtopic.php ... 421#p85421

Code: Select all

#!/bin/bash
#
# Domoticz Denon Script
# ---------------------
#
# Created 2016 Trixwood
#
# 0.1 first try
# 0.2 TC only update when needed
#
#
# to do: check if domoticz online else do not send anything
#
# Enable debug remove the # from the echo's (only volume uses echo... will change that todo ;-)

# Settings
DOMO_IP="10.0.0.1"            # Domoticz IP Address
DOMO_PORT="8090"              # Domoticz Port
DENONIP="10.0.0.91"           # Denon IP Address
DENON_IDX="155"               # On/Off    (Switch) IDX *1
DENON_STATUS_IDX="290"        # Status    (Text) IDX
DENON_MUTE_IDX="114"          # Mute      (Switch) IDX
DENON_VOL_REL_IDX="59"        # Relative Volume (Sound Volume) IDX
DENON_VOL_ABS_IDX="117"       # Absolute Volume (Slider) IDX
DENON_SURROUND_IDX="149"      # Surround  (Selector Switch) IDX
DENON_INPUT_IDX="133"         # Input     (Selector Switch) IDX *1
DENON_NET_INPUT_IDX="289"     # Net input (Text) IDX
DENON_AIRPLAY_IDX="150"       # Airplay?  (Switch)

# *1 You need additional virtual device which this one is a slave
# use ip for domoticz not the hostname, else password protection will fail…

# Selector Switches with 13 entries from -6db -5db .. -1db 0db .. 6db
#DENON_BASS_IDX="287"          # BASS (Selector Switch) IDX
#DENON_TREBLE_IDX="288"        # TREBLE (Selector Switch) IDX

# check if receiver in online
PINGTIME=`ping -c 1 -q $DENONIP | awk -F"/" '{print $5}' | xargs`

#
# Default Values
# todo only update when value changed... sleepy time now ;-)
#
function defaulting {

  #echo Defaulting...  
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_STATUS_IDX&nvalue=0&svalue=No%20Denon%20Detected" &> /dev/null
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_AIRPLAY_IDX&switchcmd=Off" &> /dev/null
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On" &> /dev/null
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off" &> /dev/null
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_VOL_REL_IDX&nvalue=0&svalue=-80.5" &> /dev/null
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_VOL_ABS_IDX&switchcmd=Set%20Level&level=0" &> /dev/null

}


# we can ping the machine
if expr "$PINGTIME" '>' 0
then

  # is there a denon?
  AVexists=$(curl -s http://$DENONIP/goform/formMainZone_MainZoneXml.xml | tee denon.mainzone.settings | grep "<Power><value>" &> /dev/null)
  
  # yes!
  if [ $? -eq 0 ] ; then
    
    #
    # Airplay
    # -------
    #
    # 

    # decode new value
    curl -s http://$DENONIP/goform/formNetAudio_StatusXml.xml > denon.net.settings
    AVairplay=$(grep -Eo "AirPlay" < denon.net.settings)
    

    # decode old value
    AVairplayold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_AIRPLAY_IDX" | grep Status)
    AVairplayold=${AVairplayold##*Status\" : \"}
    AVairplayold=${AVairplayold//\",/}

    #echo "Airplay: $AVairplay ($AVairplayold)" 

    if [ "$AVairplay" == "AirPlay" ]; then
      if [ "$AVairplayold" == "Off" ] ; then
        #echo "Airplay: Switching On"
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_AIRPLAY_IDX&switchcmd=On" &> /dev/null
      fi 
    else
    if [ "$AVairplayold" == "On" ] ; then
        #echo "Airplay: Switching Off"
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_AIRPLAY_IDX&switchcmd=Off" &> /dev/null
      fi 
    fi


    #
    # Volume
    # ----------
    #
    # Note that Denon Can So 0.5 steps of Decibel is set to Relative that means with relative you have twice the amount of resolution
    # So resolution will be lost if your denon is set to relative volume since the slider only half the resolution and sound volume 
    # does not have half steps
    # 
    # Range Relative -80.5 dB to +18
    #       Absolute 0..99
    #
    # that will not convert well :-/

    # decode new value
    AVisvolumerelative=$(sed -n -e 's/.*\<VolumeDisplay><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    AVvolume=$(sed -n -e 's/.*\<MasterVolume><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)

    # compensate for Denon Volume setting    
    if [ "$AVisvolumerelative" == "Relative" ] ; then
      #echo "Volume: Relative"
      AVvolumeAbs=$(echo "80.5 + $AVvolume" | bc) 
      AVvolumeRel=$AVvolume
    else
      #echo "Volume: Absolute"
      AVvolumeRel=$(echo "80.5 - $AVvolume" | bc) 
      AVvolumeAbs=$AVvolume
    fi

    # exterminate, exterminate, convert... convert...
    AVvolumeAbs=$((${AVvolumeAbs//\./}/10))

    # decode old value
    AVvolumeoldAbs=$(($(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_VOL_ABS_IDX" | grep Data | grep -Eo '[0-9]{1,4}')+1))
 
    #echo "Volume: $AVvolumeRel db $AVvolumeAbs ($AVvolumeoldAbs)" 

    # only switch when value is changed
    if [ "$AVvolumeAbs" != "$AVvolumeoldAbs" ]; then
      #echo "Volume: Switching $AVvolumeRel db $AVvolumeAbs"
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_VOL_REL_IDX&nvalue=0&svalue=$AVvolumeRel" &> /dev/null
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_VOL_ABS_IDX&switchcmd=Set%20Level&level=$AVvolumeAbs" &> /dev/null
    fi  

    #
    # Net Source
    # ----------
    #
    # 

    # decode new value
    AVnet=$(sed -n -e 's/.*\<NetFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)

    # decode old value
    AVnetold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_NET_INPUT_IDX" | grep Data)
    AVnetold="${AVnetold##*Data\" : \"}"
    AVnetold=${AVnetold//\",/}

    #echo "Net Input: $AVnet ($AVnetold)" 

    # only switch when value is changed
    if [ "$AVnet" != "$AVnetold" ]; then
      #echo "Net Input: Switching $AVnet"
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_NET_INPUT_IDX&nvalue=0&svalue=$AVnet" &> /dev/null
    fi

    #
    # Source Input
    # ------------
    #

    # decode new value
    AVinput=$(sed -n -e 's/.*\<InputFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    # AVswitchlevel=0
    if [ "$AVinput" == "GAME" ] ; then
      AVswitchlevel=10
    fi
    if [ "$AVinput" == "GAME2" ] ; then
      AVswitchlevel=20
    fi
    if [ "$AVinput" == "TUNER" ] ; then
      AVswitchlevel=30
    fi
    if [ "$AVinput" == "DVD" ] ; then
      AVswitchlevel=40
    fi
    if [ "$AVinput" == "SAT" ] ; then
      AVswitchlevel=50
    fi
    if [ "$AVinput" == "BD" ] ; then
      AVswitchlevel=60
    fi
    if [ "$AVinput" == "TV" ] ; then
      AVswitchlevel=70
    fi
    if [ "$AVinput" == "CD" ] ; then
      AVswitchlevel=80
    fi
    if [ "$AVinput" == "V.AUX" ] ; then
      AVswitchlevel=100
    fi
    if [ "$AVinput" == "DOCK" ] ; then
      AVswitchlevel=110
    fi
    if [ "$AVinput" == "SOURCE" ] ; then
      AVswitchlevel=120
    fi
    if [ "$AVinput" == "NET/USB" ] ; then
      AVswitchlevel=90
    fi

    # decode old value
    AVinputold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_INPUT_IDX" | grep Status | grep -Eo '[0-9]{1,4}' )
    #echo "Input: $AVswitchlevel ($AVinputold)" 

    # only switch when value is changed
    if [ "$AVswitchlevel" != "$AVinputold" ]; then
      #echo "Input: Switching $AVinput"
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_INPUT_IDX&switchcmd=Set%20Level&level=$AVswitchlevel" &> /dev/null
    fi

    #
    # Surround
    # --------
    #

    # decode new value
    AVsurround=$(sed -n -e 's/.*\<selectSurround><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings | sed -e 's/[[:space:]]*$//') 
    if [ "$AVsurround" == "STEREO" ] ; then
      AVswitchlevel=10
    fi
    if [ "$AVsurround" == "DIRECT" ] ; then
      AVswitchlevel=20
    fi
    if [ "$AVsurround" == "DOLBY DIGITAL" ] ; then
      AVswitchlevel=40
    fi
    if [ "$AVsurround" == "PURE DIRECT" ] ; then
      AVswitchlevel=30
    fi
    if [ "$AVsurround" == "DTS SURROUND" ] ; then
      AVswitchlevel=50
    fi
    if [ "$AVsurround" == "MCH STEREO" ] ; then
      AVswitchlevel=60
    fi
    if [ "$AVsurround" == "MONO MOVIE" ] ; then
      AVswitchlevel=70
    fi
    if [ "$AVsurround" == "VIDEO GAME" ] ; then
      AVswitchlevel=80
    fi
    if [ "$AVsurround" == "JAZZ CLUB" ] ; then
      AVswitchlevel=90
    fi
    if [ "$AVsurround" == "ROCK ARENA" ] ; then
      AVswitchlevel=100
    fi
    if [ "$AVsurround" == "VIRTUAL" ] ; then
      AVswitchlevel=110
    fi
    if [ "$AVsurround" == "MATRIX" ] ; then
      AVswitchlevel=120
    fi

    # decode old value
    AVsurroundold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_SURROUND_IDX" | grep Status | grep -Eo '[0-9]{1,4}' )
    #echo "Surround: $AVswitchlevel ($AVsurroundold)" 

    # only switch when value is changed
    if [ "$AVswitchlevel" != "$AVsurroundold" ]; then
      #echo "Surround: Switching $AVsurround"
      curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_SURROUND_IDX&switchcmd=Set%20Level&level=$AVswitchlevel" &> /dev/null
    fi

    #
    # Status
    # ------
    #

    # decode new value
    AVstatus=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)

    # decode old value
    AVstatusold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_IDX" | grep Status)
    AVstatusold="${AVstatusold##*Status\" : \"}"
    AVstatusold=${AVstatusold//\",/}
        
    #echo "Power: $AVstatus ($AVstatusold)"

    # only switch when value is changed
    if [ "$AVstatus" == "ON" ] && [ "$AVstatusold" == "Off" ] ; then
      #echo "Power: Switching On"
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=On" &> /dev/null
    fi

    if [ "$AVstatus" == "STANDBY" ] && [ "$AVstatusold" == "On" ] ; then
      #echo "Power: Switching Off"
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off" &> /dev/null
    fi

    if ([ "$AVstatus" == "ON" ] && [ "$AVstatusold" == "Off" ]) || ([ "$AVstatus" == "STANDBY" ] && [ "$AVstatusold" == "On" ]) ; then
       #echo "Power: Status Updated"
       curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_STATUS_IDX&nvalue=0&svalue=$AVstatus" &> /dev/null
    fi

    #
    # Mute
    # ----
    #
   
    # decode new value
    AVmute=$(sed -n -e 's/.*\<Mute><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)

    # decode old value
    AVmuteold=$(curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$DENON_MUTE_IDX" | grep "Status")
    AVmuteold="${AVmuteold##*Status\" : \"}"
    AVmuteold=${AVmuteold//\",/}

    #echo "Mute: $AVmute ($AVmuteold)"
    
    # only switch when value is changed
    if [ "$AVmute" == "off" ] && [ "$AVmuteold" == "On" ] ; then
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=Off" &> /dev/null
      #echo "Mute: Switching Off"
    fi
    if [ "$AVmute" == "on" ] && [ "$AVmuteold" == "Off" ] ; then
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On" &> /dev/null
      #echo "Mute: Switching On"
    fi

    #
    # Cleaning Up
    #

    #rm denon.mainzone.settings
    #rm denon.net.settings


 # Bass
 #   AVbass=$(./denon.telnet.sh PSBAS ? | sed 's/PSBAS //' | grep -Eo '[0-9]{1,4}')
 #   AVbass=$(((AVbass-43)*10)) 
 # if [ "$AVbass" == "-430" ] ; then
 #    #echo ""
 # else
 #   curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_BASS_IDX&switchcmd=Set%20Level&level=$AVbass" &> /dev/null
 # fi 
 # only one telnet allowed :-/
 #  sleep 2
 # Treble
 #    AV=$(./denon.telnet.sh PSTRE ?)
 ##echo $AV
 # sleep 2
 #   AVtreble=$(./denon.telnet.sh PSTRE ? | sed 's/PSTRE //' | grep -Eo '[0-9]{1,4}')
 #   AVtreble=$(((AVtreble-43)*10))
 #   if [ "$AVtreble" == "-430" ] ; then
 #      #echo ""
 #   else
 #   curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_TREBLE_IDX&switchcmd=Set%20Level&level=$AVtreble" &> /dev/null

 #  fi 

  else
    # no denon xml from http server do something!
    defaulting 
  fi
else
  # we could not even ping it defaulting
  defaulting  
fi

Old code: v0.1

Code: Select all

#!/bin/bash

 # Settings

DENONIP="10.0.0.91"           # Denon IP Address

# ip not host, else password protection will fail…

DOMO_IP="10.0.0.1"         # Domoticz IP Address
DOMO_PORT="8090"              # Domoticz Port

DENON_IDX="155"                # On/Off (Switch) IDX *1
DENON_MUTE_IDX="114"          # Mute (Switch) IDX
DENON_VOL_REL_IDX="59"        # Relative Volume (Sound Volume) IDX
DENON_VOL_ABS_IDX="117"       # Absolute Volume (Slider) IDX
DENON_SURROUND_IDX="149"      # Surround (Selector Switch) IDX
DENON_INPUT_IDX="133"         # Input (Selector Switch) IDX *1
DENON_NET_INPUT_IDX="115"     # Net input (Text) IDX
DENON_STATUS_IDX="62"         # Status (Text) IDX
DENON_AIRPLAY_IDX="150"       # Airplay? (Switch)


# Selector Switches with 13 entries from -6db -5 .. -1db 0db 1db 2db ... 6db
DENON_BASS_IDX="287"          # BASS (Selector Switch) IDX
DENON_TREBLE_IDX="288"          # TREBLE (Selector Switch) IDX

# *1 You need two!!! of these virtual sensors to work!!!

# check if receiver in online
PINGTIME=`ping -c 1 -q $DENONIP | awk -F"/" '{print $5}' | xargs`

# we can ping the machine
if expr "$PINGTIME" '>' 0
then

  # is there a denon?
  AVexists=$(curl -s http://$DENONIP/goform/formMainZone_MainZoneXml.xml | tee denon.mainzone.settings | grep "<Power><value>" &> /dev/null)
  if [ $? -eq 0 ] ; then
    
    curl -s http://$DENONIP/goform/formNetAudio_StatusXml.xml > denon.net.settings
    AVairplay=$(grep "AirPlay" < denon.net.settings)
    if [ $? -eq 0 ] ; then
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_AIRPLAY_IDX&switchcmd=On" &> /dev/null
    else
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_AIRPLAY_IDX&switchcmd=Off" &> /dev/null
    fi

    # Volume
    AVisvolumerelative=$(sed -n -e 's/.*\<VolumeDisplay><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    AVvolume=$(sed -n -e 's/.*\<MasterVolume><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    if [ "$AVisvolumerelative" == "Relative" ] ; then
      AVvolumeAbs=$(echo "80 + $AVvolume" | bc) 
      AVvolumeRel=$AVvolume
    else
      AVvolumeRel=$(echo "80 - $AVvolume" | bc) 
      AVvolumeAbs=$AVvolume
    fi
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_VOL_REL_IDX&nvalue=0&svalue=$AVvolumeRel" &> /dev/null
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_VOL_ABS_IDX&switchcmd=Set%20Level&level=$AVvolumeAbs" &> /dev/null
    
    # Bass

    AVbass=$(./denon.telnet.sh PSBAS ? | sed 's/PSBAS //' | grep -Eo '[0-9]{1,4}')
    AVbass=$(((AVbass-43)*10)) 

    if [ "$AVbass" == "-430" ] ; then
       echo ""
    else

    curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_BASS_IDX&switchcmd=Set%20Level&level=$AVbass" &> /dev/null

    fi 
    # only one telnet allowed :-/
    sleep 3

    # Treble
#    AV=$(./denon.telnet.sh PSTRE ?)
#echo $AV

 sleep 3



    AVtreble=$(./denon.telnet.sh PSTRE ? | sed 's/PSTRE //' | grep -Eo '[0-9]{1,4}')
    AVtreble=$(((AVtreble-43)*10))
    if [ "$AVtreble" == "-430" ] ; then
       echo ""
    else
    curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_TREBLE_IDX&switchcmd=Set%20Level&level=$AVtreble" &> /dev/null
    fi 
  

    # Net Source
    AVnet=$(sed -n -e 's/.*\<NetFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_NET_INPUT_IDX&nvalue=0&svalue=$AVnet" &> /dev/null

    # Input
    AVinput=$(sed -n -e 's/.*\<InputFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    # AVswitchlevel=0
    if [ "$AVinput" == "GAME" ] ; then
      AVswitchlevel=10
    fi
    if [ "$AVinput" == "GAME2" ] ; then
      AVswitchlevel=20
    fi
    if [ "$AVinput" == "TUNER" ] ; then
      AVswitchlevel=30
    fi
    if [ "$AVinput" == "DVD" ] ; then
      AVswitchlevel=40
    fi
    if [ "$AVinput" == "SAT" ] ; then
      AVswitchlevel=50
    fi
    if [ "$AVinput" == "BD" ] ; then
      AVswitchlevel=60
    fi
    if [ "$AVinput" == "TV" ] ; then
      AVswitchlevel=70
    fi
    if [ "$AVinput" == "CD" ] ; then
      AVswitchlevel=80
    fi
    if [ "$AVinput" == "V.AUX" ] ; then
      AVswitchlevel=100
    fi
    if [ "$AVinput" == "DOCK" ] ; then
      AVswitchlevel=110
    fi
    if [ "$AVinput" == "SOURCE" ] ; then
      AVswitchlevel=120
    fi
    if [ "$AVinput" == "NET/USB" ] ; then
      AVswitchlevel=90
    fi
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_INPUT_IDX&switchcmd=Set%20Level&level=$AVswitchlevel" &> /dev/null

    # Surround
    AVsurround=$(sed -n -e 's/.*\<selectSurround><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings | sed -e 's/[[:space:]]*$//') 
    if [ "$AVsurround" == "STEREO" ] ; then
      AVswitchlevel=10
    fi
    if [ "$AVsurround" == "DIRECT" ] ; then
      AVswitchlevel=20
    fi
    if [ "$AVsurround" == "DOLBY DIGITAL" ] ; then
      AVswitchlevel=40
    fi
    if [ "$AVsurround" == "PURE DIRECT" ] ; then
      AVswitchlevel=30
    fi
    if [ "$AVsurround" == "DTS SURROUND" ] ; then
      AVswitchlevel=50
    fi
    if [ "$AVsurround" == "MCH STEREO" ] ; then
      AVswitchlevel=60
    fi
    if [ "$AVsurround" == "MONO MOVIE" ] ; then
      AVswitchlevel=70
    fi
    if [ "$AVsurround" == "VIDEO GAME" ] ; then
      AVswitchlevel=80
    fi
    if [ "$AVsurround" == "JAZZ CLUB" ] ; then
      AVswitchlevel=90
    fi
    if [ "$AVsurround" == "ROCK ARENA" ] ; then
      AVswitchlevel=100
    fi
    if [ "$AVsurround" == "VIRTUAL" ] ; then
      AVswitchlevel=110
    fi
    if [ "$AVsurround" == "MATRIX" ] ; then
      AVswitchlevel=120
    fi
    curl  -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_SURROUND_IDX&switchcmd=Set%20Level&level=$AVswitchlevel" &> /dev/null

    # Status
    AVstatus=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)
    if [ "$AVstatus" == "ON" ] ; then
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=On" &> /dev/null
    else
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off" &> /dev/null
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On" &> /dev/null
    fi
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_STATUS_IDX&nvalue=0&svalue=$AVstatus" &> /dev/null
  
    # Mute
    AVmute=$(sed -n -e 's/.*\<Mute><value>\(.*\)<\/value>.*/\1/p' denon.mainzone.settings)

   echo $AVStatus
  
   if [ "$AVmute" == "off" ] ; then
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=Off" &> /dev/null
     else
      curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On" &> /dev/null
    fi

    #rm denon.mainzone.settings
    #rm denon.net.settings
  else
    # no denon xml from http server do something!
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_STATUS_IDX&nvalue=0&svalue=No%20Denon%20Detected" &> /dev/null
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On" &> /dev/null
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off" &> /dev/null
  fi
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off" &> /dev/null
fi
You have to configure the virtual devices, change the ip addresses and port to the correct ones and set the correct id's before running, also the AVsurround variable can contain different text if you do not have an 1912 model. Just get the correct value's by entering this address in your browser (replace the ip 10.0.0.91 with the ip of your denon stereo) http://10.0.0.91/goform/formMainZone_MainZoneXml.xml

Note that the script does not care if your denon is setup with relative or absolute volume (-80db .. 18db, or 0 ..100)
For the input selector and the power on/off switch you need two virtual devices. A status one which receives the status from the script and another selector set up like this:
3.jpg
3.jpg (221.39 KiB) Viewed 4829 times
Use ON or OFF with capitals, I know one is not showing, you make more screenshot ;-) Why? because with one virtual switch the denon keeps switching on/off/on/off.... Sub/Slave Devices solves it! The virtual devices are just clones of each other, with the status one receiving the status from the script and due to the slave position it update the Denon Power switch, but NOT trigger its On/Off Actions. The scripts runs every 10 seconds using cron or launchcontrol. On OSX install the following launchagent in /Library/LaunchAgents or ~/Library/LaunchAgents. Change the domoticz installed folder to your own folder instead of /Users/Trixwood/Smarthome/. For OSX use http://www.soma-zone.com/LaunchControl

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.domoticz.denon</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/Trixwood/Smarthome/domoticz/scripts/denon.sh</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>15</integer>
	<key>WorkingDirectory</key>
	<string>/Users/Trixwood/Smarthome/domoticz/scripts</string>
</dict>
</plist>
Improvements
Not using the disk as cache but memory to store the xml. This wil probably wear some kb down with constant read and write. If there is anybody good in bash script please let me know how to pipe, cat, grep or whatever to do the same without writing it to disk...

more command and url to use
https://knx-user-forum.de/forum/support ... ng-steuern
http://www.openremote.org/display/docs/ ... TP+Control
Last edited by trixwood on Thursday 28 July 2016 11:34, edited 25 times in total.

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Denon AV Reciver - plugin

Post by trixwood » Thursday 28 April 2016 1:35

Mute Control

The other is on (instead of off)
4.png
4.png (242.71 KiB) Viewed 4828 times
The Denon Input Selector (don't forget you need a clone of this one without the level actions called Denon Input Status, and set the subslave from this to that one (as in pic), and refer in the script only to the denon input status , else it will keep switching...

Also no 1912? Change to the correct inputs!!! Same as surround...
6.jpg
6.jpg (239.19 KiB) Viewed 4828 times
5.jpg
5.jpg (173.45 KiB) Viewed 4828 times
Last edited by trixwood on Thursday 28 April 2016 6:58, edited 1 time in total.

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Denon AV Reciver - plugin

Post by trixwood » Thursday 28 April 2016 1:40

9.jpg
9.jpg (188.75 KiB) Viewed 4826 times
8.jpg
8.jpg (68.07 KiB) Viewed 4826 times
Think i forgot the back button....
7.jpg
7.jpg (203.58 KiB) Viewed 4826 times
you also need to set this up for the menu selector... makes the other menu go away (or you are stuck in it)

denon.menu.input.sh

Code: Select all

#!/bin/bash
curl -s http://stereo.local/goform/formiPhoneAppDirect.xml?MNMEN%20OFF
sleep 0.5
curl -s http://stereo.local/goform/formiPhoneAppDirect.xml?MNSRC%20ON
denon.menu.setup.sh

Code: Select all

#!/bin/bash
curl -s http://stereo.local/goform/formiPhoneAppDirect.xml?MNMEN%20OFF
sleep 0.5
curl -s http://stereo.local/goform/formiPhoneAppDirect.xml?MNMEN%20ON
Last edited by trixwood on Thursday 28 April 2016 6:52, edited 1 time in total.

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Denon AV Reciver - plugin

Post by trixwood » Thursday 28 April 2016 1:42

Surround Menu/Switches
surround.jpg
surround.jpg (178.88 KiB) Viewed 4823 times
surround2.jpg
surround2.jpg (214.74 KiB) Viewed 4823 times
Remember, get the correct value's by entering this address in your browser (replace the ip 10.0.0.91 with the ip of your denon stereo) http://10.0.0.91/goform/formMainZone_MainZoneXml.xml, match them with the correct command

Thanks to the original poster of the denon source

viewtopic.php?f=23&t=5685&start=40#p69692

which I used as base for the modifications! Still it needs a proper plugin... should also work with marantz... anyway with the telnet and all the url you need you can add anything you want... still feels like openhab editing/script hacking everything...

User avatar
gielie
Posts: 239
Joined: Tuesday 12 January 2016 12:40
Target OS: Raspberry Pi
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Denon AV Reciver - plugin

Post by gielie » Thursday 28 April 2016 21:30

WoW trixie that is realy nice work.
I have one dumb question, I recently switched from synology to raspberry pi and on my synology it was really easy to run bash scripts but how do I do that on a pi?
- Vision ZU1401 USB Stick
- Aeotec MultiSensor 6
- FIBARO FGS222
- FIBARO FGWPE Wall Plug
- Everspring AN157
- Neo CoolCam Power plug
- Neo CoolCam PIR Sensor
- Popp Smoke Detector
- Toon
- Kodi Media Server

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Denon AV Reciver - plugin

Post by trixwood » Thursday 28 April 2016 22:14

A script is just a text file with the +x (execution) bit set.
I have no Pi but using ssh to either upload the textfile and set the execution with through the an ssh terminal session or create it using an editor on the pi and set its execution bit.

You probably want to look around in the Pi documentation
https://www.raspberrypi.org/documentati ... ccess/ssh/
https://www.raspberrypi.org/documentati ... ripting.md

When you logged using ssh into your pi try running this (assuming your domoticz is in installed in the your users home folder)

Code: Select all

cd ~/domoticz/scripts
touch denon.sh
chmod +x denon.sh
nano denon.sh
  • This will create the file (touch)
    Set the execution bit (chmod)
    And open up an editor (nano) in which I usually paste the text of the script into. Ctrl-x to save and you're should be good.
To run it

Code: Select all

cd ~/domoticz/scripts
./denon.sh
in domotics the script now can be executed with script://denon.sh

You will run into this later on:
Some text editors and some webpages copy extra characters (like not 8 bit but 16bit unicode or special language chars) or change quotes "normal quotes" to “Smart quotes” , which are total different characters. You do not want that. That is why scripts sometimes fails... bad text conversion.
TextEdit from OSX does that for example, you should disable smartquotes there by default.
Last edited by trixwood on Thursday 28 April 2016 22:42, edited 2 times in total.

User avatar
gielie
Posts: 239
Joined: Tuesday 12 January 2016 12:40
Target OS: Raspberry Pi
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Denon AV Reciver - plugin

Post by gielie » Thursday 28 April 2016 22:21

Thanks, that clear.
But now your Denon.sh script, do you run that with cron or manually via a switch?
- Vision ZU1401 USB Stick
- Aeotec MultiSensor 6
- FIBARO FGS222
- FIBARO FGWPE Wall Plug
- Everspring AN157
- Neo CoolCam Power plug
- Neo CoolCam PIR Sensor
- Popp Smoke Detector
- Toon
- Kodi Media Server

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests