Page 1 of 14
[RELEASED] Python plugin to control Onkyo receivers
Posted: Sunday 26 February 2017 10:35
by jorgh
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

Re: Python script to control Onkyo receivers
Posted: Sunday 26 February 2017 12:10
by zak45
That's great... will give it a try.
Re: Python script to control Onkyo receivers
Posted: Sunday 26 February 2017 23:27
by jake
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.
Re: Python script to control Onkyo receivers
Posted: Monday 27 February 2017 8:10
by jorgh
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.
Re: Python script to control Onkyo receivers
Posted: Thursday 02 March 2017 17:35
by jake
Would be awesome to have, but way beyond my skills unfortunately.
Re: Python script to control Onkyo receivers
Posted: Thursday 02 March 2017 19:00
by jorgh
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
Re: Python script to control Onkyo receivers
Posted: Thursday 02 March 2017 20:18
by jake
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.
Re: Python script to control Onkyo receivers
Posted: Thursday 02 March 2017 20:22
by jorgh
@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

)
Re: Python script to control Onkyo receivers
Posted: Thursday 02 March 2017 20:42
by jake
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.
Re: Python script to control Onkyo receivers
Posted: Saturday 04 March 2017 14:46
by swevm
Joerg,
This is great
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
Re: Python script to control Onkyo receivers
Posted: Saturday 04 March 2017 21:18
by jorgh
@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
Re: Python script to control Onkyo receivers
Posted: Sunday 05 March 2017 1:33
by Dnpwwo
@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
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'.
...
Re: Python script to control Onkyo receivers
Posted: Sunday 05 March 2017 17:35
by jorgh
@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
Re: Python script to control Onkyo receivers
Posted: Sunday 05 March 2017 21:39
by Dnpwwo
@jorgh,
Just noticed that myself, no idea why it compiled on Ubuntu but not my old Raspy 1. Fixed and pushed to git
Re: Python plugin to control Onkyo receivers
Posted: Monday 06 March 2017 20:31
by jorgh
@Dnpwwo,
Indeed the code now compiles correctly. And I'm successfully sending and receiving the data, have not found any issues up till now

.
Regards,
Jorg
Re: Python plugin to control Onkyo receivers
Posted: Monday 06 March 2017 20:49
by Dnpwwo
@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.
Re: Python plugin to control Onkyo receivers
Posted: Monday 06 March 2017 22:18
by jorgh
@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
Re: Python plugin to control Onkyo receivers
Posted: Tuesday 07 March 2017 14:12
by Dnpwwo
@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.
Re: Python plugin to control Onkyo receivers
Posted: Wednesday 08 March 2017 11:37
by jorgh
@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
Re: Python plugin to control Onkyo receivers
Posted: Saturday 11 March 2017 13:33
by jake
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.