Page 1 of 1

Python plugin works from terminal, but can't execute from Domoticz

Posted: Monday 27 November 2017 11:21
by sammyke007
Hi

I wrote a simple Python plugin to control my Pioneer AVR. I can only control my AVR over Telnet commands so I've been searching how to send these commands in Python.
I'm running the latest stable Domoticz package on a Synology NAS.

This is the Python script named piomute.py:

Code: Select all

#!/usr/bin/python

import getpass
import sys
import telnetlib


tn = telnetlib.Telnet("192.168.1.46",8102)

tn.write("VU\n\r")

tn.close()
It's placed in /usr/local/domoticz/var/scripts/python/piomute.py

When I run the script in Terminal or using WinSCP (python piomute.py), it works, and it turns my volume 1 step up.

However, when I run it from a dummy switch, I keep getting

Code: Select all

2017-11-27 10:55:26.878 Executing script: /usr/local/domoticz/var/scripts/python/piomute.py
2017-11-27 10:55:26.887 Error: Error executing script command (/usr/local/domoticz/var/scripts/python/piomute.py). returned: 32256
I also tried to put in a LUA script (on device change -> os.execute(/usr/local/domoticz/var/scripts/python/piomute.py)), but nothing happens...

The permissions are set to 755, the owner of piomute.py is set to domoticz.

Any idea please?

Re: Python plugin works from terminal, but can't execute from Domoticz

Posted: Monday 27 November 2017 12:05
by febalci
Try viewtopic.php?t=4998. There 0777 is used. I believe you missed using 'python3': os.execute(/usr/local/domoticz/var/scripts/python/piomute.py)) whereas should be 'python3 piomute.py' with also the path of python3?

Re: Python plugin works from terminal, but can't execute from Domoticz

Posted: Monday 27 November 2017 12:19
by sammyke007
Permissions set to 777 - same error
Owner set to root - same error

Wrote a little LUA script and edited it after reading reply above using:

Code: Select all

commandArray = {}

if devicechanged['test'] == 'On' then
    os.execute('/usr/local/python/bin/python /volume1/@appstore/domoticzscripts/piovu.py')
    commandArray["test"]='Off'
end

return commandArray
This works!!!

The on/off command using script:///... also works using

Code: Select all

script:///usr/local/python/bin/python /volume1/@appstore/domoticzscripts/piovu.py
So you need to define the Python path...
Thank you for the great tip!

Now on to writing one script for all commands instead of one script per command :D

Re: Python plugin works from terminal, but can't execute from Domoticz

Posted: Wednesday 29 November 2017 3:20
by Dnpwwo
@sammyke007,

Python Plugins use the Python Framework that comes with Domoticz to interface external hardware. They run within Domoticz and are indistinguishable from native hardware support. Technically you are creating scripts which is not quite the same thing.

That said, there are a number of amplifier plugins already that control devices over Telnet that you could probably use as a starting point to connect to your Pioneer AVR. There is a Denon/Marantz example plugin that ships with Domoticz (under domoticz/plugins/examples) that you could look at and there is a Yamaha one as well that you can find by looking in the forum.

These plugins are 2 way so that you can control the amplifier as well as reflect the changes made to it by remotes (or even actually touching the amp physically) which gives a much better result than calling out from Lua.

Have a look and good luck :D

Re: Python plugin works from terminal, but can't execute from Domoticz

Posted: Wednesday 29 November 2017 8:18
by febalci
Just by chance, i also started to write a Pioneer AVR plugin by a fork from https://github.com/oohlaf/domoticz-pioneer-avr. Give me some days, hope i will keep on my concentration :D

Re: Python plugin works from terminal, but can't execute from Domoticz

Posted: Thursday 30 November 2017 22:55
by sammyke007
That would be great, tnx!