openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

[WIP] Denon/Marantz 2.0 Binding #2204

Closed jwveldhuis closed 6 years ago

jwveldhuis commented 7 years ago

Hi all,

I started to work on a 2.0 Binding for Denon/Marantz AVR's. The 1.x Binding created by @idserda isn't working OK in OH2 and it doesn't seem like an easy upgrade to 2.0 from the existing code base, so I decided to start from scratch (and of course will reuse bits and pieces of the controlling logic were possible, the code of the 1.x Binding is well written). Let me know if someone else already started on this so we can collaborate.

As I did not develop any OH Binding before, so it will take me some time to get acquainted with the development process. Already got the IDE up and running and a skeleton binding working (thanks to the excellent documentation on docs.openhab.org and eclipse.org/smarthome :+1:)

I'm looking at the existing Pioneer, Yamaha and Onkyo Bindings for inspiration. When the time is there I need testers, as I only own 1 Marantz AVR myself ;)

Any advice I should look into before starting the implementation?


Update - 30 December 2017

The binding is almost finished and I'll sent it in for review soon. In the meantime you can install the binding manually:

jwveldhuis commented 6 years ago

@mishakim yes the binding should see that, but only if you have configured the receiver to remain on standby while turned off. There is a setting called 'IP Control' which should be set to 'Always on'. Otherwise, the binding cannot connect to the receiver and hence can't determine its state.

mishakim commented 6 years ago

Thanks - I do have IP control set to Always on, so I'll do some testing and figure out what's not working.

jwveldhuis commented 6 years ago

Update to all BETA users Just pushed a new updated binding after processing review comments. Most important change that might affect you: I have changed the unit for the polling interval from milliseconds to seconds. The default is 5 seconds (smaller is not allowed). Whenever you update to the latest jar, you might need to update the old value of 5000 to 5.

@reyem the TypeResolver error should be gone now

Made some changes that should improve the stability. Detection of zone count is now done during the discovery. When updating the zone count in the configuration the zones are added/removed accordingly.

mishakim commented 6 years ago

I'm finding that my problem is not just power - no changes made directly to the receiver, by any means other than openHAB, results in an update. If I change things through openHAB, that works, but if I change them by hand, by IR, or by Denon iOS app, that is not reflected in the state of Items. The only channels I'm trying are power, source, and volume. I did update to the new version today, that didn't seem to change anything.

jwveldhuis commented 6 years ago

@mishakim HTTP or telnet? Did you update polling interval to 5? If you enable DEBUG or TRACE logging, what do you see?

mishakim commented 6 years ago

HTTP, poling interval is indeed 5. Nothing shows up on logs with either DEBUG or TRACE - I see outbound commands from openHAB, but nothing when I change it manually.

jwveldhuis commented 6 years ago

@mishakim you need to enable DEBUG for org.openhab.binding.denonmarantz, you will definitely see additional logging if http mode is active, otherwise your logging isn’t setup correctly.

mishakim commented 6 years ago

I wasn't clear - there are things in the log, but only for actions through openHAB. Nothing done manually causes any logging. Here's all it shows: 2018-02-05 13:54:36.395 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'PWON' 2018-02-05 13:54:59.063 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'SIMPLAY' 2018-02-05 13:55:22.461 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'SISAT/CBL' 2018-02-05 13:56:18.847 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'SIMPLAY' 2018-02-05 13:56:18.848 [TRACE] [ector.http.DenonMarantzHttpConnector] - Calling url http://10.0.1.6:80/goform/formiPhoneAppDirect.xml?SIMPLAY 2018-02-05 13:56:53.650 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'PWSTANDBY' 2018-02-05 13:56:53.651 [TRACE] [ector.http.DenonMarantzHttpConnector] - Calling url http://10.0.1.6:80/goform/formiPhoneAppDirect.xml?PWSTANDBY 2018-02-05 13:57:04.623 [DEBUG] [ector.http.DenonMarantzHttpConnector] - Sending command 'PWON' 2018-02-05 13:57:04.624 [TRACE] [ector.http.DenonMarantzHttpConnector] - Calling url http://10.0.1.6:80/goform/formiPhoneAppDirect.xml?PWON

All of those entries result from doing things in openHab. I was also turning it on and off and changing inputs manually and none of those were logged. I added TRACE at 13:56

jwveldhuis commented 6 years ago

@mishakim you should see things like this (TRACE should give more detail)

2018-02-05 20:55:23.617 [INFO ] [.c.h.DenonMarantzHttpConnector:118 ] - HTTP polling started.

2018-02-05 20:55:28.620 [TRACE] [.c.h.DenonMarantzHttpConnector:294  ] - Refreshing Denon status
2018-02-05 20:55:28.621 [TRACE] [.c.h.DenonMarantzHttpConnector:202  ] - Refreshing URL: http://192.168.178.14:80/goform/formMainZone_MainZoneXml.xml
2018-02-05 20:55:28.907 [TRACE] [.c.h.DenonMarantzHttpConnector:306  ] - result of getDocument for uri 'http://192.168.178.14:80/goform/formMainZone_MainZoneXml.xml':
<?xml version="1.0" encoding="utf-8" ?>
<item>
<FriendlyName><value>Woonkamer</value></FriendlyName>
<Power><value>ON</value></Power>
<ZonePower><value>ON</value></ZonePower>
...
2018-02-05 20:55:29.466 [TRACE] [.c.h.DenonMarantzHttpConnector:306  ] - result of getDocument for uri 'http://192.168.178.14:80/goform/formZone2_Zone2XmlStatusLite.xml':
<?xml version="1.0" encoding="utf-8" ?>
<item>
...
</item>
mishakim commented 6 years ago

Definitely not getting anything like that. If I manually enter the status URL in a browser, it gets valid results, so it seems like the binding is not polling

jwveldhuis commented 6 years ago

@mishakim you did enable TRACE? Strange indeed.. every exception that may occured should have resulted in any debug log entry..

mishakim commented 6 years ago

Yep - I have trace entries for outbound commands, like this: 2018-02-05 13:56:53.651 [TRACE] [ector.http.DenonMarantzHttpConnector] - Calling url http://10.0.1.6:80/goform/formiPhoneAppDirect.xml?PWSTANDBY, but no attempts to refresh

jwveldhuis commented 6 years ago

Ok, well I just discovered some exceptions might go unnoticed.. The polling is done in a separate Thread using a ScheduledExecutorService. I don't check for the result while it seems that is required, let me check this, will get back to you. Background: https://stackoverflow.com/a/24902026/2486310

So thank you for reporting this, definitely a bug I need to address!

mishakim commented 6 years ago

ah - good to know I'm not crazy!

jwveldhuis commented 6 years ago

@mishakim try with this jar, I included error reporting for the polling: https://www.dropbox.com/s/14mnyjkcfzuw2vl/org.openhab.binding.denonmarantz-2.3.0-SNAPSHOT.jar?dl=0 If this helps to find the issue I'll add it to the binding.

mishakim commented 6 years ago

It ran, and Trace showed a few updates, one for each zone, it looked like, then threw this error: 2018-02-05 16:02:28.945 [ERROR] [st.core.internal.thing.ThingResource] - Exception during HTTP PUT request for update config at 'things/denonmarantz:avr:0005cd2f3f4a/config' java.lang.IllegalArgumentException: Value must be between 0 and 100

all the details are here

The binding hasn't logged anything since except in response to my actions.

jwveldhuis commented 6 years ago

@mishakim interesting, thanks. BTW, this error is not logged by the code I added. It would have looked like this:

2018-02-05 21:38:33.007 [ERROR] [.c.h.DenonMarantzHttpConnector:130  ] - Error while polling Http: "Error Message" Stacktrace: 
....

Still, this piece of log you shared is exactly what I need. So it seems the value for Zone3 Volume is not in the 0 to 100 range, that is causing an error. For me http://<AVR-IP>/goform/formZone3_Zone3XmlStatusLite.xml (well for zone 2, I don't have 3 zones) it looks like this:

<item>
..
  <VolumeDisplay>
    <value>Absolute</value>
  </VolumeDisplay>
  <MasterVolume>
    <value>-58</value>
  </MasterVolume>
..
</item>

i.e. the volume starts is offset with 80 (0 = -80 dB). I guess for your model it displays the relative volume. In the code the 80 offset is substracted, which leads to the issue you have. What is the value for <VolumeDisplay> in your case? (Nevermind that, it is only showing the preference as configured in Setup -> Volume, it is not affecting the volume, at least not for my Marantz SR5008) What is the value for <MasterVolume> for you?

mishakim commented 6 years ago

Zone3 looks like this: `<?xml version="1.0" encoding="utf-8" ?>

OFF HDRADIO Relative -34 off ` Right before the latest version of that error, it logged this: `2018-02-05 16:43:55.534 [DEBUG] [nmarantz.handler.DenonMarantzHandler] - Received state OFF for channelID zone3Power 2018-02-05 16:43:55.535 [DEBUG] [nmarantz.handler.DenonMarantzHandler] - Received state 46 for channelID zone3Volume 2018-02-05 16:43:55.536 [DEBUG] [nmarantz.handler.DenonMarantzHandler] - Received state -34 for channelID zone3VolumeDB ` so it seems like it is correctly getting both decimal and dB volume numbers, but the dB isn't being handled right somewhere?
mishakim commented 6 years ago

PS, I'm not sure why I'm not getting line breaks inside my code tags here

jwveldhuis commented 6 years ago

@mishakim Please do the following: -remove the Thing -enable TRACE log for the binding (not sure it will add anything useful up to this point) -re-add the Thing -share the full log from the moment you added the Thing until the error occurs

Still a bit clueless under what circumstances this error occurs.

jwveldhuis commented 6 years ago

And, what is your Item definition? Did you perhaps assign a Dimmer type Item to the Zone3VolumeDB channel? (That would be wrong, Dimmer is for the non-dB channels, Number is for the dB channels)

jwveldhuis commented 6 years ago

Ok, I can reproduce your issue. It is caused when you assign a Dimmer item to the Number channel (which is not possible in the Paper UI, but possible when using the .items files). E.g. Dimmer test "test" {channel="denonmarantz:avr:0006781d58b1:zone2VolumeDB"} This breaks the binding..

Will check what to do about this, but for sure it's a configuration issue on your end.. ;)

mishakim commented 6 years ago

Yep, Zone3VolumeDB was a dimmer, I fixed that now. My various items were created in PaperUI, most were created from the Thing page by creating items within the channels. I also used Habmin for some setup, I don't recall if that's where I crated the zone 3 db volume dimmer.

I fixed the zone 3 item before removing and reading the Thing, then realized I'd broken logging completely in my attempt to create a separate file for denon. I fixed logging and restarted, and all seems to be working -- updates seem to be posting (I'll check power as soon as the kid's show is over ...)

mishakim commented 6 years ago

re-read your note about PaperUI, I think I must have created the volume dimmer in HabMin, when I hadn't figured out the "show more" to see the volume channels in Paper UI. It let me get away with it, and silently broke.

jwveldhuis commented 6 years ago

Well, that was 4 hours well spent 😛 @mishakim thanks for your input on this, it helps to make this better!

At the others: sorry for the spam in this thread, next time will search for an other place to do 1-on-1 issue resolution.. ;)

grzegorz914 commented 6 years ago

Hi,

I have this warning every time restart Openhab: (AVR-X6300H with Telnet connection)

2018-02-08 08:18:37.739 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Command for channel surroundProgram not supported.

it is normal? or something wrong.

P.S. - I use manually created items.

GRORI commented 6 years ago

I've just checked it at my setup and can see some additional messages at every restart of openhab (AVR-X3400H with telnet connection):

openhab.log:2018-02-08 08:28:59.176 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Command for channel album not supported. openhab.log:2018-02-08 08:28:59.175 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Command for channel artist not supported. openhab.log:2018-02-08 08:28:59.177 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Command for channel track not supported. openhab.log:2018-02-08 08:28:59.179 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Unsupported command REFRESH for channel command openhab.log:2018-02-08 08:28:59.173 [WARN ] [nmarantz.handler.DenonMarantzHandler] - Command for channel surroundProgram not supported.

jwveldhuis commented 6 years ago

@grzegorz914 @orificer that's normal:

Will see where I can change the WARN to DEBUG to avoid confusion.

grzegorz914 commented 6 years ago

Hello,

OK understod, other thongs if I change to HTTP mode then get this error (OFFLINE-COMMUNICATION ERROR):

2018-02-08 11:42:52.423 [hingStatusInfoChangedEvent] - 'denonmarantz:avr:xxxxxxxxx' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): IO error while connecting to AVR: Server returned HTTP response code: 403 for URL: http://192.168.1.6:8080/goform/formMainZone_MainZoneXml.xml

jwveldhuis commented 6 years ago

@grzegorz914 jep.. that's what you get with HTTP on a Heos model. Once the binding is accepted we can think about adding HTTP support for those. Need to find out what are the common HTTP / xml pages which can be used by all models. It's too much work now to cover that.

I'm aware of https://github.com/scarface-4711/denonavr/blob/master/denonavr/denonavr.py, there the approach is different.

IceBrainzz commented 6 years ago

Will it be possible to change more detailed setups like the dialog/subwoofer level adjust?

jwveldhuis commented 6 years ago

@IceBrainzz for now you can use the command Channel to set anything that the protocol allows. Reading those properties is not supported currently. You could use the Http Binding to fetch these if you really want to. There are hundreds of settings, only the most common are implemented.

IceBrainzz commented 6 years ago

@jwveldhuis As far as I know the HTTP interface is “disabled” for all Heos-based models (for example the X3400, which I have). When I try to open the IP of the AVR in a browser it gives me a 403 Forbidden, But for now the already implemented features are working like a charm, thank you for that.

jwveldhuis commented 6 years ago

@IceBrainzz I meant the HTTP Binding, not the Http mode, to pull specific info from the receiver into openhab. It won’t be easy, but it’s possible. On your model there is something possible on port 8080.

Mr-Eskildsen commented 6 years ago

I have an older Denon with only the serial interface. I have managed to setup an ESP8266 as a serial to Wifi gateway, and the Binding connects to the gateway as a charm. Awesome! @pabloNZ asked for the .things sample back in november. In case he didn't figure it out, mine is here: Thing denonmarantz:avr:avr3805-livingroom "Denon: AVR3805" @ "Denon" [ host="192.168.1.92", telnetEnabled=true ] If you need to set other/more parameters, find the names in the xml file in the code, where the parameters is defined. Change avr3805-livingroom to match your own name, and use that in the .items file. Remeber to change the host to something apropriate.

jwveldhuis commented 6 years ago

I'm pleased to announce the DenonMarantz binding got merged into the next 2.3.0 version of OpenHAB! Thanks all for giving feedback! Important: during review I had to change the names of the channels, this will impact everyone upgrading to the new binding. The channels make use of so-called 'channel groups' now. This leads to different names, e.g. general#power instead of power and zone2#volume instead of zone2Volume. Please have a close look at the updated README.md file here: https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.denonmarantz/README.md

I'm closing this issue now, as it was related to the binding under development.

gooman-uk commented 6 years ago

Any chance of making the receiver display brightness (the DIM command) available as a channel, rather than just as a command?

If it were a channel, it would be easy to add to HABpanel ... but as a command I can't even conceive how to begin!

jwveldhuis commented 6 years ago

@davidgurr no not planning to implement that. Note that a command is one-way only, so you should be able to send the brightness but can't request the current state of the brightness. Lookup the command to send in the Protocol documentation. Probably it's one of these:

DIM BRI DIM DIM DIM DAR DIM OFF

My Marantz SR5008 doesn't support this so can't test this myself.


General remark: this issue has been closed. Please raise a new issue or open a topic in the Community instead of commenting on this one.

gooman-uk commented 6 years ago

Yep, got the DIM commands working fine on my NR1506. From the command documentation, it looks like "DIM ?" should return the status, but I guess you don't have plans to support that either ... no biggy. Great work on the binding anyway!

desidia-pura commented 5 years ago

Hi could anyone help me? I've OH2 and installed at first the version from OH MArket (I think a modulation from OH1) That version founds my Marantz NR1504 but by adding to things I've got the error 409 - Conflict. I've googled and found this binding. I uninstalled the first version. I add the *jar file into the addons Folder from the second post. after restart it found my Marantz NR1504 but the same problem. After clicking "Add to things" I get the error 409 - Conflict and there's no marantz thing. How could I use it now? :-\

Thanks!

edit: I found an error into log:

2018-10-06 20:31:52.668 [WARN ] [g.discovery.internal.PersistentInbox] - Cannot create thing. No binding found that supports creating a thing of type denonmarantz:avr.

but I've got added the binding and it is under "Configuration - Bindings"

Or is that the old one?