Script -Error - Returned: 256

Python and python framework

Moderator: leecollings

Post Reply
vicenschamorro
Posts: 2
Joined: Wednesday 22 July 2015 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.9443
Location: Sant Cugat del Valles (Spain)
Contact:

Script -Error - Returned: 256

Post by vicenschamorro »

Hi All,

I'm a novice in Domoticz. I've configured correctly a couple of ZWave devices. The problem I have is that I cannot execute scripts in a Raspberry Pi 2 environment.

I've read a lot about this topic in the forums and internet but I have not be able to find a solution.

All the attempts has been unsuccessful. Always the error I see in the log from Domoticz is the same:

"Error: Error executing script command (/home/pi/domoticz/scripts/play_radio_sonos.py). returned: 256"

I've tried:

1. Add 777 permisions to the script file
2. Reboot pi and domoticz
3. Add a third "/" in the domoticz - On Action
4. Write the script in bash or python
5. Move the script to another locations

and probably other scenarios that now I cannot remember.

One important point is that if I execute the script using the "pi" user, I don't have any problem.

Any idea?

Thanks!!!
Vicens
Raspberry PI 3 - Aeon S2 stick - Aeon Multisensor - Belkin Wemo Switch - Sonos Player1 - Xiaomi Gateway + sensors
vicenschamorro
Posts: 2
Joined: Wednesday 22 July 2015 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.9443
Location: Sant Cugat del Valles (Spain)
Contact:

Re: Script -Error - Returned: 256

Post by vicenschamorro »

Hi all,

I've been all the weekend trying alternatives without any progress.... Do you have some idea? :-(

Thanks!
Raspberry PI 3 - Aeon S2 stick - Aeon Multisensor - Belkin Wemo Switch - Sonos Player1 - Xiaomi Gateway + sensors
zaadstra
Posts: 23
Joined: Saturday 06 September 2014 15:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Script -Error - Returned: 256

Post by zaadstra »

Today I've been debugging this "feature" for the second time.

First case, I ran a script with parameters, and one parameter was incorrect and the script wasn't too happy about that. The commandline showed that quickly.

Today, another script was tested on commandline first and happily ran there, but not as Action in Domoticz. This time it appeared that a config file was not used/not found but no clear error given.

2015-08-05 21:33:02.885 Error: Error executing script command (/home/pi/pushover/pushover.sh). returned: 256
2015-08-05 21:43:51.274 Error: Error executing script command (/home/pi/domoticz/scripts/pushover.sh). returned: 256

The problem was solved when I added extra parameters to the script line (the ones it should read from it's file in /home/pi/.config/

So tweak a little with your script and/or parameters, good luck :D
oliviers
Posts: 73
Joined: Wednesday 16 September 2015 22:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Paris area, France
Contact:

Re: Script -Error - Returned: 256

Post by oliviers »

Hi,
Like several others, I'm also unable to execute scrits from an On/off virtual swith.... They result in "errror 256"..

Code: Select all

2015-09-25 21:09:04.325 Executing script: /home/pi/domoticz/scripts/listen_radio.sh
2015-09-25 21:09:43.315 Error: Error executing script command (/home/pi/domoticz/scripts/listen_radio.sh). returned: 256
2015-09-25 21:09:44.324 Executing script: /home/pi/domoticz/scripts/stop_radio.sh
2015-09-25 21:09:45.064 Error: Error executing script command (/home/pi/domoticz/scripts/stop_radio.sh). returned: 256
Both scripts run just fine when executed from the command line.
Both scripts are owned by "pi" and have proper execution flags:

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ ls -l *radio*
-rwxrwxrwx 1 pi pi 103 Sep 25 17:06 listen_radio.sh
-rwxr-xr-x 1 pi pi  59 Sep 25 18:06 stop_radio.sh
I have tried with two or three '/' in the swith configuration:
script:///home/pi/domoticz/scripts/listen_radio.sh
script:///home/pi/domoticz/scripts/stop_radio.sh

Script contents are quite simple:

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ cat listen_*
#!/bin/bash
echo RADIO CLASSIQUE
mplayer -noconsolecontrols -playlist /home/pi/domoticz/playlist.txt
and

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ cat stop*
#!/bin/bash
sudo /usr/bin/killall mplayer > /dev/nul
Anyone has an idea ?

Oliviers

EDIT:
This is solved.
1. If any command in the script sends messages to the console, make sure you redirect the output somewhere ( > /dev/null)
(In my example above, this is the case of the mplayer command)
2. If any command "never ends/never returns" (like the mplayer radio streaming in my case), put an "&" at the end of the command to let the script continue and finish
Paris area
Raspberry Pi 4 - RFXComm 433 - IrTrans - Zwave
jpinzon408
Posts: 1
Joined: Friday 21 October 2016 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by jpinzon408 »

Hi, for ON/OFF works for me this way,
for ON: script:///path/yourpythonprogramON.sh

Code: Select all

#!/bin/sh
python yourpythonprogram.py > /dev/null 2>&1 &
exit 0
and OFF: only script:///path/yourpythonprogramOFF.py

I hope you find this information useful.
Larka
Posts: 2
Joined: Monday 07 November 2016 22:29
Target OS: Linux
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by Larka »

zaadstra wrote:Today I've been debugging this "feature" for the second time.

First case, I ran a script with parameters, and one parameter was incorrect and the script wasn't too happy about that. The commandline showed that quickly.

Today, another script was tested on commandline first and happily ran there, but not as Action in Domoticz. This time it appeared that a config file was not used/not found but no clear error given.

2015-08-05 21:33:02.885 Error: Error executing script command (/home/pi/pushover/pushover.sh). returned: 256
2015-08-05 21:43:51.274 Error: Error executing script command (/home/pi/domoticz/scripts/pushover.sh). returned: 256

The problem was solved when I added extra parameters to the script line (the ones it should read from it's file in /home/pi/.config/

So tweak a little with your script and/or parameters, good luck :D

I thought I would post my findings from when I had the same problem. Since my domoticz run as root, the scripts were executed as root as well. So in my case it tried to find the config files in /root/.config/xxx and then failed

Maybe someone will find this useful.
MikeNg
Posts: 6
Joined: Tuesday 07 June 2016 4:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by MikeNg »

Got the same issue with the playcode.py script running from on/off action of a domoticz switch. Checked in the log it say error executing script returned 256. Running the script from SSH comand line it works perfectly.
Stefan
Posts: 6
Joined: Tuesday 27 June 2017 9:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Script -Error - Returned: 256

Post by Stefan »

I`m also facing issues with this. My switch triggers two scripts, on and off. It throws the error 256 on both on and off action, however the on does get executed and turns on the purifier. I can`t understand why, since the scripts look exactly the same, both are owned by root and permission 777 had been applied.

ON:

Code: Select all

#!/usr/bin/lua
commandArray = {}
if (devicechanged['Air Purifier'] == 'On') then
    os.execute ('node /etc/domoticz/scripts/xiaomi/airpurifier.js 192.168.1.20 power true > /dev/null')
end
return commandArray
OFF:

Code: Select all

#!/usr/bin/lua
commandArray = {}
if (devicechanged['Air Purifier'] == 'Off') then
    os.execute ('node /etc/domoticz/scripts/xiaomi/airpurifier.js 192.168.1.20 power false')
end
return commandArray

Code: Select all

root@stf-pi:/etc/domoticz/scripts/xiaomi# pwd
/etc/domoticz/scripts/xiaomi
root@stf-pi:/etc/domoticz/scripts/xiaomi# ls
airpurifier.js  air_purifier_off.lua  air_purifier_on.lua

Code: Select all

2017-07-29 19:36:22.376 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_on.lua). returned: 256
2017-07-29 19:36:32.979 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_off.lua). returned: 256
2017-07-29 19:39:17.320 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_on.lua). returned: 256
2017-07-29 19:39:27.036 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_off.lua). returned: 256
2017-07-29 19:41:07.420 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_on.lua). returned: 256
2017-07-29 19:41:15.853 Error: Error executing script command (/etc/domoticz/scripts/xiaomi/air_purifier_off.lua). returned: 256
fan.JPG
fan.JPG (44.71 KiB) Viewed 12823 times
Can somebody help pls?
oliviers
Posts: 73
Joined: Wednesday 16 September 2015 22:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Paris area, France
Contact:

Re: Script -Error - Returned: 256

Post by oliviers »

Hi,
The answer is above in this thread. You need an "intermediate" script which launches your lua sript with an "&" at the end of the command line to return to Domoticz without waiting. See my post of Sept 16 2015 and the post from jpinzon408 dated 21 Oct 2016.
Rgds,
Oliviers
Paris area
Raspberry Pi 4 - RFXComm 433 - IrTrans - Zwave
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

Re: Script -Error - Returned: 256

Post by EdddieN »

Hello

Reviving this.

I'm doing a simple pmrestart.sh

Code: Select all

#!/bin/sh
/usr/bin/pm2 restart all
my pmrestart.sh has a 755 and works from shell. But when I try to execute it within Domoticz I get the 256 error on the log file.

I have other SH files that work fine no idea why I'm wrong here. Any help?
11101101 - www.machinon.com
timmpo
Posts: 14
Joined: Sunday 24 February 2019 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by timmpo »

old thread but ...
When one of this problem hit me, was it because my python library environment path not was set when run from root/sudo
domoticz run python scripts with sudo/root environment path's

Stop Domoticz service:

Code: Select all

sudo /etc/init.d/domoticz.sh stop
Run Domoticz direct from terminal:

Code: Select all

./home/pi/domoticz/domoticz
Run the script from inside domoticz (pushbutton etc..)
now you shuld see in terminal what cuase the problem
pic.png
pic.png (60.78 KiB) Viewed 6094 times
you can run this python code to check your environment path's the user using

Code: Select all

import sys
print (sys.path)
pic2.png
pic2.png (29.07 KiB) Viewed 6094 times
for me sudoers missing /home/pi/.local/lib/python2.7/site-packages
to fix that you can add this directly in your python code

Code: Select all

import sys
sys.path.append('/home/pi/.local/lib/python2.7/site-packages')
User avatar
Keptenkurk
Posts: 103
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Script -Error - Returned: 256

Post by Keptenkurk »

old thread but...
timmpo, thanks for sharing your solution, it saved my day! (after all other fixes about rights, wrapping the python script in a bash shell etc failed).
My newly installed and imported lib was just not in the path...
/paul
damdub
Posts: 38
Joined: Tuesday 31 December 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by damdub »

Hello all,

I read and followed solutions provided here with no luck.
I have a .sh script which I fire from a switch in domoticz.
The script is supposed to change a switch configuration via telnet communication.
The script is working from console with no error.
The script is working from Domoticz but leaves an error in logs
Error executing script command (/home/pi/domoticz/scripts/remote_HP_switch.sh). returned: 256

The script is

Code: Select all

#!/bin/sh

HOST='***.***.***.***' /IP address of the switch
CMD1='conf'
CMD2='interface 1 enable"

(
echo open "$HOST"
sleep 0.2
echo "$x"
sleep 0.2
echo "$CMD1"
sleep 0.2
echo "$CMD2"
sleep 0.2
echo "exit"
) | telnet
The script file permissions is rwx for everyone

I could live with the error as the script is running OK but I would prefer to understand what I'm doing wrong

Any idea someone ?

Thank you very much
Damien
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Script -Error - Returned: 256

Post by FireWizard »

Hi, @damdub

Please, have a look at: viewtopic.php?f=6&t=30657&p=231907#p231907

Perhaps the solution at the end, mentioned by DewGew is also suitable for you.

Best regards
damdub
Posts: 38
Joined: Tuesday 31 December 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by damdub »

Hello FireWizard
Thank you for taking care of this case
I haven't tried your suggestion yet but are you sure it could change something for me ? I doubt that because in my case the script runs and does what I want him to do. The command reaches my HP switch and the configuration is changed as asked in the script. But there is an error code 256 in the domoticz logs.

Damien
damdub
Posts: 38
Joined: Tuesday 31 December 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script -Error - Returned: 256

Post by damdub »

Hello
I've found the solution.
I had to close the telnet communication properly at the end of the script by adding a exit 0

For anyone interrested in scripting HP Switch config, my working script is now

Code: Select all

#!/bin/sh

HOST='***.***.***.***' /IP address of the switch
CMD1='conf'
CMD2='interface 1 enable"

(
echo open "$HOST"
sleep 0.2
echo "$x"
sleep 0.2
echo "$CMD1"
sleep 0.2
echo "$CMD2"
) | telnet > /dev/null
exit 0
Thank you for your help
Damien
OldPensionado
Posts: 22
Joined: Wednesday 01 March 2017 9:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Script -Error - Returned: 256

Post by OldPensionado »

@timmpo: many thanks! Your solution about an incomplete PATH variable saved my weekend!
Especially the suggestion about running Domoticz from the terminal and then printing sys.path was extremely clarifying.

Thanks again!

(And yes, I know: it's an old thread but who cares! I'm old too...)
RPi 1, model B, Rev. 2; RPi 3B+; RPi Zero; RPi 4B
Raspbian 10 (Buster)
Domoticz V2022.2

Well, such is life. And it's getting sucher and sucher...
nigels0
Posts: 221
Joined: Thursday 23 January 2014 12:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Script -Error - Returned: 256

Post by nigels0 »

A good check before doing anything is to run the script with sudo beforehand. It should give an idea where the problems are.

I found that with my python scripts, I needed to install a library again using sudo pip install <libraryname> - saves having to edit the path.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests