Page 1 of 4
Show DENON AV reciever input in Text switch
Posted: Saturday 07 March 2015 22:20
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?
Show DENON AV reciever input in Text switch
Posted: Saturday 07 March 2015 22:27
by ThinkPad
I would start by searching for some tutorials/projects where they parse XML with Lua. Or Bash... Or Python

Re: Show DENON AV reciever input in Text switch
Posted: Saturday 07 March 2015 22:51
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

Show DENON AV reciever input in Text switch
Posted: Sunday 08 March 2015 9:44
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
Show DENON AV reciever input in Text switch
Posted: Wednesday 25 March 2015 0:12
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.
Show DENON AV reciever input in Text switch
Posted: Wednesday 25 March 2015 22:23
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¶m=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¶m=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¶m=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¶m=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¶m=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¶m=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¶m=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

.
I hope this will get you started.
Re: Show DENON AV reciever input in Text switch
Posted: Thursday 26 March 2015 18:53
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. :/
Show DENON AV reciever input in Text switch
Posted: Thursday 26 March 2015 20:31
by Mooseknuckle
Did you also change the IDX numbers into the numbers of your own switches?
Re: Show DENON AV reciever input in Text switch
Posted: Thursday 26 March 2015 22:45
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!
Show DENON AV reciever input in Text switch
Posted: Friday 27 March 2015 8:56
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

Re: Show DENON AV reciever input in Text switch
Posted: Friday 27 March 2015 11:48
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?

Show DENON AV reciever input in Text switch
Posted: Friday 27 March 2015 12:02
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.
Re: Show DENON AV reciever input in Text switch
Posted: Tuesday 31 March 2015 19:34
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?
Show DENON AV reciever input in Text switch
Posted: Wednesday 01 April 2015 9:57
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.
Re: Show DENON AV reciever input in Text switch
Posted: Wednesday 01 April 2015 22:48
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.
Re: Show DENON AV reciever input in Text switch
Posted: Monday 07 December 2015 11:32
by pepeEL
Maybe someone who knows write plug into domoticz to handle Reciver Denon AVR as works KODI in Domoticz?
Re: Show DENON AV reciever input in Text switch
Posted: Tuesday 05 January 2016 0:46
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?
Re: Show DENON AV reciever input in Text switch
Posted: Tuesday 05 January 2016 6:40
by Egregius
That's 80 - value because 80 is the max volume of the Denon interface.
I use a webpage for this:

Re: Show DENON AV reciever input in Text switch
Posted: Tuesday 05 January 2016 9:53
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.
Re: Show DENON AV reciever input in Text switch
Posted: Tuesday 05 January 2016 12:13
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.