[RELEASED] Python plugin to control Onkyo receivers

Python and python framework
Post Reply
User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

[RELEASED] Python plugin to control Onkyo receivers

Post by jorgh » Sunday 26 February 2017 11:35

Edit:
The Onkyo plugin can now be found on GitHub, the command line tool is still attached to this post.
https://github.com/jorgh6/domoticz-onkyo-plugin

Hi All,

I've created a command line Python script to control Onkyo receivers (power, input and volume, also for zone2). Although it's not a Domoticz plugin, it can be used to control the receiver through the On Action / Off Action script interface.

To use the script from Domoticz, put it in /home/pi/domoticz/scripts/

The script can be called from the command line with the --help argument, to get usage information.

Example: To power on the receiver and put in on input 5 with a volume of 20 the command is:
onkyocmd.py --power on --input 5 --volume 20
To control zone 2, add --zone2 to the command line.

To do this from a Domoticz switch, put 'script:///home/pi/domoticz/scripts/onkyocmd.py --power on --input 5 --volume 20' in the On Action field of a (dummy) switch.

To figure out the input numbers of your receiver, set the receiver to the desired input and call onkyocmd.py with the --state parameter. It will then list the current Power, Input and Volume.

Feel free to use/change the script, or if you have some spare time, create a proper Domoticz plugin ;-)
Attachments
onkyocmd.zip
(2.43 KiB) Downloaded 249 times
Last edited by jorgh on Monday 27 March 2017 16:32, edited 4 times in total.

zak45
Posts: 503
Joined: Sunday 22 January 2017 12:37
Target OS: Windows
Domoticz version: V3.9056
Contact:

Re: Python script to control Onkyo receivers

Post by zak45 » Sunday 26 February 2017 13:10

That's great... will give it a try.

jake
Posts: 410
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python script to control Onkyo receivers

Post by jake » Monday 27 February 2017 0:27

I control my Onkyo according the setup as described in the wiki pages about Onkyo receivers. However, it is too bad that everything has to be pulled from the receiver, while the standard Onkyo app receives push messages. Whatever I do with the IR remote or physical buttons on the receiver, the standard app shows the update immediately. It would be nice if Domoticz could have the same level of status updates of the receiver, because pulling the updates every minute is a waste, plus much too late in case there is a change.

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python script to control Onkyo receivers

Post by jorgh » Monday 27 February 2017 9:10

It is possible to receive push messages from the Onkyo in the same fashion as the App. However, someone needs to write a proper pluging for this. Maybe if I've some spare time I will write it myself, but I'm currently working on some other projects.
If someone has some spare time right now, they could grab my code and beat me to it ;-).
All Onkyo codes can be found on the web to basically do far more than the Onkyo app is capable of.
Last edited by jorgh on Friday 03 March 2017 12:10, edited 1 time in total.

jake
Posts: 410
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python script to control Onkyo receivers

Post by jake » Thursday 02 March 2017 18:35

Would be awesome to have, but way beyond my skills unfortunately.

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python script to control Onkyo receivers

Post by jorgh » Thursday 02 March 2017 20:00

All,

Well, I couldn't help myself, so I've started on the Onkyo plugin ;-)
However, there is a small issue with the plugin system and handling non text communication.
It is however being worked on by the dev's so it's going to be resolved :-)
As soon as I get my hands on some new beta code I will continue the development.
Keep you posted.

Regards,

Jorg
Last edited by jorgh on Friday 03 March 2017 12:10, edited 1 time in total.

jake
Posts: 410
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python script to control Onkyo receivers

Post by jake » Thursday 02 March 2017 21:18

Would it be possible to send display text to the receiver? When it is playing from an internet radio station, the station name is shown. I would like to send Kodi played content title to the receiver. Unfortunately with the current tools this is not possible.

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python script to control Onkyo receivers

Post by jorgh » Thursday 02 March 2017 21:22

@jake,

I've not seen such an option. Everything that can be controlled though the network is documented at: https://github.com/miracle2k/onkyo-eisc ... mands.yaml

I'll concentrate on power volume and input for now. If that works, I'll add features on request (and available time ;-) )

jake
Posts: 410
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python script to control Onkyo receivers

Post by jake » Thursday 02 March 2017 21:42

OK, 1 additional request: adjust listening mode. I do that now as well, to chose 5ch stereo for audio through Kodi and 'digital theater' for video through Kodi. When Kodi stops, the script is supposed to store the current mode into an variable.
Unfortunately this doesn't always work and of course no feedback except too frequent and not needed polling with current tools.

swevm
Posts: 24
Joined: Friday 16 September 2016 20:04
Target OS: Raspberry Pi
Domoticz version: 8718
Location: Sweden
Contact:

Re: Python script to control Onkyo receivers

Post by swevm » Saturday 04 March 2017 15:46

Joerg,

This is great :D
I have a TX-NR828 that I have currently integrated with Domoticz through Node-red. Unfortunately Node-red stop recieving pushed events from the reciever from time to time. Not sure what happens. Have seen similar behavior in the Onkyo python2mqtt python application. Most of the times its sorted out by pulling power plug to reciever.

I´m interested in your plugin. Any chance you can share it? I´m happy to help enhance but its been some time since I did anything with Python.

/Magnus
jorgh wrote:All,

Well, I couldn't help myself, so I've started on the Onkyo plugin ;-)
However, there is a small issue with the plugin system and handling non text communication.
It is however being worked on by the dev's so it's going to be resolved :-)
As soon as I get my hands on some new beta code I will continue the development.
Keep you posted.

Regards,

Jorg
Domoticz on RPi3 with Razberry: 10xZME WALLC-S, 14x Fib Switch, 6x Fib Wallplug, 1x Fib Motion Sensor, 2x Fib Smoke Sensor, 1x Fib Universal sensor (with 1-wire), 3x SwiidInter cordsw, ESPEasy [1-wire and relay], Kodi, Node-Red [Onkyo NR-828, UI etc]

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python script to control Onkyo receivers

Post by jorgh » Saturday 04 March 2017 22:18

@swevm,

I'll definitely post it on this forum as soon as I have something that works. For now, we need to wait on some fixes to Domoticz before I can continue development, as it is currently not possible to send and receive binary data using the plugin framework. This should be fixed soon by the devs.
I've already developed most of the code in stand alone python scripts and have earlier written a kodi plugin, so with most of the code lying around, it should not take me a lot of time.

Regards,

Jorg

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

Re: Python script to control Onkyo receivers

Post by Dnpwwo » Sunday 05 March 2017 2:33

@jorgh,

Can you give it another go using the Python-Plugins branch. I haven't tried all combinations of transports and protocols but it compiles and runs on Windows and Linux and will dump the messages in hex and text if you set

Code: Select all

Domoticz.Debugging(1)
output is something like this:

Code: Select all

2017-03-05 11:27:55.510 (CG-100-12) Transport set to: 'TCP/IP', 192.168.xxx.xxx:4998.
2017-03-05 11:27:55.510 (CG-100-12) Protocol set to: 'Line'.
2017-03-05 11:27:55.510 (CG-100-12) Connect directive received, transport connect initiated successfully.
2017-03-05 11:27:55.510 (CG-100-12) Heartbeat interval set to: 30.
2017-03-05 11:27:55.562 (CG-100-12) Calling message handler 'onConnect'.
2017-03-05 11:27:55.562 (CG-100-12) onConnect called
2017-03-05 11:27:55.562 (CG-100-12) Connected successfully to: 192.168.xxx.xxx:4998
2017-03-05 11:27:55.562 (CG-100-12) Sending 11 bytes of data:.
2017-03-05 11:27:55.562 (CG-100-12) 67 65 74 64 65 76 69 63 65 73 0d .. .. .. .. .. .. .. .. .. getdevices.
2017-03-05 11:27:55.613 (CG-100-12) Received 17 bytes of data:.
2017-03-05 11:27:55.613 (CG-100-12) 64 65 76 69 63 65 2c 31 2c 31 20 53 45 52 49 41 4c .. .. .. device,1,1.SERIAL
2017-03-05 11:27:55.613 (CG-100-12) Calling message handler 'onMessage'.
2017-03-05 11:27:55.614 (CG-100-12) Received 17 bytes of data:.
2017-03-05 11:27:55.614 (CG-100-12) 64 65 76 69 63 65 2c 32 2c 31 20 53 45 52 49 41 4c .. .. .. device,2,1.SERIAL
2017-03-05 11:27:55.614 (CG-100-12) Calling message handler 'onMessage'.
2017-03-05 11:27:55.614 (CG-100-12) Received 16 bytes of data:.
2017-03-05 11:27:55.615 (CG-100-12) 64 65 76 69 63 65 2c 33 2c 33 20 52 45 4c 41 59 .. .. .. .. device,3,3.RELAY
2017-03-05 11:27:55.615 (CG-100-12) Calling message handler 'onMessage'.
... 
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

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python script to control Onkyo receivers

Post by jorgh » Sunday 05 March 2017 18:35

@Dnpwwo,

Tried compiling the code, it fails with:

Code: Select all

/home/pi/Domoticz-Python-Plugins/hardware/plugins/PluginTransports.cpp: In member function ‘virtual void Plugins::CPluginTransportTCP::handleWrite(const std::vector<unsigned char>&)’:
/home/pi/Domoticz-Python-Plugins/hardware/plugins/PluginTransports.cpp:167:119: error: cannot pass objects of non-trivially-copyable type ‘const class std::vector<unsigned char>’ through ‘...’
     _log.Log(LOG_ERROR, "%s: Socket error during 'write_some' operation: %d '%s'", __func__, pMessage.size(), pMessage);
I commented out the line, as it's only a log entry, to see if the rest compiles successfully. And I can confirm it does :-)

Regards,

Jorg

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

Re: Python script to control Onkyo receivers

Post by Dnpwwo » Sunday 05 March 2017 22:39

@jorgh,

Just noticed that myself, no idea why it compiled on Ubuntu but not my old Raspy 1. Fixed and pushed to git
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

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python plugin to control Onkyo receivers

Post by jorgh » Monday 06 March 2017 21:31

@Dnpwwo,

Indeed the code now compiles correctly. And I'm successfully sending and receiving the data, have not found any issues up till now :D .

Regards,

Jorg

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

Re: Python plugin to control Onkyo receivers

Post by Dnpwwo » Monday 06 March 2017 21:49

@jorgh,

Good news :!: I have done some more testing and it seems backwards compatible and stable so I will look to merge it into the main branch in the next day or so.

thanks.
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

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python plugin to control Onkyo receivers

Post by jorgh » Monday 06 March 2017 23:18

@Dnpwwo,

I've hit another issue :(

If I request the receiver configuration, it sends 7390 bytes of information. After this Domoticz is dead. I get no plugin onHeartbeat calls anymore, and the Domoticz web interface is also completely unresponsive, until I restart Domoticz.
I've already tested with commands that produce smaller responses and they all seem to work normally. I suspect there is some buffer overflow causing Domoticz to lockup.

Hope you can look into this issue.

Edit: As there is always the next device that sends even more data, messages could also be split and send to the Python plugin using subsequent onMessage calls. The plugin is then responsible, for concatenating the data. This is already in my code, as reading from a TCP stream, you never know when you have all data ;-).

Kind regards,

Jorg

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

Re: Python plugin to control Onkyo receivers

Post by Dnpwwo » Tuesday 07 March 2017 15:12

@jorgh,

Can you post a log and your plugin? The code should handle that kind of volume, it works in 4K chunks (but so does TCP/IP), I can allocate extra buffers if required but I want to be kind to small systems if possible.
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

User avatar
jorgh
Posts: 149
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Python plugin to control Onkyo receivers

Post by jorgh » Wednesday 08 March 2017 12:37

@Dnpwwo,

I've done some more research, and it is not an issue in the onMessage function, receiving data.
The problem arises when instantiating the XMLRoot object.
I've created a small server and test plugin that reproduce the issue. I've attached this to this post.

You should be able to reproduce the issue easily (at least on a Pi)

Kind regards,

Jorg
Attachments
Reproduction.zip
(3.03 KiB) Downloaded 44 times

jake
Posts: 410
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python plugin to control Onkyo receivers

Post by jake » Saturday 11 March 2017 14:33

Just wondering, what is the reaction time on a command to the receiver with this plugin? With the current described method it usually takes about 2 or 3 seconds before a command is executed.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests