Generic Denon / Marantz python plugin

Python and python framework
Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Generic Denon / Marantz python plugin

Post by Artemgy » Sunday 19 March 2017 19:38

The Denon & Marantz Company have sensibly chosen to use the same basic AVR Control Protocol across most of their products.

I am starting this thread to draw together knowledge and code to work towards a generic "DenonMarantz.py" plugin. Note that this intends to use the (single-user) telnet command structure in the following documents, rather than any http / xml based access using the AVR's built-in web services.

Documentation

Examples of Denon / Marantz "AVR Control Protocol" documentation direct from from Denon & Marantz Company: Existing code

So far most of the development work has been by Dnpwwo, and this is a great help already, with the most recent version 2.2.0 can be found at He did also supply an earlier version ''DenonX2100W.rar'' in post [https://www.domoticz.com/forum/viewtopi ... 20#p110467]

I am very grateful to Dnpwwo's work, and I offer to contribute:
  • coding
  • testing
  • documentation
NB: for anyone wanting to use plugins see [http://www.domoticz.com/wiki/Using_Python_plugins]

I welcome anyone else to offer suggestions based their own experience and testing, so we can ensure this plugin provides all the owners of Marantz or Denon AVR equipment need to make the most of Domoticz.
Thanks

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Sunday 19 March 2017 20:28

With Marantz NR 1504 the plugin works well:
  • Power On / Off switch
  • select output for Main Zone
  • Set Main Volume
  • no contention on connections from Marantz Android App
  • read changes to above when switched elsewhere (remote / android app / AVR web UI) within a second or so
You need to take care to match list of Zone Output names in plugin to those your AVR recognises.

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: Generic Denon / Marantz python plugin

Post by woodtrix » Sunday 19 March 2017 20:53

I would advice against telnet, except for setting up advanced stuff like treble, bass or stuff like individual speaker levels. (things that you probably will not use that often).

Reason: My denon locks up with telnet. You only get one connection with telnet :-/ (av1912) and most of my phone apps stop working if I do not close the connection right away after sending commands.

I have build a bridge to handle only one connection (and added that it disconnects after sending a command...) To try if this would work better, but the time to build a telnet connection is high... and my denon randomly disconnects or will not reconnect and is completely locked (from the network), it even brings the http server down for a while, that means no volume control, no input select nothing will work for more then 5 seconds. Not really an option if you have to wait more then 5 seconds to lower the volume... or use mute or change the input. So changing the occasional treble or bass settings works, but trying to do the same stuff as with the xml file... nah... (note: the remote and the buttons on the unit itself still work)

So you will end up polling the various xml files. Like every other denon app out there :-) And use the telnet only for the advance stuff.

Anyway good luck! Ambitious project :-)

If you ever find out how to you update a sensor without it triggering the html action (without using two sensors, cuzwith a slave/master combi it still does not work 100%) I would love to know...

The biggest problem with the current denon scrip and I am real curious how the new plugin system would handle it...:

A user select a volume level, domoticz changes the volume value of the sensor and triggers the html to change the volume on the denon, but the script just read the xml/telnet volume and updates the sensor back to the old value,... html action triggers and sets it back to the old volume,... etc.. (that's my there is a master slave to give it some delay... I actually do not know why it works... I think its the delay :-)

It is the biggest bottleneck you have to solve. But then again maybe in the new plug in system you can handle this differently then I did with my bash script :-)

Anyway.... good luck!

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Generic Denon / Marantz python plugin

Post by G3rard » Monday 20 March 2017 0:42

woodtrix wrote: If you ever find out how to you update a sensor without it triggering the html action (without using two sensors, cuzwith a slave/master combi it still does not work 100%) I would love to know...
You can use this command

Code: Select all

commandArray['UpdateDevice'] = otherdevices_idx['TV volume'] ..'|2|' .. vol_tv
where 'TV volume' is the switch name and 'vol_tv' is the volume.
I use this to update a dimmer with the volume without triggering any actions in Domoticz.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Monday 20 March 2017 0:55

Yeah, I understand your concerns, woodtrix - I have met problems with the "only one concurrent telnet session" limitation of Denons before. However I have found the current Python Plugin performs surprisingly well in my setup. I'd rather move forward by following the vendor documented telnet protocol than by disassembling scraped xml, if it works, but I'll bear in mind the scenarios you mention for creating robust test scripts.

BTW: if you haven't tried the new Python Plugin for Denon from domoticz/plugins/examples/Denon4306.py yet then consider upgrading to the latest beta and giving it a go - you may be pleasantly surprised how much more streamlined this new framework is to use than when you had to cook the bash - lua combo in the past.

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Generic Denon / Marantz python plugin

Post by G3rard » Monday 20 March 2017 0:57

Artemgy wrote:With Marantz NR 1504 the plugin works well:
  • Power On / Off switch
  • select output for Main Zone
  • Set Main Volume
  • no contention on connections from Marantz Android App
  • read changes to above when switched elsewhere (remote / android app / AVR web UI) within a second or so
You need to take care to match list of Zone Output names in plugin to those your AVR recognises.
I have a Marantz NR1604 and the plugin from Dnpwwo is working fine. I added some code for handling the error codes, see viewtopic.php?f=65&t=15681&p=123496#p123454.

The only thing that is not working properly for me yet is the switch selector with the output.
Where did you get the right list that the AVR recognizes? I took my list from the GUI of the AVR (by browsing to the IP address), but somehow the selector switch is not being updated.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: Generic Denon / Marantz python plugin

Post by woodtrix » Monday 20 March 2017 4:24

Well definitely going to play with it, it is now on my long list of things to play with :-)

My domoticz at the moments runs these "smart" features on my denon

Incomming call
You can also add some special functionality, like a switch to lower gracefully the volume to a desired settings if its higher... call it incoming call volume :-) At least I have u switch for that...

NightSound
I also have a switch called NightSound, its a night time volume limiter, which from 10 o clock in the evening gracefully lowers the volume to a night time limit (As I remembered correctly it made it that it takes like 5 minutes to lower the value to the limits the volume, that gracefully and you do not notice), and (!) lowers the bass*. Note that the 5 minutes is around 10.00 clock, at 12:00 it just limits the volume right away (except on friday and Saturday evening, the whole nightsound is always disabled then, I had it set around 2 o clock at night, but time varies too much it was not usable)

I also added after some time, that when you change the volume to a higher level then the limit more then 2 times in the last couple of minutes , it disables nightsound... (keeps other family members happy)

At 6:30 o clock in the morning the saved values get restored...

* If I am tired and there is too much bass (like with shooting and explosions in action movies) my ears go red (from I think the pressure) Lowering the bass gradually in the evening helps alot... (and nobody notice, at least no complaints from other family members :-)

The last feature I have is that my denon will NOT auto lip-sync audio correctly, luckily you can disable it and manual adjust it, I have a up and down button to fine tune those settings... saving me the trip into that awfull menu of theirs... (I get really annoyed when speech and moving mouths are not aligned, it feels like an echo)


The list of inputs you can get from the main xml file.

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Monday 20 March 2017 20:52

G3rard wrote:Where did you get the right list that the AVR recognizes? I took my list from the GUI of the AVR (by browsing to the IP address), but somehow the selector switch is not being updated.
Truly definitive list of sources, I guess, would be to find your particular AVR model in one of the official Denon/Marantz docs (e.g. see the first post of this thread) and check all the SIxxxxx codes that model supports.

The way I successfully obtained a definitive list of sources I use on my amp was by selecting each manually, one by one, and querying the receiver over telnet - perhaps slightly long-winded but very effective...

Code: Select all

# stop the service so the receiver accepts a telnet connection
sudo systemctl stop domoticz.service 

# do a full query of the Selected Input, waiting 1 sec for the response and correctly handling carriage returns
echo -ne 'SI?\r'|nc -q 1 livsnd 23 |tr '\r' '\n'

# truncate the query to show ONLY the internal code for the currently selected input 
echo -ne 'SI?\r'|nc -q 1 livsnd 23 |tr '\r' '\n'|head -n 1|cut -c 3-
### REPEAT THIS ### for each input you select from the remote or the AVR front panel dial

# restart the service so domoticz works once again
sudo systemctl start domoticz.service 

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Generic Denon / Marantz python plugin

Post by G3rard » Tuesday 21 March 2017 0:35

Artemgy wrote: Truly definitive list of sources, I guess, would be to find your particular AVR model in one of the official Denon/Marantz docs (e.g. see the first post of this thread) and check all the SIxxxxx codes that model supports.
Thanks, tested it with one of the items in the SI list from the Excel in your first link and that works :)
Will check the other items in the list to see which ones are supported on my AVR model.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

User avatar
Dnpwwo
Posts: 749
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Generic Denon / Marantz python plugin

Post by Dnpwwo » Tuesday 21 March 2017 11:17

@Artemgy,

I'm happy for someone else to take ownership of this plugin so I can focus on other plugin framework development.

I have a newer version that I am testing at the moment that you might want to start from. Changes are:
  • Better aligned to Domoticz standards, creates all devices in the Device tab only
  • Less user configuration, auto-detects zone support and adds zones that are supported
  • Simplified (and more reliable logic), the current one was developed in parallel with the python framework (and a test at it showed).
  • Optimised polling
I just need to add the new Selector Switch Option handling and I will post it.

To answer a few things discussed below:
  • Haven't seen (or had reported) any Denon lockups with Telnet and I've been running it for 6 months
  • Using anything that does not stay connected (or polls) is unacceptable IMHO for one reason: The Web UI polls every 10 seconds so if a plugin polls as well you can end up with device updates being shown in the UI up to 20 seconds later if someone uses a remote or (god forbid) actually does something on the physical device itself. The Telnet interface reports changes as they happen.
  • I don't understand @woodtrix's "biggest problem", volume updates seem to work just fine, maybe its because the current plugin doesn't poll :?:
  • I looked at a number of ways of discovering the sources that the amp supports in the plugin but realised that discovery is not the problem (you could just attach to the amp web port the first time and scrape the sources), the problem is what to do with the list once you have it. You can't just put every source into a Selector Switch because I believe they only support 10 entries at the moment. Assuming the web UI is standard across amps you could scrape the 'Digital In Assign' section from 'Audio Input Setup (1)' and only scrape the devices that weren't 'OFF' to get the entires to put in the selector then scrape the 'Function Rename' section from 'Audio Input Setup (2)' for what to name them, that way you don't need to know the whole list because you get the ones that are being used. Would that approach interest people?
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Wednesday 22 March 2017 11:29

@Dnpwwo,

I am really impressed with the work you have already done on this plugin, and I think you've already got much of the functionality in there (or as you say, on the way). Once you release the next version, I can document it on the wiki and try to keep tabs on feedback we get. If I could just ask you to rename it to be a generic DenonMarantz.py file in the examples folder, rather than model-specific, then I think that will help it get better adoption.

I'm still learning how plugins relate to the web interface re notifications, and for the moment your mode of connectivity seems appropriate. Perhaps in the future we might consider an option where the telnet connection is initiated on demand, then closed immediately after receiving the response, to allow the possibility of alternative clients getting a telnet connection when the user is not actively navigating the web interface. That would mitigate "this plugin stops me from ..." issues, but let's wait until people using this plugin start clamouring for it first :)

As to the list of inputs in the selector, many amps allow you to set up the available choices on the selector dial, so it would not be too bad to leave this as part of the user setup procedure when activating the plugin, as long as we can advise them in the doc how to derive the appropriate list for their model.

I look forward to the new release, when I will review @G3rard's extra code, and anyone else's, to consider for merging. And I'll write it up in the wiki.
Again, many thanks!

User avatar
Dnpwwo
Posts: 749
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Generic Denon / Marantz python plugin

Post by Dnpwwo » Friday 24 March 2017 5:54

@Artemgy,

Latest version:
plugin v2.5.4.rar
(3.76 KiB) Downloaded 125 times
You should delete the current hardware and recreate it with this one. Features are:
  • Better aligned to Domoticz standards, creates all devices in the Device tab only
  • Less user configuration, auto-detects zone support and adds zones that are supported
  • Simplified (and more reliable logic), the current one was developed in parallel with the python framework (and it showed).
  • Optimised polling
Plugins current recieve all notifications from Domoticz and can choose what to do with them but currently they don't trigger them. This is on the enhancement list.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Friday 24 March 2017 10:38

Thanks for that @Dnpwwo - in my initial tests this version does suppress creation of devices for non existent zones, but in my case it also failed to create the main zone device selector. I'll take a look into the new code in the next day or so to see if I can figure it out. Cheers

Artemgy
Posts: 11
Joined: Friday 17 March 2017 18:17
Target OS: Raspberry Pi
Domoticz version: v3.7017b
Contact:

Re: Generic Denon / Marantz python plugin

Post by Artemgy » Friday 24 March 2017 19:52

To make it easier find the latest version, and to track issues, I have copied this 2.5.4 version in github at

Permalink to latest working version: https://github.com/artmg/domoticz-denon ... Marantz.py

We can keep tabs on showstoppers and nice to have's in the repo's issues list, and then once it's ready I'll PR it into the main domticz repo.
Hope this works for you. +A

Boredcat
Posts: 44
Joined: Friday 17 March 2017 10:31
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Generic Denon / Marantz python plugin

Post by Boredcat » Monday 27 March 2017 22:45

Thank you for this plugin, looks very good.

But I got an issue with it. In the logs I found this error. I have switches for power on/off volume zone 1 and zone 2. No selector for source.

receiver is an X2200W, domoticz is a stable build running on Windows 2012R2 Python 3.5.2 x86 installed.

Its probable an configuration issue at my config. But I have no idea where to look or to solve it.


2017-03-27 22:38:03.034 Error: Expected: myVar = Domoticz.Device(Name="myDevice", Unit=0, TypeName="", Type=0, Subtype=0, Switchtype=0, Image=0, Options="", Used=1)
2017-03-27 22:38:03.035 Error: (X2200W) 'CDevice_init' failed 'TypeError':'argument 8 must be str, not dict'.
2017-03-27 22:38:03.035 Error: Device creation failed, Device object is not associated with a plugin.
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff

sweup
Posts: 37
Joined: Friday 19 February 2016 14:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Generic Denon / Marantz python plugin

Post by sweup » Monday 27 March 2017 23:22

I followed the guide by installing from github, the folder and file is there but can't see it under the hardware tab. What name will it have there?

User avatar
Dnpwwo
Posts: 749
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Generic Denon / Marantz python plugin

Post by Dnpwwo » Tuesday 28 March 2017 5:20

@Boredcat,

Sounds like you aren't running a recent enough Domoticz beta. The Options argument changed recently (to be a dictionary) and the latest plugin is aligned to that change.

If you update to the latest beta it should create the additional devices.

@sweup,

If you are running the stable Domoticz version you won't see it because it isn't supported. If you are running the current beta it will show up as 'Denon AVR 4306'.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw

sweup
Posts: 37
Joined: Friday 19 February 2016 14:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Generic Denon / Marantz python plugin

Post by sweup » Tuesday 28 March 2017 8:42

Dnpwwo wrote:@Boredcat,

@sweup,

If you are running the stable Domoticz version you won't see it because it isn't supported. If you are running the current beta it will show up as 'Denon AVR 4306'.
Thanks, i see that one. I thought that one was another, the example version.

Thanks for plugin

Boredcat
Posts: 44
Joined: Friday 17 March 2017 10:31
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Generic Denon / Marantz python plugin

Post by Boredcat » Tuesday 28 March 2017 8:45

@Dnpwwo

Now running a beta version and after removing and adding the receiver/plugin is working as expected. Thnx for your help.
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Generic Denon / Marantz python plugin

Post by G3rard » Friday 31 March 2017 0:28

Dnpwwo wrote:@Artemgy,

Latest version:plugin v2.5.4.rarYou should delete the current hardware and recreate it with this one. Features are:
  • Better aligned to Domoticz standards, creates all devices in the Device tab only
  • Less user configuration, auto-detects zone support and adds zones that are supported
  • Simplified (and more reliable logic), the current one was developed in parallel with the python framework (and it showed).
  • Optimised polling
Plugins current recieve all notifications from Domoticz and can choose what to do with them but currently they don't trigger them. This is on the enhancement list.
Thanks for this new version!
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests