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.

Moderators: leecollings, remb0

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

Re: Denon AV Reciver - plugin

Post by simon_rb »

I would love to help you but I've not even had time to play with it myself yet. I think a lot of it depends on all the values being correct in the .xml files. Carefully read through the thread, @trixwood has documented most of it, trial and error! Good luck!
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

baekmark wrote:Hi all

I'm new to Domoticz, but I'm getting there

I have been following this thread the last two month, and I have a Denon AVR-3312 that I would like to integrate into my Domoticz server.

My first question is, how to add the Virtual switches that is shown in this thread?

I like to see something like this.
1) Setup -- Add hardware how to etc
2) add Virtual switches How to
3) Where to place files
4) First Switch "PowerStatus" of Denon

I'm using Ubuntu 16.04 64bit

@trixwood, get well soon

Thanx in advance
Most of it is stuff that is more basic to domoticz the specific to Denon.

Screen Shot 2016-08-29 at 15.21.55.png
Screen Shot 2016-08-29 at 15.21.55.png (76.96 KiB) Viewed 3525 times


You can add virtual switches in SETUP->HARDWARE menu and select dummy hardware from the list. Name it "Denon" Add.
You now see new hardware "Denon" in the list which has a button "create virtual sensors"

Click on it, select your type... and then add...

Now move over to the SWITCHES menu. Since you can NOT edit sensors in the devices section....
Screen Shot 2016-08-29 at 15.25.46.png
Screen Shot 2016-08-29 at 15.25.46.png (24.49 KiB) Viewed 3525 times
Press edit.. will in the commands...
Screen Shot 2016-08-29 at 15.26.59.png
Screen Shot 2016-08-29 at 15.26.59.png (147.73 KiB) Viewed 3525 times
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

I have the script under...

Code: Select all

/domoticz/scripts/
Make sure in the denon.sh to remove all

Code: Select all

&> /dev/null
And you will have to edit it... the 33xx has other multisurround options to begin with...
if you have another model working please post your scripts here.. call it denon33xx.sh or denon1920.sh...

And i still have to fix it sometimes looses state... ik works ok for 3 weeks, then it refuses to in stay standby... but it also could be the cec or just the receiver itself...

But I am just as you, playing with it... in the beginning I had no idea what I was doing... and I really do not like to get stuck... it demotivating. that why i have 7 little projects which I alternate... learning stuff from one, putting it to use in another...
and this is one of my first...

In the winter I hope(!) to update, the philips hue scripts and the denon scripts.... with the iKettle i figured out to create the virtual switches from the scripts itself... so no more setup is needed. You just run the script and it just works... (like adding hardware, but then from a python script)...

I still can not figure out how to write hardware plugins itself. The code is too large, and the help how to do that is crap, well I got stuck adding it the the html...

Anyway... for now!

(I also lost interrest in the denon which I use solely for playing music, after using a http://chordelectronics.co.uk/mojo/ and some really, really good headphones...) If you want to ruin every other device you have which plays music... then test that with for example bayerndynamics headphones... with some lossless music, you hear stuff you never heard before in your music.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

trixwood wrote:In the winter I hope(!) to update, the philips hue scripts and the denon scripts.... with the iKettle i figured out to create the virtual switches from the scripts itself... so no more setup is needed. You just run the script and it just works... (like adding hardware, but then from a python script)...
Excellent! I only need the Absolute volume control for my Denon and dynamically grabs the volume if its changed on the receiver itself.. I was going to add your script (As you are aware I was speaking to you before). Reason I would like it is for use with Homebirdge/eDomoticz. This way I can just say set volume to whatever I like and have a volume slider on my Watch. I currently use a homebridge plugin for my Denon but would rather have it within Domoticz..

Good luck with the script.. I'd love to test if you get around to it :D
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

Got the volume control working rather easily which was surprising for me - a credit to the script.

Question I have is if there is a way to grab the volume of the amp say every minute and update the Denon Volume accordingly - this will keep the volume in sync. Maybe a LUA time script that sends the values to the virtual Denon Volume dimmer?

Cheers :)
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

for that I use:

viewtopic.php?f=31&t=11011&hilit=denon&start=40#p85421

The script is designed to update domoticz virtual sensors with the denon information retrieved from the xml files available from the denon av receiver. But every model is different so the text in the xml file differs and you have to adapt it to your model and domoticz setup. You can comment out which information you do not use. And if you run it in a cron job (or something simular) you can run it in the background every 2-3 seconds. Which gives in domoticz an almost realtime state of the av receiver. It takes some time to setup. And you have to pick the right virtual sensor types. But it works nicely.

Anyway if you have bugs or a modified version of your model post it here. :-)
Last edited by trixwood on Saturday 12 November 2016 1:32, edited 1 time in total.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

trixwood wrote:for that I use:

viewtopic.php?f=31&t=11011&hilit=denon&start=40#p85421

and put it an a launchdeamon (on osx) or a cron job on a raspberry pi, called every 2 or 3 seconds... which updates the volume, its not perfect, but it works. Still have to change the script to match your model and domoticz setup...
Sorry, I didn't realise that your script actually gets volume feedback from the Denon amp? I didn't realised. I'll take a look!! Cheers

Update:- Sorry, was using tapatalk on iPhone and missed the actual script - setting it up now, cheers!!!!

Update 2:- I already had that setup but I had set it up as a device rather than a time script. I have it now but my amp as absolute volume, does that matter?

Update 3:- Promise this is last update, I get nil value within Domoticz logs, the IP address is correct..

Code: Select all

commandArray = {} 

-- very laze here assume relative volume setting on the denon amp...

IP = '192.168.1.12'

if devicechanged['Denon Volume'] then 
  NewLevel = otherdevices_svalues['Denon Volume'] 
  if NewLevel ~= "Off" and NewLevel ~= "0" then  
    SendLevel = NewLevel - 79.5
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutSystem_OnStandby%2FON")
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutVolumeMute%2Foff")    
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
  end
end 
return commandArray
Last edited by simon_rb on Saturday 12 November 2016 1:35, edited 1 time in total.
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

I did not test it with absolute. Also it have less range (fewer steps) to choose from. If it does not work with absolute. You can change it on the denon on screen menu (somewhere ;-)
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

Do not set it up as an time or device script inside domoticz... (domoticz time is i thought every 30 seconds??? i forgot so the update is slow, and on every device change is a lot of calls to the script and it will choke the denon)
Run it with a cron job in the background (or something simular on your operating system), such that you can choose the delay time yourself.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

I think we are getting confused. The scripts you have just linked me to they send the volume from the virtual dimmer to the Denon Amp. I am trying to get the virtual dimmer (Denon Volume) to be updated from the Denon Amp. So if the Denon amp is changed then it will update the Denon Volume dimmer within domoticz with the value from the Denon Amp? Make sense? lol
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

The nil is probably relative absolute untested stuff. I have no idea, no crystal ball ;-) I would suggest changing that to relative as that I tested on my own system. And to debug use "print" a lot to see it stuff has values as you expect. :-)
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

trixwood wrote:The nil is probably relative absolute untested stuff. I have no idea, no crystal ball ;-) I would suggest changing that to relative as that I tested on my own system. And to debug use "print" a lot to see it stuff has values as you expect. :-)
Does your script get the volume status from the amp and update the virtual dimmer if its different?

I have it working where I set the "Denton Volume" (Virtual dimmer in domoticz) and it updates the Denon Amps volume. However does it work the other way around? If the Denon Amp volume is changed physically using the Denon Amp volume knob on the front of the amp, will your script update the Denon Volume dimmer inside Domoticz?
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

Ok... to be sure....

my denon scripts start here:

viewtopic.php?f=31&t=11011&start=20#p84408

which has a denon.telnet.sh and a old version without volume of denon.sh (

then it continues with long post on setting up the virtual sensors and action url/scripts...

this post contains some info on the cron job:

viewtopic.php?f=31&t=11011&start=40#p84487

this post is the volume part:

viewtopic.php?f=31&t=11011&start=40#p85421

with an updated denon.sh (seconds piece of code) which you should adapt to your model xml files and your domoticz setup and run in the cron job.

and you where right! a piece of device event inside domoticz... (only relative as the comment in the code said... have no idea what it does... something to do with mute or... i suggest first try it without it... see what happens...)

:-)

It works both ways, change volume or any other control you set up in domoticz and it changes it on the amp... (all the on action, off action of the virtual sensors see viewtopic.php?f=31&t=11011&start=20#p84411 as example) and change the amp and it changes the volume in domoticz... or other controls like hdmi input, mute... (this due to denon.sh updating it in the background) And almost real time...

step 1 is setting up the virtual sensors... with the proper url for the actions, you can test the actions if they work...

step 2 is getting the xml files from the denon (see for url inside denon.sh) and look if the text inside is compatible with the script and comment out things you do not use (or add thing you want to use like radio, or like i did, bass and treble control using denon.telnet.sh as on action script and added reading out the values to denon.sh). (i suggest commenting out a lot at first and test the basic stuff like on/off and add and test incremental). use a lot of print ;-) you can run the script once and see if any virtual sensor is updated... or any errors...
step 3 if all works... put it in a cron job...
step 4 enjoy...

I have to set it up for myself soon (since i started over with a pi)... i maybe make lots of screenshots for a wiki...
Last edited by trixwood on Saturday 12 November 2016 2:15, edited 1 time in total.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

Excellent - thank you. Clearer now :D

Do I need the Telnet stuff? Or for volume feedback do I only need these two:-

denon.sh - Runs every minute via cron (If I run this script via command line I get just 1 then exits

Code: Select all

#!/bin/bash
#
# Domoticz Denon Script
# ---------------------
#
# Created 2016 Trixwood
#
# 0.1 first try
# 0.2 TC only update when needed
# 0.3 Mute & Volume feature
#
#
# 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="192.168.1.26"            # Domoticz IP Address
DOMO_PORT="8080"              # Domoticz Port
DENONIP="192.168.1.12"           # Denon IP Address
#DENON_IDX="155"               # On/Off    (Switch) IDX *1
#DENON_STATUS_IDX="290"        # Status    (Text) IDX
DENON_MUTE_IDX="284"         # Absolute Volume (Slider) IDX (same as Absolute Volume)
DENON_VOL_REL_IDX="59"        # Relative Volume (Sound Volume) IDX
DENON_VOL_ABS_IDX=“284”       # 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

    #
    # 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" == "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=Off" &> /dev/null
      #echo "Mute: Switching On"
    fi
    if [ "$AVmute" == "off" ] && [ "$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 Off"
    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 [ "$AVvolume" == "--" ] ; then
          AVvolume="0"
          AVisvolumerelative="Infinity"
     fi
   
    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 [ "$AVmute" == "off" ] && [ "$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  
  
# CHECK FOR OLD VALUE FIRST!!!! FIX FIX  
     if [ "$AVmute" == "on" ] ; then
       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


    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



    #
    # 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
script_device_denon_volume.lua - Which updates the Denon Amp with the Volume from the Denon Volume dimmer/slide in domoticz

Code: Select all

commandArray = {} 

-- very laze here assume relative volume setting on the denon amp...

IP = '192.168.1.12'

if devicechanged['Denon Volume'] then 
  NewLevel = otherdevices_svalues['Denon Volume'] 
  if NewLevel ~= "Off" and NewLevel ~= "0" then  
    SendLevel = NewLevel - 80
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutSystem_OnStandby%2FON")
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutVolumeMute%2Foff")    
    os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
  end
end 
return commandArray
Above two scripts are what I have now. The Denon Volume switch updates my amps volume just fine. I don't get it the other way around though :(
I have changed to relative volume and its exactly the same :( I am obviously missing something simple somewhere... It will send a volume but not receive.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

Twat twat twat - ignore all the above... I think its because I had the Relative and the Absolute un hashed! Working now! Thanks man - brilliant script and pretty easy to setup! I had to change the 79.5 to 80.5 to get the conversion to absolute spot on. (It was .5 out. so 50% on slide would send 50.5 to amp).

How can you get it running more often than a minute? Cron is a minute minimum lol

Edit:- I might have to leave this, the moment I changed my amp back to Absolute it now sets the slider to 216%. I have other plugins that rely on it being in absolute. the 99 steps that gives me is plenty. Such a shame as got it working as well :( Is there no easy conversation? Its odd that it sends the values just fine in Absolute mode - just doesn't receive them correctly. Gutted :(
Last edited by simon_rb on Saturday 12 November 2016 2:41, edited 1 time in total.
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

This was my lastest script... i have to check it out myself if it works, cuz my domoticz deleted my whole database again and i have to start over :-/

important parts:

Code: Select all

# 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="117"         # Absolute Volume (Slider) IDX (same as Absolute Volume)
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)
As you can see you need the ip addresses and the port filled in right, then have fill in the idx of the virtual sensor

surf to (your own ip)

Code: Select all

http://10.0.0.90/goform/formMainZone_MainZoneXml.xml 
http://10.0.0.90/goform/formNetAudio_StatusXml.xml
and compare it to the code in the script...
because all denon.sh does is get the xml, grabs the data (using grep or sed) and send it with json to domoticz.

Code: Select all

   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 could be that on your model its

Code: Select all

<selectSurround><value>DIRECT2.0</value>...
instead of on my model.

Code: Select all

<selectSurround><value>DIRECT</value>...
try removing parts that you do not need like

Code: Select all

#!/bin/bash
#
# Domoticz Denon Script
# ---------------------
#
# Created 2016 Trixwood
#
# 0.1 first try
# 0.2 TC only update when needed
# 0.3 Mute & Volume feature
#
#
# 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_MUTE_IDX="117"         # Absolute Volume (Slider) IDX (same as Absolute Volume)
DENON_VOL_REL_IDX="59"        # Relative Volume (Sound Volume) IDX
DENON_VOL_ABS_IDX="117"       # Absolute Volume (Slider) IDX


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

# 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=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
    
    #
    # 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" == "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=Off" &> /dev/null
      #echo "Mute: Switching On"
    fi
    if [ "$AVmute" == "off" ] && [ "$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 Off"
    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)
  
     if [ "$AVvolume" == "--" ] ; then
          AVvolume="0"
          AVisvolumerelative="Infinity"
     fi

    # 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 "$AVvolume - 80.5" | 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 [ "$AVmute" == "off" ] && [ "$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  

    # if mute then show sound -81db
    if [ "$AVmute" == "off" ]  && [ "$AVmuteold" == "On" ]; then
      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
    fi

  
     if [ "$AVmute" == "on" ] && [ "$AVmuteold" == "Off" ]; then
       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=-81" &> /dev/null


    fi  

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





and a lot of prints to debug...


--------
my latest version... not sure if it works...

Code: Select all

#!/bin/bash
#
# Domoticz Denon Script
# ---------------------
#
# Created 2016 Trixwood
#
# 0.1 first try
# 0.2 TC only update when needed
# 0.3 Mute & Volume feature
#
#
# 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="117"         # Absolute Volume (Slider) IDX (same as Absolute Volume)
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

    #
    # 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" == "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=Off" &> /dev/null
      #echo "Mute: Switching On"
    fi
    if [ "$AVmute" == "off" ] && [ "$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 Off"
    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)
  
     if [ "$AVvolume" == "--" ] ; then
          AVvolume="0"
          AVisvolumerelative="Infinity"
     fi

    # 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 "$AVvolume - 80.5" | 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 [ "$AVmute" == "off" ] && [ "$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  

    # if mute then show sound -81db
    if [ "$AVmute" == "off" ]  && [ "$AVmuteold" == "On" ]; then
      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
    fi

  
     if [ "$AVmute" == "on" ] && [ "$AVmuteold" == "Off" ]; then
       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=-81" &> /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



    #
    # 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


trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

kewl! yeah the 0.5 is kinda hmm ;-)

Enjoy!
trixwood

Re: Denon AV Reciver - plugin

Post by trixwood »

You can put it in a bash script and call that only once, and inside the script create an infinite loop with a sleep command between it calling denon.sh... if you want more finer control...

something like

Code: Select all

while true
   ./denon.sh
   sleep 0.5
but then in your favorite shell script lanhuage...

but every second is ok in my opinion. i do not mind if the information is a second or two behind, as long it response immediately if I change the volume slider... :-)
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

trixwood wrote:You can put it in a bash script and call that only once, and inside the script create an infinite loop with a sleep command between it calling denon.sh... if you want more finer control...

something like

Code: Select all

while true
   ./denon.sh
   sleep 0.5
but then in your favorite shell script lanhuage...

but every second is ok in my opinion. i do not mind if the information is a second or two behind, as long it response immediately if I change the volume slider... :-)
Didn't think of the loop function! Did you see my last edit above? its all a working except receiving in Absolute mode :(
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Denon AV Reciver - plugin

Post by simon_rb »

The volume part of the script looks really complicated where it calculates all the values. Using absolute values should be as easy as reading the number and sending it to domoticz as I have a 100 step dimmer/slider.. How hard would that be to modify? I had a look myself and just got overwhelmed lol
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest