Show DENON AV reciever input in Text switch

Moderator: leecollings

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 »

pepeEL wrote:Is any chance to add button to set Volume in Domoticz(up, down) in one button ?
You can create Denon as LightwaveRF Dimmer and attach the following LUA script to it:

Code: Select all

commandArray = {}

DomDevice = 'Denon'
IP = '<denon_ip>'
Port = '80'

 if devicechanged[DomDevice] then
      DomValue = otherdevices_svalues[DomDevice];
      print ("Start Current DomValue is: " .. DomValue);
   if(devicechanged[DomDevice]=='Off') then DomValue = 0;
   print ("Turning off " .. DomDevice);
   runcommand = "curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF";
   print (runcommand);
   os.execute(runcommand);
  return commandArray
   else
    if(devicechanged[DomDevice]=='On') then print ("Turning on " .. DomDevice);
    runcommand = "curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON";
    print (runcommand);
    os.execute(runcommand);
    return commandArray
    else
     DomValue = otherdevices_svalues[DomDevice];
     print ("In else current DomValue is: " .. DomValue);
    end
   end
   if DomValue==nil then DomValue=100 end
   if CalcValue==nil then CalcValue=0 end
   CalcValue = 80*DomValue/32-80;
   print ("Value received from Domoticz was " .. (DomValue) .." ");
   print ("Calculated value for Denon is " .. (CalcValue) .." ");
   runcommand = "curl 10 http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (CalcValue);
   print (runcommand);
   os.execute(runcommand);
 end
return commandArray
This way, you will have an ability to switch the AVR on and off and control the volume level using the slider. Mind you, my Denon model has values till 80, hence the calculation.
I have added also some binary switches with actions like:

Code: Select all

http://<denon_ip>/MainZone/index.put.asp?cmd0=PutZone_InputFunction%2FBD
for ON
and

Code: Select all

http://<denon_ip>/MainZone/index.put.asp?cmd0=PutZone_InputFunction%2FSAT%2FCBL
for OFF
attached, so I can control the switching of standard (pass through Cable/Sattelite) input to OSMC (attached to Denon BD input) when I am watching a move and back after movie.
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 »

Hi
Can you explained me more on private message ?
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 »

Changed something in the bash script to get the correct volume level the Denon receiver displays.

Change the volume section to this code.

Code: Select all

# Volume
        AVvolume=`grep -oP '(?<=<MasterVolume><value>-).*(?=</value)' test.txt`
        
        AVvolumeCor=$(bc <<< "80 - $AVvolume")
        echo "$AVvolumeCor"
        # 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=$AVvolumeCor"
Full script

Code: Select all

#!/bin/bash

 # Settings

 DENONIP="192.168.X.X"          # Denon IP Address
 DOMO_IP="192.168.X.X"          # Domoticz IP Address
 DOMO_PORT="8080"                 # Domoticz Port
 DENON_IDX="XX"                      # Denon Switch IDX
 DENON_VOL_IDX="XX"          # Denon volume IDX
 DENON_INPUT_IDX="XX"          # Denon input IDX
 DENON_STATUS_IDX="XX"          # 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`
        
	AVvolumeCor=$(bc <<< "80 - $AVvolume")
	echo "$AVvolumeCor"
	# 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=$AVvolumeCor"

   # 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`
	# Process the AVinput to replace spaces with %20  (so domoticz  knows what to do)
	# Instead of giving  a bad request
	AVinput1=`echo "$AVinput" | sed -e 's/ /%20/g'`

	# 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=$AVinput1"

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

Re: Show DENON AV reciever input in Text switch

Post by pepeEL »

Anybody know how build script to change volume in ZONE 2 on Denon AV by virtual slider ? I done clone script as write mKotek but change link to ZONE 2 but not work.
Link to change volume in ZONE2 is:

[url]http://IP_DENON/MainZone/index.put.asp?cmd0=PutMasterVolumeBtn/>&cmd1=aspMainZone_WebUpdateStatus/&ZoneName=ZONE2[/url] but it change volume by one point... +1 + 1 +1 etc


And maybe anybody know how put to switch text info which is display/ currently play on denon ?
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 »

I did not have a lot of time to check it, but I believe, there is an example here: http://forum.iobroker.org/viewtopic.php?t=327.
According to protocol reference, you could even control individual level for left and right channel.
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 »

On this page is the same link to VOLUME as i show:

Code: Select all

http://192.168.1.21/MainZone/index.put.asp?cmd0=PutMasterVolumeBtn/>
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 »

I do not know, how you were looking, but there is even better way to set the volume, because it is using commands from Protocol Reference directly.

In order to set Zone2 Volume to 40 you can use the following code:

Code: Select all

http://<denon_ip>/goform/formiPhoneAppDirect.xml?Z240
where Z2 stands for Zone 2 and 40 is the volume level. HTH
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 »

Ok but i dont know how use it in script lua domoticz to control by slider...

Wysłane z mojego SM-G920F przy użyciu Tapatalka
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 »

pepeEL wrote:Ok but i dont know how use it in script lua domoticz to control by slider...
Really? You need just to analyze the script I have provided and change parts where slider has been controlling MainZone Volume to Z2 Volume. Change needs to be made to URL Execution (os.execute).
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 »

This link works ok but i dont know programming script and dont know how change this script with use this link for zone2
TheSnitz
Posts: 10
Joined: Tuesday 29 September 2015 19:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by TheSnitz »

Dear Mooseknuckle,

I am running Domoticz on a Synology NAS and get the following errors while i am trying to run the Denon.sh script

Code: Select all

/volume1/cron$ sh /volume1/cron/denon.sh
0.413 ms
1
grep: invalid option -- 'P'
BusyBox v1.16.1 (2015-10-28 13:19:22 CST) multi-call binary.

Usage: grep [-HhnlLoqvsriFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

Options:
	-H	Add 'filename:' prefix
	-h	Do not add 'filename:' prefix
	-n	Add 'line_no:' prefix
	-l	Show only names of files that match
	-L	Show only names of files that don't match
	-c	Show only count of matching lines
	-o	Show only the matching part of line
	-q	Quiet. Return 0 if PATTERN is found, 1 otherwise
	-v	Select non-matching lines
	-s	Suppress open and read errors
	-r	Recurse
	-i	Ignore case
	-F	PATTERN is a literal (not regexp)
	-E	PATTERN is an extended regexp
	-m N	Match up to N times per file
	-A N	Print N lines of trailing context
	-B N	Print N lines of leading context
	-C N	Same as '-A N -B N'
	-e PTRN	Pattern to match
	-f FILE	Read pattern from file

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0100  1331    0  1331    0     0  68689      0 --:--:-- --:--:-- --:--:-- 73944
(23) Failed writing body
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0100  1331    0  1331    0     0  57185      0 --:--:-- --:--:-- --:--:-- 60500
Denon OFF
HTTP/1.1 200 OK

Content-Length: 51

Content-Type: application/json;charset=UTF-8

Cache-Control: no-cache

Pragma: no-cache

Access-Control-Allow-Origin: *



{
   "status" : "OK",
   "title" : "SwitchLight"
}
grep: invalid option -- 'P'
BusyBox v1.16.1 (2015-10-28 13:19:22 CST) multi-call binary.

Usage: grep [-HhnlLoqvsriFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

Options:
	-H	Add 'filename:' prefix
	-h	Do not add 'filename:' prefix
	-n	Add 'line_no:' prefix
	-l	Show only names of files that match
	-L	Show only names of files that don't match
	-c	Show only count of matching lines
	-o	Show only the matching part of line
	-q	Quiet. Return 0 if PATTERN is found, 1 otherwise
	-v	Select non-matching lines
	-s	Suppress open and read errors
	-r	Recurse
	-i	Ignore case
	-F	PATTERN is a literal (not regexp)
	-E	PATTERN is an extended regexp
	-m N	Match up to N times per file
	-A N	Print N lines of trailing context
	-B N	Print N lines of leading context
	-C N	Same as '-A N -B N'
	-e PTRN	Pattern to match
	-f FILE	Read pattern from file

HTTP/1.1 200 OK

Content-Length: 53

Content-Type: application/json;charset=UTF-8

Cache-Control: no-cache

Pragma: no-cache

Access-Control-Allow-Origin: *



{
   "status" : "OK",
   "title" : "Update Device"
}
And before that i change:

AVvolumeCor=$(bc <<< "80 - $AVvolume") To AVvolumeCor=$("80 - $AVvolume")
otherwise i get many errors.

It looks like that "grep -oP" not exist on the Synology

Do you have any idea's how we can fix this?

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

Re: Show DENON AV reciever input in Text switch

Post by Mooseknuckle »

Hi there,

I am not too familiar with sed but maybe this works:

Code: Select all

sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' test.txt
Replace the values and txt file to suit your needs.
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
TheSnitz
Posts: 10
Joined: Tuesday 29 September 2015 19:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by TheSnitz »

Mooseknuckle wrote:Hi there,

I am not too familiar with sed but maybe this works:

Code: Select all

sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' test.txt
Replace the values and txt file to suit your needs.

Hi Mooseknuckle,

It took me a day to get everything running :D i am not that good in programming but it works :D :D

what i did first was testing the new code lines:

Code: Select all

#!/bin/bash
	
AVstatus=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' test.txt)
echo "Versterker Status: ${AVstatus}"
	
AVvolume=$(sed -n -e 's/.*\<MasterVolume><value>\(.*\)<\/value>.*/\1/p' test.txt)
echo "Versterker Volume: ${AVvolume}"
	
AVinput=$(sed -n -e 's/.*\<InputFuncSelect><value>\(.*\)<\/value>.*/\1/p' test.txt)
echo "Versterker Input Status: ${AVinput}"
	
AVvolumeCor=$(echo "80 + $AVvolume" | bc)  
echo "Versterker volume berekend: ${AVvolumeCor}"
This line: AVvolumeCor=$(echo "80 + $AVvolume" | bc) was a hard one because the function "bc " was not installed on my synology DS212+
After a lot of reading and testing i crossed my fingers and bootstrapted my NAS ;) installed the IPKG dc and bash, and test the script.

Yes the "dc" was working now after that i put the new line of codes in the original code and i run the script.
^%#^%@# error: "xargs: xargs.c:443: main: Assertion `bc_ctl.arg_max <= (131072-2048)' failed.Aborted (core dumped)" WTF :oops: :evil: :cry:

After i while i found out that it has something to do with the ipkg findutils. I don't know if i use it but i removed it :P :P
Running the script again and there we are :D :D :D One working Denon_synology.sh script.

below is my script running on a Synology Nas 212+

Code: Select all

#!/bin/bash

 #Nas Synology 212+ 
 #Bootstrapped (needed for BC function)
 #wget http://web.archive.org/web/20121005035819/http://wizjos.endofinternet.net/synology/archief/syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh  (for 212+)
 
 #installed IPKG
 #bash - 3.2.54-1 - A bourne style shell
 #bash-completion
 #bc - 1.06-2 - GNU bc is an arbitrary precision numeric processing language
 
 #Removed after bootstrap because of getting error:  "xargs: xargs.c:443: main: Assertion `bc_ctl.arg_max <= (131072-2048)' failed.Aborted (core dumped)"
 #ipkg remove findutils

 
 # Settings

 DENONIP="**********"          # Denon IP Address
 DOMO_IP="********"          # Domoticz IP Address
 DOMO_PORT="*****"              # Domoticz Port
 DENON_STATUS_IDX="***"        # Denon status IDX
 DENON_VOL_IDX="***"           # Denon volume IDX
 DENON_INPUT_IDX="***"         # Denon input IDX
 DENON_IDX="***"               # Denon Switch IDX

 # Check if receiver in online

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

 echo pingtijd: $PINGTIME 
 
 if expr "$PINGTIME" '>' 0
 then
   curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml | sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' test.txt | grep "ON"
               if [ $? -eq 0 ] ; then

			    echo "Denon already ON"

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

   
# Volume
     	AVvolume=$(sed -n -e 's/.*\<MasterVolume><value>\(.*\)<\/value>.*/\1/p' test.txt)
		   
	 	AVvolumeCor=$(echo "80 + $AVvolume" | bc)  
		echo "$AVvolumeCor"
		
	# 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=$AVvolumeCor"

# Status
        AVstatus=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' 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=$(sed -n -e 's/.*\<InputFuncSelect><value>\(.*\)<\/value>.*/\1/p' test.txt)
		
   # Process the AVinput to replace spaces with %20  (so domoticz  knows what to do)
   # Instead of giving  a bad request
   AVinput1=`echo "$AVinput" | sed -e 's/ /%20/g'`

   # 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=$AVinput1"

   # 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=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' 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
Thanks for making this great script.
User avatar
gielie
Posts: 290
Joined: Tuesday 12 January 2016 11:40
Target OS: Raspberry Pi / ODroid
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Show DENON AV reciever input in Text switch

Post by gielie »

mKotek wrote:
pepeEL wrote:Is any chance to add button to set Volume in Domoticz(up, down) in one button ?
You can create Denon as LightwaveRF Dimmer and attach the following LUA script to it:
Can you explain how i can attach a LUA script to this dimmer, i created this dimmer with an on and off command or do you mean i have to put the volume script to the on command and create a different on/off switch.
- Aeon Labs USB Stick met Z-wave plus
- Aeotec MultiSensor 6
- FIBARO FGS223
- FIBARO FGWPE Wall Plug
- Neo CoolCam Power plug
- Popp Smoke Detector
- Toon
- Kodi Media Server
trixwood

Re: Show DENON AV reciever input in Text switch

Post by trixwood »

I had not found the sed workaround :-) On osx I installed grep from homebrew, and use ggrep instead of grep but sed works much beter! Also used a sound level in (db) for the volume monitor! :-)

Now it off to add my TV :-)

Samsung TV with possibility of messaging on the tv screen the latter at least for the C and D series!
(compiles & works on samsungtv, pi, windows but not osx)... osx i got a lot of warning and nothing happens... I am not really used to bsd, osx and all the new compilers options warning me about dangling else :-) the sms if functioning on osx, but for some reason the text does not work... too tired :-)

I mis the soap, upnp stuff in domoticz... ow well...

Link to (older) precompiled version

https://forum.samygo.tv/viewtopic.php?t=5794

Code: Select all

SamsungTV ‪Remote Control CLI‬ v0.02 April 2013 TRiXWooD
usage: STVCLI IP -KEY   KEY
   STVCLI IP -TEXT  TEXT
   STVCLI IP -SMS   DATE TIME FROM NUMBER TO NUMBER MESSAGE
   STVCLI IP -CALL  DATE TIME FROM NUMBER TO NUMBER
   STVCLI IP -SCHEDULE SUBJECT STARTDATE STARTTIME ENDDATE ENDTIME LOCATION OWNER NUMBER MESSAGE

examples: STVCLI 192.168.1.11 -KEY KEY_VOLUP
      --Simulates Press Volume Up
     STVCLI 192.168.1.11 -TEXT "Colour Haze"
      --Sends Text To Youtube...
     STVCLI 192.168.1.11 -SMS 2013-6-24 "7:01:01 PM" Cris +555-4323 Me +555-2343 "Get Off The Couch"
      --Show Incomming SMS...
     STVCLI 192.168.1.11 -CALL 23:06:01 Cris +555-4323 "" ""
      --Show Incomming Call (skips input with empty strings)...


exmaple script for displaying popup message
(hint forward ports 52235 & 55000 on your internet router so you can reach your tv from anywhere)

usage popup.sh 10.0.0.2 "Pop Says The Message on C6710"

STVCLI $1 -SMS "" "" "" "" "" "" $2
SLEEP 0.3
STVCLI $1 -KEY KEY_ENTER
SLEEP 3
STVCLI $1 -KEY KEY_ENTER
(but it is 3 years since I coded, And yes this is my own code I wrote 3 years ago :-)

Code: Select all

/*
* SamsungTV Remote C++ Command Line Interface v0.02 April 2013 TRiXWooD (cris.wood.org -AD- ‪gmail.com‬)
*
* Network Error Handling (Mostly Missing)
* Key &| Text Input Checking, some chars will result in disabling the tv's remote part
*
* April 2013
* v0.00 Prototype
* v0.01 Remote Working
* v0.02 SOAP Message Working
*
*
* modified base64 (Base64EncodeDecode.c) from Sam Ernest Kumar 
* part code/research from various places/people on the samygo forum
*/

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>


int samsungtv_base64encodeblock(char *input, char *output, int oplen){
  int rc = 0, iplen = 0;
  char encodedstr[5] = "";
  char encodingtabe[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  iplen = strlen(input);
  encodedstr[0] = encodingtabe[ input[0] >> 2 ];
  encodedstr[1] = encodingtabe[ ((input[0] & 0x03) << 4) | ((input[1] & 0xf0) >> 4) ];
  encodedstr[2] = (iplen > 1 ? encodingtabe[ ((input[1] & 0x0f) << 2) | ((input[2] & 0xc0) >> 6) ] : '=');
  encodedstr[3] = (iplen > 2 ? encodingtabe[ input[2] & 0x3f ] : '=');
  strncat(output, encodedstr, oplen-strlen(output));  
  return rc;
}

int samsungtv_base64encode(char *input, char *output, int oplen){
  int rc = 0;
  int index = 0, ipindex = 0, iplen = 0;
  char encoderinput[4] = "";
  iplen = strlen(input);
  while(ipindex < iplen){
    for(index = 0; index < 3; index++){
      if(ipindex < iplen){
        encoderinput[index] = input[ipindex];
      }else{
        encoderinput[index] = 0;
      }
      ipindex++;
    }
    rc = samsungtv_base64encodeblock(encoderinput, output, oplen);
  }
  return rc;
}

int samsungtv_response(int net_socket) {
 unsigned char message[256];
 memset (message,0x00,256);
 int i = 3;
 recv(net_socket,message,3,0);
 recv(net_socket,message+i,message[1],0);
 i += message[1];
 recv(net_socket,message+i,2,0);
 i += 2;
 unsigned char response = message[i-2];
 recv(net_socket,message+i,response,0);
 i += response;
 if (message[i-4] == 0x00 && message[i-3] == 0x00 && message[i-2] == 0x00 && message[i-1] == 0x00)
   if (message[0] == 0x01) return 4;           // success repeat keystroke...
   else return 0;                     // success
 if (message[i-response] == 0x65) return 3;         // timeoutt....
 if (message[i-4] == 0x64 && message[i-2] == 0x00) return 1; // access denied...
 if (message[i-4] == 0x64 && message[i-2] == 0x01) return 0; // success
 if (message[i-response] == 0x0A) return 2;         // waiting for user...
 return -1;                         // bug!
}

int samsungtv_setlength(unsigned char message[], unsigned int length) {
  message[0] = (unsigned char) (length & 0xFF);
  message[1] = (unsigned char) ((length >> 8) & 0xFF);
}

int samsungtv_setstring(unsigned char message[],unsigned char string[],int base64) {
  unsigned char s[512];
  memset (s,0x00,512);
  if (base64 == 1) samsungtv_base64encode(string,s,strlen(string)*2);
  else strncpy(s,string,strlen(string));
  samsungtv_setlength(message,strlen(s));
  strncpy(message+2,s,strlen(s));
  return strlen(s)+2;
}

enum modes {eKey, eText, eSMS, eCall, eSchedule, eAuth, eUnknown};

int samsungtv_message(unsigned char string[], int net_socket,int type) {
  unsigned char remote[] = "SamsungTVRemote";
  unsigned char message[1024];
  memset (message,0x00,1024);
  unsigned int s = samsungtv_setstring(message+1,"iphone.iapp.samsung",0) + 1;
  unsigned int i = s + 4 + (type==eKey?1:0);
  i += samsungtv_setstring(message+i,string,1);
  if (type == eAuth) {
    message[s+2] = 0x64;
    i += samsungtv_setstring(message+i,remote,1);
    i += samsungtv_setstring(message+i,remote,1);
  }
  if (type == eText) {
   message[0] = 0x01;
   message[s+2] = 0x01;
  }
  samsungtv_setlength(message+s,i-s-2);
  send(net_socket,message, i, 0);
  return (type==eText?0:samsungtv_response(net_socket));
}

int samsungtv_authenticate(unsigned char ip[], int net_socket) { return samsungtv_message(ip,net_socket,eAuth); }
int samsungtv_key(unsigned char key[], int net_socket) { return samsungtv_message(key,net_socket,eKey); }
int samsungtv_text(unsigned char text[], int net_socket) { return samsungtv_message(text,net_socket,eText); }

int samsungtv_sms(char ip[], int net_socket, char date[], char time[], char from[], char fromnumber[], char to[],
         char tonumber[], char message[]) {
 char request[3072];
  sprintf( request,"<Category>SMS</Category>"
     "<DisplayType>Maximum</DisplayType>"
     "<ReceiveTime>"
     "<Date>%s</Date>"
     "<Time>%s</Time>"
     "</ReceiveTime>"
     "<Receiver>"
     "<Number>%s</Number>"
     "<Name>%s</Name>"
     "</Receiver>"
     "<Sender>"
     "<Number>%s</Number>"
     "<Name>%s</Name>"
     "</Sender>"
     "<Body>%s</Body>",date,time,tonumber,to,fromnumber,from,message);
  return samsungtv_soap(ip,net_socket,request);
}

int samsungtv_schedule(char ip[], int net_socket, char subject[], char startdate[], char starttime[], char enddate[], char endtime[], char location[], char owner[], char number[], char message[]) {
char request[3072];
sprintf( request,"<Category>Schedule Reminder</Category>"
"<DisplayType>Maximum</DisplayType>"
"<StartTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</StartTime>"
"<Owner>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Owner>"
"<Subject>%s</Subject>"
"<EndTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</EndTime>"
"<Location>%s</Location>"
"<Body>%s</Body>",startdate,starttime,number,owner,subject,enddate,endtime,location,message);
 return samsungtv_soap(ip,net_socket,request);

}

int samsungtv_call(char ip[], int net_socket, char date[], char time[], char from[], char fromnumber[], char to[] , char tonumber[]) {
  
  char request[3072];
  sprintf( request,"<Category>Incoming Call</Category>"
      "<DisplayType>Maximum</DisplayType>"
      "<CallTime>"
      "<Date>%s</Date>"
      "<Time>%s</Time>"
      "</CallTime>"
      "<Callee>"
      "<Number>%s</Number>"
      "<Name>%s</Name>"
      "</Callee>"
      "<Caller>"
      "<Number>%s</Number>"
      "<Name>%s</Name>"
      "</Caller>",date,time,tonumber,to,fromnumber,from);

  return samsungtv_soap(ip,net_socket,request);
}

int samsungtv_soap(unsigned char ip[], int net_socket,char requestbody[]) {
  
  char request[3072];
  char buffer[4096];
  
  strcpy( request,
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
     "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
     "<s:Body>"
     "   <u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\">"
     "    <MessageType>text/xml</MessageType>"
     "    <MessageID>anything</MessageID>"
     "<Message>");
  
  strcat(request,requestbody);
  strcat(request,
     "</Message>"
     "   </u:AddMessage>"
     " </s:Body>"
     "</s:Envelope>" );

 sprintf( buffer,
    "POST /PMR/control/MessageBoxService HTTP/1.0\r\n"
    "Content-Type: text/xml; charset=\"utf-8\"\r\n"
    "HOST: %s\r\n"
    "Content-Length: %d\r\n"
    "SOAPACTION: \"uuid:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n"
    "Connection: close\r\n"
    "\r\n", ip, strlen( request));
  strcat( buffer, request );
  
  int numbytes;
  if((numbytes = send(net_socket, buffer, strlen( buffer ), 0)) == -1) { }  
  if((numbytes = recv(net_socket, buffer, 10000, 0)) == -1) { }
}

int main(int argc, char *argv[]) {
  
  struct addrinfo hints, *res, *p;
  int net_status, net_socket;
   enum modes mode = eUnknown;
  
  if (argc > 2) {
    if (strcmp(argv[2],"-TEXT") == 0) mode = eText;
    if (strcmp(argv[2],"-KEY") == 0) mode = eKey;
    if (strcmp(argv[2],"-SMS") == 0) mode = eSMS;
    if (strcmp(argv[2],"-CALL") == 0) mode = eCall;
    if (strcmp(argv[2],"-SCHEDULE") == 0) mode = eSchedule;
    
  }
  
  if (argc < 4 || mode == eUnknown ||
    
    !(mode == eText && argc == 4) &&
    !(mode == eKey && argc == 4) &&
    !(mode == eSMS && argc == 10) &&
    !(mode == eCall && argc == 9) &&
    !(mode == eSchedule && argc == 12) 
    
    ) {
    printf("SamsungTV ‪Remote Control CLI‬ v0.02 April 2013 TRiXWooD\n");
    printf("usage: STVCLI IP -KEY   KEY\n");
    printf("   STVCLI IP -TEXT  TEXT\n");
    printf("   STVCLI IP -SMS   DATE TIME FROM NUMBER TO NUMBER MESSAGE\n");
    printf("   STVCLI IP -CALL  DATE TIME FROM NUMBER TO NUMBER\n");
    printf("   STVCLI IP -SCHEDULE SUBJECT STARTDATE STARTTIME ENDDATE ENDTIME LOCATION OWNER NUMBER MESSAGE\n\n");
    printf("examples: STVCLI 192.168.1.11 -KEY KEY_VOLUP\n      --Simulates Press Volume Up\n");
    printf("     STVCLI 192.168.1.11 -TEXT \"Colour Haze\"\n      --Sends Text To Youtube...\n");
    printf("     STVCLI 192.168.1.11 -SMS 2013-6-24 \"7:01:01 PM\" Cris +555-4323 Me +555-2343 \"Get Off The Couch\"\n      --Show Incomming SMS...\n");
    printf("     STVCLI 192.168.1.11 -CALL 23:06:01 Cris +555-4323 \"\" \"\"\n      --Show Incomming Call (skips input with empty strings)...\n\n\n");
    printf("exmaple script for displaying popup message\n(hint forward ports 52235 & 55000 on your internet router so you can reach your tv from anywhere)\n\nusage popup.sh 10.0.0.2 \"Pop Says The Message on C6710\"\n\nSTVCLI $1 -SMS \"\" \"\" \"\" \"\" \"\" \"\" $2\nSLEEP 0.3\nSTVCLI $1 -KEY KEY_ENTER\nSLEEP 3\nSTVCLI $1 -KEY KEY_ENTER\n");
   return 1;
  }
  
  char port[] = "55000";
  if (mode != eKey && mode != eText) strcpy(port,"52235");
  
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
  hints.ai_socktype = SOCK_STREAM;
    if ((net_status = getaddrinfo(argv[1],port, &hints, &res)) != 0) {
    fprintf(stderr, "SamsungTV Remote Control: Connection Failure: (%s)\n", gai_strerror(net_status));
    return 2;
  }
  net_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if ((net_status = connect(net_socket, res->ai_addr, res->ai_addrlen)) != 0) {
    fprintf(stderr, "SamsungTV Remote Control: Connected Failure (%s)\n", gai_strerror(net_status));
    return 2;
  }
  
  if (mode == eKey || mode == eText) {
   int response,auth_status = samsungtv_authenticate(argv[1],net_socket);
   if (auth_status == 0) {
    if (mode == eText) response = samsungtv_text(argv[3],net_socket);
    else response = samsungtv_key(argv[3],net_socket);
    if (response != 0 && response != 4) fprintf(stderr, "SamsungTV Remote Control: Bug!\n");
   }
   else
   { if (auth_status == -1) fprintf(stderr, "SamsungTV Remote Control: Bug!\n");
    if (auth_status == 1) fprintf(stderr, "SamsungTV Remote Control: Access Denied\n");
    if (auth_status == 2) fprintf(stderr, "SamsungTV Remote Control: Waiting On User\n");
    if (auth_status == 3) fprintf(stderr, "SamsungTV Remote Control: Time Out\n");
   }
  }
  else {
   if (mode == eSMS) samsungtv_sms(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9]);
   if (mode == eCall) samsungtv_call(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8]);
   if (mode == eSchedule) samsungtv_schedule(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11]);
  }
  close(net_socket);
  freeaddrinfo(res);
  return 0;
}

/*
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_11
KEY_12
KEY_3SPEED
KEY_4_3
KEY_16_9
KEY_AD
KEY_ADDDEL
KEY_ALT_MHP
KEY_ANGLE
KEY_ANTENA
KEY_ANYNET
KEY_ANYVIEW
KEY_APP_LIST
KEY_ASPECT
KEY_AUTO_ARC_ANTENNA_AIR
KEY_AUTO_ARC_ANTENNA_CABLE
KEY_AUTO_ARC_ANTENNA_SATELLITE
KEY_AUTO_ARC_ANYNET_AUTO_START
KEY_AUTO_ARC_ANYNET_MODE_OK
KEY_AUTO_ARC_AUTOCOLOR_FAIL
KEY_AUTO_ARC_AUTOCOLOR_SUCCESS
KEY_AUTO_ARC_CAPTION_ENG
KEY_AUTO_ARC_CAPTION_KOR
KEY_AUTO_ARC_CAPTION_OFF
KEY_AUTO_ARC_CAPTION_ON
KEY_AUTO_ARC_C_FORCE_AGING
KEY_AUTO_ARC_JACK_IDENT
KEY_AUTO_ARC_LNA_OFF
KEY_AUTO_ARC_LNA_ON
KEY_AUTO_ARC_PIP_CH_CHANGE
KEY_AUTO_ARC_PIP_DOUBLE
KEY_AUTO_ARC_PIP_LARGE
KEY_AUTO_ARC_PIP_LEFT_BOTTOM
KEY_AUTO_ARC_PIP_LEFT_TOP
KEY_AUTO_ARC_PIP_RIGHT_BOTTOM
KEY_AUTO_ARC_PIP_RIGHT_TOP
KEY_AUTO_ARC_PIP_SMALL
KEY_AUTO_ARC_PIP_SOURCE_CHANGE
KEY_AUTO_ARC_PIP_WIDE
KEY_AUTO_ARC_RESET
KEY_AUTO_ARC_USBJACK_INSPECT
KEY_AUTO_FORMAT
KEY_AUTO_PROGRAM
KEY_AV1
KEY_AV2
KEY_AV3
KEY_BACK_MHP
KEY_BOOKMARK
KEY_CALLER_ID
KEY_CAPTION
KEY_CATV_MODE
KEY_CHDOWN
KEY_CHUP
KEY_CH_LIST
KEY_CLEAR
KEY_CLOCK_DISPLAY
KEY_COMPONENT1
KEY_COMPONENT2
KEY_CONTENTS
KEY_CONVERGENCE
KEY_CONVERT_AUDIO_MAINSUB
KEY_CUSTOM
KEY_CYAN
KEY_DEVICE_CONNECT
KEY_DISC_MENU
KEY_DMA
KEY_DNET
KEY_DNIe
KEY_DNSe
KEY_DOOR
KEY_DOWN
KEY_DSS_MODE
KEY_DTV
KEY_DTV_LINK
KEY_DTV_SIGNAL
KEY_DVD_MODE
KEY_DVI
KEY_DVR
KEY_DVR_MENU
KEY_DYNAMIC
KEY_ENTER
KEY_ENTERTAINMENT
KEY_ESAVING
KEY_EXIT
KEY_EXT1
KEY_EXT2
KEY_EXT3
KEY_EXT4
KEY_EXT5
KEY_EXT6
KEY_EXT7
KEY_EXT8
KEY_EXT9
KEY_EXT10
KEY_EXT11
KEY_EXT12
KEY_EXT13
KEY_EXT14
KEY_EXT15
KEY_EXT16
KEY_EXT17
KEY_EXT18
KEY_EXT19
KEY_EXT20
KEY_EXT21
KEY_EXT22
KEY_EXT23
KEY_EXT24
KEY_EXT25
KEY_EXT26
KEY_EXT27
KEY_EXT28
KEY_EXT29
KEY_EXT30
KEY_EXT31
KEY_EXT32
KEY_EXT33
KEY_EXT34
KEY_EXT35
KEY_EXT36
KEY_EXT37
KEY_EXT38
KEY_EXT39
KEY_EXT40
KEY_EXT41
KEY_FACTORY
KEY_FAVCH
KEY_FF
KEY_FF_
KEY_FM_RADIO
KEY_GAME
KEY_GREEN
KEY_GUIDE
KEY_HDMI
KEY_HDMI1
KEY_HDMI2
KEY_HDMI3
KEY_HDMI4
KEY_HELP
KEY_HOME
KEY_ID_INPUT
KEY_ID_SETUP
KEY_INFO
KEY_INSTANT_REPLAY
KEY_LEFT
KEY_LINK
KEY_LIVE
KEY_MAGIC_BRIGHT
KEY_MAGIC_CHANNEL
KEY_MDC
KEY_MENU
KEY_MIC
KEY_MORE
KEY_MOVIE1
KEY_MS
KEY_MTS
KEY_MUTE
KEY_NINE_SEPERATE
KEY_OPEN
KEY_PANNEL_CHDOWN
KEY_PANNEL_CHUP
KEY_PANNEL_ENTER
KEY_PANNEL_MENU
KEY_PANNEL_POWER
KEY_PANNEL_SOURCE
KEY_PANNEL_VOLDOW
KEY_PANNEL_VOLUP
KEY_PANORAMA
KEY_PAUSE
KEY_PCMODE
KEY_PERPECT_FOCUS
KEY_PICTURE_SIZE
KEY_PIP_CHDOWN
KEY_PIP_CHUP
KEY_PIP_ONOFF
KEY_PIP_SCAN
KEY_PIP_SIZE
KEY_PIP_SWAP
KEY_PLAY
KEY_PLUS100
KEY_PMODE
KEY_POWER
KEY_POWEROFF
KEY_POWERON
KEY_PRECH
KEY_PRINT
KEY_PROGRAM
KEY_QUICK_REPLAY
KEY_REC
KEY_RED
KEY_REPEAT
KEY_RESERVED1
KEY_RETURN
KEY_REWIND
KEY_REWIND_
KEY_RIGHT
KEY_RSS
KEY_RSURF
KEY_SCALE
KEY_SEFFECT
KEY_SETUP_CLOCK_TIMER
KEY_SLEEP
KEY_SOUND_MODE
KEY_SOURCE
KEY_SRS
KEY_STANDARD
KEY_STB_MODE
KEY_STILL_PICTURE
KEY_STOP
KEY_SUB_TITLE
KEY_SVIDEO1
KEY_SVIDEO2
KEY_SVIDEO3
KEY_TOOLS
KEY_TOPMENU
KEY_TTX_MIX
KEY_TTX_SUBFACE
KEY_TURBO
KEY_TV
KEY_TV_MODE
KEY_UP
KEY_VCHIP
KEY_VCR_MODE
KEY_VOLDOWN
KEY_VOLUP
KEY_WHEEL_LEFT
KEY_WHEEL_RIGHT
KEY_W_LINK
KEY_YELLOW
KEY_ZOOM1
KEY_ZOOmessage
KEY_ZOOM_IN
KEY_ZOOM_MOVE
KEY_ZOOM_OUT
*/

/* Future!!!! GetVolume/GetMute... && Trying to Play a avi.... 
POST /upnp/control/RenderingControl1 HTTP/1.1
Host: 192.168.0.10:52235
SOAPAction: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
Accept-Language: LC-ctypes=en-us;q=1, LC-ctype=en;q=0.5
Content-Type: text/xml; charset=utf-8
Content-Length: 335

<?xml version="1.0"?>
<s:Envelope xmlns:s="‪http://schemas.xmlsoap.org/soap/envelope/‬" s:encodingStyle="‪http://schemas.xmlsoap.org/soap/encoding/‬">
<s:Body><u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
<InstanceID>0</InstanceID>
<Channel>Master</Channel>
<DesiredMute>0</DesiredMute></u:SetMute>
</s:Body>
</s:Envelope>

POST /upnp/control/AVTransport1 HTTP/1.1
SOAPACTION: urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI
Connection: close
Content-Length: 619
Content-Type: text/xml
Host: 192.168.1.51:52235
User-Agent: HttpSamyGO/1.1

<?xml version='1.0' encoding='UTF-8' standalone='no' ?><s:Envelope s:encodingStyle="‪http://schemas.xmlsoap.org/soap/encoding/‬" xmlns:s="‪http://schemas.xmlsoap.org/soap/envelope/‬"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>‪http://75.101.165.227:8080/app/iLJy+VD9xyYqv5jtERGBijAeiqUmYWqCFzy4Li6gM0uMzI8pYoRWTxqp+UxEy14ibHGOrLpqJTkjI+WE6Q6lbQ6e2+1X96ToH8lGCv0f4f88M0jxU6S6z4SwC8KOCoMhscRxjOiy4CJVzNNeCGQxpw==.mp4‬</CurrentURI><CurrentURIMetaData><DIDL-Lite></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>

*/
trixwood

Re: Show DENON AV reciever input in Text switch

Post by trixwood »

Expanded it a little bit...

Mute button, Better Volume Logic :-)

enjoy...

Code: Select all

#!/bin/bash

 # Settings

 DENONIP="stereo.local"           # Denon IP Address
 DOMO_IP="pluto.local"         # Domoticz IP Address
 DOMO_PORT="8080"              # Domoticz Port

 DENON_IDX="60"                # Denon switch IDX
 DENON_MUTE_IDX="114"          # Denon switch mute IDX
 DENON_VOL_REL_IDX="59"        # Relative Denon sound volume (Sound Volume) IDX
 DENON_VOL_ABS_IDX="127"       # Absolute Denon sound volume (Percentage) or Dimmer IDX
 DENON_INPUT_IDX="61"          # Denon text input IDX
 DENON_NET_INPUT_IDX="115"     # Denon text net input IDX
 DENON_STATUS_IDX="62"         # Denon text 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 | sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' denon.settings | grep "ON"
        if [ $? -eq 0 ] ; then

   # get xml
   curl http://$DENONIP/goform/formMainZone_MainZoneXml.xml > denon.settings
   
   # extract now playing from telnet.... not done...
   # python /Users/Tristan/Smarthome/domoticz/scripts/denontelnet.py > denon.playing
   #AVTrack1=$(sed -n -e 's/.*\NSA1\(.*\).*/\1/p' denon.playing)
   #AVTrack2=$(sed -n -e 's/.*\NSA2\(.*\).*/\1/p' denon.playing)
   #AVTrack3=$(sed -n -e 's/.*\NSA3\(.*\).*/\1/p' denon.playing)
   #AVTrack4=$(sed -n -e 's/.*\NSA4\(.*\).*/\1/p' denon.playing)
   #AVTrack5=$(sed -n -e 's/.*\NSA5\(.*\).*/\1/p' denon.playing)
   #echo $AVTrack1 $AVTrack2 $AVTrack3 $AVTrack4 $AVTrack5
     
   # Volume
        AVisvolumerelative=$(sed -n -e 's/.*\<VolumeDisplay><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        AVvolume=$(sed -n -e 's/.*\<MasterVolume><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        
       
        if [ "$AVisvolumerelative" == "Relative" ] ; then
          AVvolumeAbs=$(echo "80 + $AVvolume" | bc) 
          AVvolumeRel=$AVvolume
        else
          # untested :-)
          AVvolumeRel=$(echo "80 - $AVvolume" | bc) 
          AVvolumeAbs=$AVvolume
        fi

        # Send data
        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"

        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DENON_VOL_ABS_IDX&nvalue=0&svalue=$AVvolumeAbs"
                # use for dimmer:   curl -s -i -H "Accept: application/json.htm?type=command&param=switchlight&idx=$DENON_VOL_ABS_IDX&switchcmd=Set%20Level&level=$AVvolumeAbs"
        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"

   # Status
        AVstatus=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        # 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"

   # Mute
        AVmute=$(sed -n -e 's/.*\<Mute><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        # Send data
        
        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"
        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"
        fi

   # Net Source
        AVnet=$(sed -n -e 's/.*\<NetFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        # Send data
        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"

   # Input
        AVinput=$(sed -n -e 's/.*\<InputFuncSelect><value>\(.*\)<\/value>.*/\1/p' denon.settings)
        # 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 > denon.settings

        # 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=$(sed -n -e 's/.*\<Power><value>\(.*\)<\/value>.*/\1/p' denon.settings)
    # Send data
        #echo $AVstatus
        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"
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$DENON_MUTE_IDX&switchcmd=On"
 
fi
 else
   # 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

# other options
# Tuner Options: curl http://10.0.0.91/goform/formTuner_HdXml.xml
# Direct Commands curl http://10.0.0.91/goform/formiPhoneAppDirect.xml?MUOFF
# http://www.openremote.org/display/docs/OpenRemote+2.0+How+To+-+Denon+HTTP+Control
# links to telnet commands here...
make an extra(!) virtual switch which controls on/off

put in this and add to it's sub/slave the denon switch defined above, from our code this witch: DENON_IDX="60" # Denon switch IDX
will be the sub/slave. This will make with the timeout of the cron job when the denon power's up the off trigger is not triggered... resulting in on-off-on-off... of the machine... but in normal working button!

for the mute switch add this:

in /Library/LaunchAgents (or use cron, i have apple Pi :-)

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/Tristan/Smarthome/domoticz/scripts/denon.sh</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>15</integer>
	<key>WorkingDirectory</key>
	<string>/Users/Tristan//Smarthome/domoticz/scripts</string>
</dict>
</plist>



found also some telnet code to get now playing information... decade ago that I write code so I decided not to rewrite this to bash that's why it commented out... only half working :-/

Code: Select all

import socket
import string
from time import sleep
import re

LIMIT=1024

class Avr:
    def __init__(self, addr, port = 23):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((addr, port))
        self.buf=[]

    def command(self, message):
        self.sock.send(message + '\r')

    def response(self):
        if len(self.buf) < 2:
            data=self.sock.recv(LIMIT)
            print data
            n = string.split(data, '\r')
            if len(self.buf) == 1:
                n[0] = self.buf[0] + n[0]
            self.buf = n

        return self.buf.pop(0).strip()

    def close(self):
        self.sock.close()

    # *** volume & mute *********
    def vol_up(self):
        self.command("MVUP")

    def vol_down(self):
        self.command("MVDOWN")

    def vol_query(self):
        self.command("MV?")
        return self.response()

    def mute(self):
        self.command("MUON");

    def unmute(self):
        self.command("MUOFF");

    def is_muted(self):
        self.command("MU?")
        return self.response() != "MUOFF"

    # *** input *** 
    def select_dvr(self):
        self.command("SIDVR")

    def select_rhapsody(self):
        self.command("SIRHAPSODY")

    def select_hdp(self):
        self.command("SIHDP")

    def select_server(self):
        self.command("SIHDP")

    def source(self):
        self.command("SI?")
        return self.response()

    # *** net screen ***
    def onscreen_display(self):
        self.command("NSA")
        ret = []
        for line in range(9):
            n = self.response()
  #          print n
            n = n[4:-1]
            if line != 0 and line != 8:
                # tag = n[0]
                n = n[1:-1]
            ret.append( n )
        return string.join(ret, '\n')

    def onscreen_display_more(self):
        self.command("NSE")
        ret = []
        for line in range(9):
            n = self.response()
            n = n[4:-1]
            if line != 0 and line != 8:
                # tag = n[0]
                n = n[1:-1]
            ret.append( n )
        return string.join(ret, '\n')

x = Avr("10.0.0.91")

#x.select_rhapsody()
#print x.source() 
x.onscreen_display()

#x.vol_up()

#x.vol_down()
#x.mute()

sleep(1)

x.close()

# ripped from https://forum.pimatic.org/topic/974/need-help-with-python-script-for-denon-avr
hoped it helped somebody!...
denisb88
Posts: 18
Joined: Thursday 11 February 2016 8:37
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Show DENON AV reciever input in Text switch

Post by denisb88 »

Thanks, do you know how to commut HDMI sound to TV or AMP.
I have found this but I don(t knows how to use it.

Code: Select all

curl http://192.168.1.5/SETUP/VIDEO/HDMISETUP/f_video.asp?cmd0=radioHdmiDviInAssignAudio%2AMP
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Show DENON AV reciever input in Text switch

Post by simon_rb »

This looks like something that may help me with my situation, I have posted in another thread before I found this one, below is my issue in more detail but in a nutshell I need to query the Denon to see if its on or not and let Domoticz act accordingly however I can't use ping to do it, I need to use the PW? command I think.

I have a problem I am trying to solve - I thought I had found a solution however it wasn't, since I have thought of another way round but its out of my basic knowledge. My setup:-

I have a network Denon Amp and a separate amp to power a subwoofer. I have a surround sound button in domoticz and when pressed it switches the mains socket to power on the amp the is connected to the sub and then domoticz sends an IR command to my Denon to turn on and it works. The hurdle I have is when the Denon is in standby and we select it from an airplay menu to play some music then the Denon powers up but obviously the amp powering the sub doesn't turn on as Domoticz is unaware the amp is on.

What I tried to do was turn off the network when it was in standby and had domoticz ping it so when it powered up then it would know as it would then respond to the ping and then turn on the Sub Amp - brilliant I thought however of course this defeats the object as now when the Denon is in standby the network is turned off so we can't select it from the Airplay menu. This got me thinking that maybe I am on the right track with the ping, instead is there a way of querying the Amp using domoticz and when it powers up then Domoticz would know and turn on the other amp. I found some documentation but how I get Domoticz to query and use the received info is a bit beyond my abilities. Any ideas anyone? I know the query for power status is "PW?"

Thank you in advance.
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 »

The easiest solution is to use the 12v switching port on the denon to turn on the subwoofer.

If you want domoticz to know you can use a bash script like this one:
memberlist.php?mode=viewprofile&u=1923
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest