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

Python and python framework

Moderator: leecollings

Post Reply
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

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

Post 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?
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post 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?
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

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

Post 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
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post 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
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
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

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

Post 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
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

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

Post by sammyke007 »

That would be great, tnx!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 1 guest