Show DENON AV reciever input in Text switch

Moderator: leecollings

dijkdj
Posts: 63
Joined: Saturday 07 March 2015 22:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by dijkdj »

I want to read the output of my Denon reciever. This information is in an XML file under http://192.168.1.22/goform/formMainZone_MainZoneXml.xml
The line with information is

Code: Select all

<InputFuncSelect>
<value>Squeezebox</value>
</InputFuncSelect>
You can see that the choosen input is "Squeezebox". I want to show this value in a :"text" switch. Does someone has an example in LUA code?
Last edited by dijkdj on Saturday 07 March 2015 22:29, edited 1 time in total.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Show DENON AV reciever input in Text switch

Post by ThinkPad »

I would start by searching for some tutorials/projects where they parse XML with Lua. Or Bash... Or Python :P
I am not active on this forum anymore.
dijkdj
Posts: 63
Joined: Saturday 07 March 2015 22:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by dijkdj »

A tutorial would not be bad :) If I can start with a few lines that do what I need, I can start adjusting :)
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

What I did is created a shell script which runs every 2 minutes and just basically greps some values from the xml and puts it in an text switch. This is a grep example:

Code: Select all

curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml | grep -oP '(?<=<InputFuncSelect><value>).*(?=</value)'
Is is also possible to send actions to you receiver, for example like this:

Code: Select all

curl http://DENON_IP/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Morcegolas »

@Mooseknuckle Can you do a step by step for noobs please! I can create the script, but run it every two minutes and add it to a text switch is another thing.

If I run this scrip manually I get the last selected source, like AUX, and what I'm looking for is for its state, ON/OFF. So I can set rules based on Denon status. ;)

Thanks.
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

I use the following script. It is based on the synology monitoring script found on the Domoticz wiki so credits to the creator of that script.
I basically put all the info from the xml file into a text file and the grep the info that I want and put it in a text switch but for the on/off status you can also use on/off switch.
Here is my script, lots of room for improvement but atm it works for me. You can add/change/remove depending on your wishes. I made one virtual light switch and 3 text switches for my version.
The short version, it does a ping. If the receiver is off, it sets the on/off switch to off. If it responds to the ping it will check if the receiver is on or standby. If it is standby, it will set the on/off switch to off. If it is on it will grep the info I want (On status, Volume level and Input selection).

Code: Select all

#!/bin/bash

 # Settings

 DENONIP="192.168.1.18"          # Denon IP Address
 DOMO_IP="192.168.1.26"          # Domoticz IP Address
 DOMO_PORT="8080"                 # Domoticz Port
 DENON_IDX="73"                      # Denon Switch IDX
 DENON_VOL_IDX="64"	       # Denon volume IDX
 DENON_INPUT_IDX="72"	       # Denon input IDX
 DENON_STATUS_IDX="63"	       # Denon status IDX

 # Check if receiver in online

 PINGTIME=`ping -c 1 -q $DENONIP | awk -F"/" '{print $5}' | xargs`

 echo $PINGTIME
 if expr "$PINGTIME" '>' 0
 then
	curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml | grep -oP '(?<=<Power><value>).*(?=</value)' | grep "ON"
        if [ $? -eq 0 ] ; then

	echo "Denon already ON"

	# get xml
	curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml > test.txt

	# Volume
        AVvolume=`grep -oP '(?<=<MasterVolume><value>-).*(?=</value)' test.txt`
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_VOL_IDX&nvalue=0&svalue=$AVvolume"

	# Status
        AVstatus=`grep -oP '(?<=<Power><value>).*(?=</value)' test.txt`
        # Send data
        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"

	# Input
        AVinput=`grep -oP '(?<=<InputFuncSelect><value>).*(?=</value)' test.txt`
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_INPUT_IDX&nvalue=0&svalue=$AVinput"

	# Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=On"

        else
	# get xml
        curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml > test.txt

	echo "Denon OFF"
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off"

	# Status
        AVstatus=`grep -oP '(?<=<Power><value>).*(?=</value)' test.txt`
    # Send data
        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"

fi
 else
    echo "Denon already OFF"
	# Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_IDX&switchcmd=Off"
 fi

Besides getting info into Domoticz you can also give your receiver commands based on triggers. Here are some examples:

Code: Select all

curl http://DENON_IP/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON # receiver on
curl http://DENON_IP/MainZone/index.put.asp?cmd0=PutSystem_OnStandby%2FSTANDBY # receiver standby
You can give more commands, information can be found here:
http://forum.kodi.tv/showthread.php?tid=162592
https://github.com/jtangelder/denon-remote (lots of info in the protocol.pdf)

For example, I made a scene in Domoticz for when I want a romantic dinner with my gf. It sets my Hue lights, it turns off the tv (if its on), turns on my receiver and set it to a favorite internet radio station at a predefined volume level :D.

I hope this will get you started.
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Morcegolas »

@Monoseknuckle

I created the script, changed the Denon and Domoticz IPs and when I run it I get this errors and the text.txt file is empty :/

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ ./Denon.sh 
0.683
1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1510    0  1510    0     0  19329      0 --:--:-- --:--:-- --:--:-- 26491
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1510    0  1510    0     0  21287      0 --:--:-- --:--:-- --:--:-- 29607
Denon OFF
HTTP/1.0 200 OK
Content-Length: 24
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "ERR"
}
HTTP/1.0 200 OK
Content-Length: 24
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "ERR"
}
If i run from domoticz terminal: curl http://10.1.1.7/goform/formMainZone_MainZoneXml.xml > test.txt it works just great, in the script I don't know what's happening. :/
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

Did you also change the IDX numbers into the numbers of your own switches?
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Morcegolas »

I forgot that! :/
Now that I change it reports:

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ ./Denon.sh 
4.730
1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1504    0  1504    0     0  21973      0 --:--:-- --:--:-- --:--:-- 28377
ON
Denon already ON
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1504    0  1504    0     0  27870      0 --:--:-- --:--:-- --:--:-- 39578
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
HTTP/1.0 200 OK
Content-Length: 51
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "SwitchLight"
}
I created 4 virtual switches, all the same way, on/off light switch. The Denon Switch that report the ON/OFF state off the receiver is working great, the other 3 ( Volume, Input and Status ) they all stay off, I have to change anything on the virtual switches?

Thanks for the big help!
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

It's not going to work with 4 virtual on/off switchtes because you can't put text info in that. You have to create 1 virtual switch for the on/off status. For the other 3 that get the info from the xml file you have to choose "text" as virtual sensor and not "switch" when you create them. I should have explained this better in my first post :)
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Morcegolas »

Thanks, it's working great now! The only thing that it's still missing in my configuration is to run the script automatic every 2 minutes, can you help me doing that? ;)
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

To run the script every 2 minutes you open crontab (crontab -e) and add the following line:

Code: Select all

*/2 * * * * /home/pi/domoticz/scripts/denon.sh
Maybe you have to adjust the path and name of the script, then it should work.
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Morcegolas
Posts: 24
Joined: Wednesday 01 October 2014 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Morcegolas »

Everything 100% now, thanks once again.

Just one question, isn't possible to change the text icons on domoticz so they can match a sound icon for exemple?
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

Maybe it is but I haven't done that. You can check here http://www.domoticz.com/wiki/Custom_ico ... binterface for more info.
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
dijkdj
Posts: 63
Joined: Saturday 07 March 2015 22:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by dijkdj »

YOU ARE A HERO. WOW! Works perfectly!

Now I will have a look how to only update a sensor if the value is changed, that helps keeping the log clean.
pepeEL

Re: Show DENON AV reciever input in Text switch

Post by pepeEL »

Maybe someone who knows write plug into domoticz to handle Reciver Denon AVR as works KODI in Domoticz?
Panda
Posts: 11
Joined: Wednesday 26 August 2015 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Panda »

Thank you for the script, strange thing is that my Denon Avr-x1200 displays 44db but the script and xml page returns 36, what could cause this?

Would be cool to have all this info into one switch.

Edit: When I put it on 40db it will show 40db but when I put it higher then 40db it will go down, so 40.5 gives me 39.5 strange..., what I also noticed is that when you changed input name like I did, e.g. Mac Mini it will return http error bad request because the input name contains a space. Anyway to fix this to send space to domoticz?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Show DENON AV reciever input in Text switch

Post by Egregius »

That's 80 - value because 80 is the max volume of the Denon interface.

I use a webpage for this:
Image
mKotek
Posts: 68
Joined: Wednesday 30 December 2015 23:54
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Show DENON AV reciever input in Text switch

Post by mKotek »

Panda wrote:Thank you for the script, strange thing is that my Denon Avr-x1200 displays 44db but the script and xml page returns 36, what could cause this?

Would be cool to have all this info into one switch.

Edit: When I put it on 40db it will show 40db but when I put it higher then 40db it will go down, so 40.5 gives me 39.5 strange..., what I also noticed is that when you changed input name like I did, e.g. Mac Mini it will return http error bad request because the input name contains a space. Anyway to fix this to send space to domoticz?
There are 2 modes you can use for Volume control with Denon. The first one is sound level - between 0 and 80 and the other one is attenuation, so muting. With the first one, you set the level to (ie. 30) and the value you set is 30-80, meaning you mute it by -50. With db, it is even more visible as you are specifying directly, you are attenuating by ie. 30db. I hope, I made myself clear.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.
pepeEL

Re: Show DENON AV reciever input in Text switch

Post by pepeEL »

Is anuone who can create plugin/support for Domoticz to support control Denon AV as is created in Domoticz now plugin for KODI media...
How you use this script for control DENON AV by Domoticz ? Sorry for my english and i am begginer.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest