Error executing script command returned: 256 Topic is solved

Python and python framework

Moderator: leecollings

JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Error executing script command returned: 256

Post by JanvdW »

A Domoticz Blockly starts a python script to set the Evohome temperature of rooms.
Capture.PNG
Capture.PNG (10.43 KiB) Viewed 5071 times
This starts the following script:

Code: Select all

#!/usr/bin/env python
import evoconfig
import sys 
import requests 
from evohomeclient2 import EvohomeClient 
from datetime import datetime
import datetime
import time

# Zet de systeem status op 'Normal' als hij op 'Away' is ingesteld 
client = EvohomeClient(evoconfig.usr, evoconfig.pw) 
status=client.locations[0].status()
tcs=status['gateways'][0]['temperatureControlSystems'][0]
zones=tcs['zones']

# Wait to avoid that previous script is still running
time.sleep( 10 ) 

# Set system in the normal mode if that is not the case
currentmode = tcs['systemModeStatus']['mode']
if currentmode == "Away":
   client.set_status_normal()

# Wijzigingen doorvoeren tussen 06:00 en 21:30 uur
dt = datetime.datetime.now()
start_time = "06:00"
end_time = "21:30"
if start_time < dt.strftime("%H:%M") < end_time:
   # Aanpassen radiator temperatuur
   kamer=sys.argv[1]
   if kamer <> "aanwezig":
      temp=sys.argv[2]
      zone = client.locations[0]._gateways[0]._control_systems[0].zones[kamer]
      zone.set_temperature(temp)
This worked excellent for a long time, but suddenly Domoticz logs an error message when the scrips is called:

Code: Select all

Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
I am not aware of relevant changes to my system that triggered this. To solve the issue I have tried a lot of things that are suggested in similar issues:
  • I checked that the absolute path to the script is defined in Domoticz
  • I checked rights and ownership: -rwxrwxrwx 1 pi pi 1142 Feb 3 10:36 radiator_temp.py
  • I tested different suggestions for the first line of the pyhton script
#!/usr/bin/env python -> original one, which returned 256
#!/bin/bash -> returned 512
#!/usr/bin/python -> returned 256
#!/bin/sh -> returned 512
  • edited script with vi
  • Running the script (in this case starting with #!/bin/sh) in putty works fine: python radiator_temp.py Voorkamer 19
What else can I change to solve this issue?
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Error executing script command returned: 256

Post by erem »

#!/usr/bin/env python is the correct shebang.
or use #!/usr/bin/python3

try adding exit() at the end of your script.
Regards,

Rob
User avatar
FireWizard
Posts: 1974
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Error executing script command returned: 256

Post by FireWizard »

Hi, @JanvdW

Hello Jan, this is an ever returning topic.

Have a look at this discussion: viewtopic.php?f=6&t=30657&p=231907#p231907

Maybe the solution in @DewGew 's post will help you.

Regards
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

erem wrote: Wednesday 03 February 2021 12:23 #!/usr/bin/env python is the correct shebang.
or use #!/usr/bin/python3

try adding exit() at the end of your script.
I thought so, and was using that shebang. I have added exit() at the end of the script, but the error is still there.
The strange thing is that the script is executed properly, but gives an error every time.
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

FireWizard wrote: Wednesday 03 February 2021 12:36 Hi, @JanvdW

Hello Jan, this is an ever returning topic.

Have a look at this discussion: viewtopic.php?f=6&t=30657&p=231907#p231907

Maybe the solution in @DewGew 's post will help you.

Regards
Seems a good suggestion in case the script is started with the wrong account. I changes the script (this is how it's should be done, right?):

Code: Select all

#!/usr/bin/env python
import evoconfig
import sys 
import requests 
from evohomeclient2 import EvohomeClient 
from datetime import datetime
import datetime
import time

# make sure we're running as the user
RUN_AS="pi" # Enter username here
if [ "$USER" != "$RUN_AS" ]
then
    echo ""
    echo " This script must run as $RUN_AS, trying to change user..."
    exec sudo -u $RUN_AS $0 $1
fi

# Zet de systeem status op 'Normal' als hij op 'Away' is ingesteld 
client = EvohomeClient(evoconfig.usr, evoconfig.pw) 
status=client.locations[0].status()
tcs=status['gateways'][0]['temperatureControlSystems'][0]
zones=tcs['zones']

# Wait to avoid that previous script is still running
time.sleep( 10 ) 

# Set system in the normal mode if that is not the case
currentmode = tcs['systemModeStatus']['mode']
if currentmode == "Away":
   client.set_status_normal()

# Wijzigingen doorvoeren tussen 06:00 en 21:30 uur
dt = datetime.datetime.now()
start_time = "06:00"
end_time = "21:30"
if start_time < dt.strftime("%H:%M") < end_time:
   # Aanpassen radiator temperatuur
   kamer=sys.argv[1]
   if kamer <> "aanwezig":
      temp=sys.argv[2]
      zone = client.locations[0]._gateways[0]._control_systems[0].zones[kamer]
      zone.set_temperature(temp)
exit()
Unfortunately the error is still in the Domoticz log
User avatar
FireWizard
Posts: 1974
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Error executing script command returned: 256

Post by FireWizard »

@JanvdW

You wrote:
this is how it's should be done, right?)
I don't know.

@DewGew ´s solution has been made in a Bash shell script and not a Python script.
From the shell script, you can call the Python script.

@DewGew said also:
I don't know if it has same problem with python scripts. Maybe a bash script like above to call python script might work.
I forgot mention in last post that the bash script need to be executable.
You can try, at least.

Regards
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Error executing script command returned: 256

Post by erem »

you can find more info on the various exit modes here
https://www.geeksforgeeks.org/python-ex ... -os-_exit/

what version of python do you use, 2 or 3?
Regards,

Rob
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

erem wrote: Wednesday 03 February 2021 13:42 you can find more info on the various exit modes here
https://www.geeksforgeeks.org/python-ex ... -os-_exit/
I tried sys.exit() as well; same result.
erem wrote: Wednesday 03 February 2021 13:42 what version of python do you use, 2 or 3?
Evohome client (which is included in my script) works with Python 2, in my case 2.7.16
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

FireWizard wrote: Wednesday 03 February 2021 13:39 @JanvdW

You wrote:
this is how it's should be done, right?)
I don't know.

@DewGew ´s solution has been made in a Bash shell script and not a Python script.
From the shell script, you can call the Python script.

@DewGew said also:
I don't know if it has same problem with python scripts. Maybe a bash script like above to call python script might work.
I forgot mention in last post that the bash script need to be executable.
You can try, at least.

Regards
I am not sure how to do this. My python script is started with two parameters and I don't know how I can pass them from the shell script to the python script.
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Error executing script command returned: 256

Post by erem »

i dumbed the code down to this blocky,
03-02-2021 15-21-18.jpg
03-02-2021 15-21-18.jpg (18.44 KiB) Viewed 5025 times
and the script

-rwxr-xr-x 1 pi pi 448 Feb 3 15:16 py2test.py

with code

Code: Select all

#!/usr/bin/python2

import sys
import requests

from datetime import datetime
import datetime
import time

print "test python2 starts"
# Wait to avoid that previous script is still running
time.sleep( 5 )


# Wijzigingen doorvoeren tussen 06:00 en 21:30 uur
dt = datetime.datetime.now()
start_time = "06:00"
end_time = "21:30"
if start_time < dt.strftime("%H:%M") < end_time:
   # Aanpassen radiator temperatuur
   print "test python2 ran"
#exit()
output in domoticz log

Code: Select all

2021-02-03 15:17:00.213 EventSystem: Event triggered: py2test_1
2021-02-03 15:17:00.442 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:18:00.234 EventSystem: Event triggered: py2test_1
2021-02-03 15:18:00.473 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:19:00.247 EventSystem: Event triggered: py2test_1
2021-02-03 15:19:00.460 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:20:00.261 EventSystem: Event triggered: py2test_1
2021-02-03 15:21:00.275 EventSystem: Event triggered: py2test_1
2021-02-03 15:21:18.487 (Buienradar) General/Custom Sensor (Next Rainshower Leadtime)
2021-02-03 15:21:18.495 (Buienradar) General/Custom Sensor (Next Rainshower Duration)
2021-02-03 15:21:18.504 (Buienradar) General/Custom Sensor (Next Rainshower Avg Rainrate)
2021-02-03 15:21:18.512 (Buienradar) General/Custom Sensor (Next Rainshower Max Rainrate)
2021-02-03 15:21:18.520 (Buienradar) General/Percentage (Rain Intensity)
2021-02-03 15:21:18.528 (Buienradar) General/Custom Sensor (Rainfall next Hour)
2021-02-03 15:22:00.287 EventSystem: Event triggered: py2test_1
2021-02-03 15:23:00.300 EventSystem: Event triggered: py2test_1
2021-02-03 15:23:00.530 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:24:00.313 EventSystem: Event triggered: py2test_1
2021-02-03 15:24:00.531 Status: Executing script: //home/pi/py2test.py
i did the same test with python3, same result.

can you see if that runs without the error on your system
you can see that i tried with and without exit(), both give no error on my system.

does your domoticz run as root?
if so, what happens if you execute the script from a root command line? any errors?
Regards,

Rob
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

erem wrote: Wednesday 03 February 2021 15:38 i dumbed the code down to this blocky,
03-02-2021 15-21-18.jpg

and the script

-rwxr-xr-x 1 pi pi 448 Feb 3 15:16 py2test.py

with code

Code: Select all

#!/usr/bin/python2

import sys
import requests

from datetime import datetime
import datetime
import time

print "test python2 starts"
# Wait to avoid that previous script is still running
time.sleep( 5 )


# Wijzigingen doorvoeren tussen 06:00 en 21:30 uur
dt = datetime.datetime.now()
start_time = "06:00"
end_time = "21:30"
if start_time < dt.strftime("%H:%M") < end_time:
   # Aanpassen radiator temperatuur
   print "test python2 ran"
#exit()
output in domoticz log

Code: Select all

2021-02-03 15:17:00.213 EventSystem: Event triggered: py2test_1
2021-02-03 15:17:00.442 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:18:00.234 EventSystem: Event triggered: py2test_1
2021-02-03 15:18:00.473 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:19:00.247 EventSystem: Event triggered: py2test_1
2021-02-03 15:19:00.460 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:20:00.261 EventSystem: Event triggered: py2test_1
2021-02-03 15:21:00.275 EventSystem: Event triggered: py2test_1
2021-02-03 15:21:18.487 (Buienradar) General/Custom Sensor (Next Rainshower Leadtime)
2021-02-03 15:21:18.495 (Buienradar) General/Custom Sensor (Next Rainshower Duration)
2021-02-03 15:21:18.504 (Buienradar) General/Custom Sensor (Next Rainshower Avg Rainrate)
2021-02-03 15:21:18.512 (Buienradar) General/Custom Sensor (Next Rainshower Max Rainrate)
2021-02-03 15:21:18.520 (Buienradar) General/Percentage (Rain Intensity)
2021-02-03 15:21:18.528 (Buienradar) General/Custom Sensor (Rainfall next Hour)
2021-02-03 15:22:00.287 EventSystem: Event triggered: py2test_1
2021-02-03 15:23:00.300 EventSystem: Event triggered: py2test_1
2021-02-03 15:23:00.530 Status: Executing script: //home/pi/py2test.py
2021-02-03 15:24:00.313 EventSystem: Event triggered: py2test_1
2021-02-03 15:24:00.531 Status: Executing script: //home/pi/py2test.py
i did the same test with python3, same result.

can you see if that runs without the error on your system
you can see that i tried with and without exit(), both give no error on my system.

does your domoticz run as root?
if so, what happens if you execute the script from a root command line? any errors?
I need to use python2, because the Evohome scripts are not compliant with python3. When I run the script on the command line everything works fine; no errors appear.

I tested your setup and this works fine. I noticed some differences with my setup:
  • The test script was owned by root, while my script was owned by pi.
  • Different shebang
So I changed ownership and shebang of my script. Unfortunately the 256 errors are still there.

As far as I know this error normally means that the script is not executed. In my case the script is clearly executed, because the room temperature is changed as expected. But the 256 error appears in the log as well.

How can I check if domoticz run as root?
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

I found another confusing fact: in some cases the script results in an error and in some cases it doesn't. I can't recognize any pattern.

The log filtering of script execution between 20:50 and 21:20:

Code: Select all

	2021-02-03 20:50:09.254 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:51:06.198 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 20:52:09.747 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:53:06.134 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 20:54:10.588 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 20:55:06.591 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:56:10.140 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:57:05.668 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:58:10.963 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 20:59:05.723 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:00:24.232 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:01:05.739 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:02:10.269 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 21:03:05.771 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:04:10.316 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:05:07.028 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 21:06:10.178 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
2021-02-03 21:07:05.817 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	021-02-03 21:08:10.302 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
	2021-02-03 21:09:05.850 Status: Executing script: //home/pi/evohome-client/radiator_temp.py
I indented the lines in this log that are correlated to an error message, as is shown in the log filtering of script errors between 20:50 and 21:20

Code: Select all

2021-02-03 20:50:10.541 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 20:52:10.671 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 20:54:11.493 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 20:55:07.576 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:00:25.189 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:01:06.658 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:02:11.115 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:04:11.256 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:05:07.875 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:08:11.344 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
2021-02-03 21:09:06.762 Error: Error executing script command (//home/pi/evohome-client/radiator_temp.py). returned: 256
So possibly the conclusion in my previous message that, despite of the error, the script was clearly executed (because the room temperature changed) wasn't appropriate. Maybe this change was caused by an occasions which didn't end up in an 256 error.
User avatar
FireWizard
Posts: 1974
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Error executing script command returned: 256

Post by FireWizard »

Hi, @JanvdW,

Have you read this thread?

viewtopic.php?t=7465

Perhaps it is useful

Regards
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

FireWizard wrote: Wednesday 03 February 2021 23:29 Hi, @JanvdW,

Have you read this thread?

viewtopic.php?t=7465

Perhaps it is useful

Regards
Yes, I have seen that topic before. Most of the solutions mentioned here can't solve my problem, because other (quite similar) scripts work perfectly well. And some solutions are mentioned for Actions in Domoticz (like the three '/'). I have have tested the suggestion in this topic to end the script with 'exit 0', but that doesn't solve the issues either.

I have another script, that is called with a similar Blockly, stored in the same directory, using the same Evohome libraries, which run without trouble:

Code: Select all

#!/usr/bin/env python
import evoconfig
import sys
import requests
from evohomeclient2 import EvohomeClient

client = EvohomeClient(evoconfig.usr, evoconfig.pw)
status=client.locations[0].status()
tcs=status['gateways'][0]['temperatureControlSystems'][0]
zones=tcs['zones']
currentmode = tcs['systemModeStatus']['mode']

if currentmode != "Away":
   client.locations[0]._gateways[0]._control_systems[0].zones["Achterkamer"].set_temperature(15)
   client.locations[0]._gateways[0]._control_systems[0].zones["Tussenkamer"].set_temperature(15)
   client.locations[0]._gateways[0]._control_systems[0].zones["Voorkamer"].set_temperature(15)
   client.locations[0]._gateways[0]._control_systems[0].zones["Badkamer"].set_temperature(15)
I don't know what I'm overlooking, but at this moment don't understand this at all.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error executing script command returned: 256

Post by waaren »

JanvdW wrote: Wednesday 03 February 2021 21:43 I found another confusing fact: in some cases the script results in an error and in some cases it doesn't. I can't recognize any pattern.
Maybe belows dzVents script does give you some insight what's going wrong.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'every minute',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Python script-starter',
    },

    execute = function(dz)

        local function osCommand(cmd)

            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
                dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_DEBUG)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local res, rc = osCommand ('/home/pi/evohome-client/radiator_temp.py Voorkamer "19" ' )
        dz.log('returnCode: ' .. (rc % 255) .. ' , result: ' .. res, dz.LOG_DEBUG)

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

waaren wrote: Thursday 04 February 2021 0:12
JanvdW wrote: Wednesday 03 February 2021 21:43 I found another confusing fact: in some cases the script results in an error and in some cases it doesn't. I can't recognize any pattern.
Maybe belows dzVents script does give you some insight what's going wrong.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'every minute',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Python script-starter',
    },

    execute = function(dz)

        local function osCommand(cmd)

            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
                dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_DEBUG)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local res, rc = osCommand ('/home/pi/evohome-client/radiator_temp.py Voorkamer "19" ' )
        dz.log('returnCode: ' .. (rc % 255) .. ' , result: ' .. res, dz.LOG_DEBUG)

    end
}

I ran the script and script temperature setting is implemented. In the log

Code: Select all

2021-02-04 08:42:21.329 Status: dzVents: Debug: Python script-starter: returnCode: 0 , result:
2021-02-04 08:43:00.295 Status: dzVents: Info: Python script-starter: ------ Start internal script: Script #2:, trigger: "every minute"
2021-02-04 08:43:00.295 Status: dzVents: Debug: Python script-starter: Executing Command: /home/pi/evohome-client/radiator_temp.py Voorkamer "10"
2021-02-04 08:43:14.177 Status: dzVents: Debug: Python script-starter: ReturnCode: 0
2021-02-04 08:43:14.177 commandOutput:
2021-02-04 08:43:14.177
2021-02-04 08:43:14.177 Status: dzVents: Debug: Python script-starter: returnCode: 0 , result:
The only error that is logged is:

Code: Select all

2021-02-04 08:42:20.436 Error: EventSystem: Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds
2021-02-04 08:42:21.331 Error: dzVents: Error: (3.1.4) Python script-starter: ------ Finished Script #2 after >16 seconds. (using 0.934 seconds CPU time !)
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

After some of these the following error was logged:

Code: Select all

2021-02-04 08:46:06.324 Error: dzVents: Debug: Python script-starter: Error ==>> Traceback (most recent call last):
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/radiator_temp.py", line 11, in <module>
2021-02-04 08:46:06.324 client = EvohomeClient(evoconfig.usr, evoconfig.pw)
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 89, in __init__
2021-02-04 08:46:06.324 self._login()
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 94, in _login
2021-02-04 08:46:06.324 self.user_account()
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 228, in user_account
2021-02-04 08:46:06.324 response = requests.get(url, headers=self._headers())
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 110, in _headers
2021-02-04 08:46:06.324 self._basic_login()
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 150, in _basic_login
2021-02-04 08:46:06.324 self._obtain_access_token(credentials)
2021-02-04 08:46:06.324 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 180, in _obtain_access_token
2021-02-04 08:46:06.324 raise AuthenticationError(msg)
2021-02-04 08:46:06.324 evohomeclient2.AuthenticationError: Unable to obtain an Access Token, hint: {"error":"attempt_limit_exceeded"}
2021-02-04 08:46:06.325 Error: dzVents: Debug: Python script-starter: returnCode: 0 , result: Traceback (most recent call last):
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/radiator_temp.py", line 11, in <module>
2021-02-04 08:46:06.325 client = EvohomeClient(evoconfig.usr, evoconfig.pw)
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 89, in __init__
2021-02-04 08:46:06.325 self._login()
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 94, in _login
2021-02-04 08:46:06.325 self.user_account()
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 228, in user_account
2021-02-04 08:46:06.325 response = requests.get(url, headers=self._headers())
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 110, in _headers
2021-02-04 08:46:06.325 self._basic_login()
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 150, in _basic_login
2021-02-04 08:46:06.325 self._obtain_access_token(credentials)
2021-02-04 08:46:06.325 File "/home/pi/evohome-client/evohomeclient2/__init__.py", line 180, in _obtain_access_token
2021-02-04 08:46:06.325 raise AuthenticationError(msg)
2021-02-04 08:46:06.325 evohomeclient2.AuthenticationError: Unable to obtain an Access Token, hint: {"error":"attempt_limit_exceeded"}
2021-02-04 08:46:06.325 ::ERROR::
This explains why the error occurs not in all cases: the problem had nothing to do with the python script, but with exceeding Evohome access limits. In other words, it's caused by the Blocky timer (that I added for some tests) which fires the script every minute. I removed that and fired the script based on (manually triggered) smartphone presence only. No errors are logged now. So it seems to be solved. Rather confusing error message...

Thanks for your help and your script. It helps me to find the cause.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error executing script command returned: 256

Post by waaren »

JanvdW wrote: Thursday 04 February 2021 8:55 Thanks for your help and your script. It helps me to find the cause.
Given that you are on a recent dzVents version, you can also use below script. This will process the evohome script async from domoticz and therewith not blocking the eventsystem for 10 seconds when evohome connection takes too long.

Code: Select all

local scriptVar = 'pythonStarter'
return
{
    on =
    {
        devices = 
        {
            ['Smartphone Jan'] = 
            {
                'at 08:00-21:00',
            },
        },
        shellCommandResponses =
        {
            scriptVar,
        },
    },
   
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
       
        if item.isDevice and item.active then 
            dz.executeShellCommand(
            {
                command = '/home/pi/evohome-client/radiator_temp.py Voorkamer "19" ' ,
                timeout = 30,
                callback = scriptVar,
            })
        elseif item.isShellCommandResponse then
            local result = ''
            if item.data and item.data ~= '' then
                result = '\n' .. 'output: ' .. item.data 
            end    
            dz.log('returnCode: '.. item.statusCode .. ' , error Text: ' .. item.errorText .. result , dz.LOG_DEBUG)
        end 
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error executing script command returned: 256

Post by JanvdW »

waaren wrote: Thursday 04 February 2021 22:21
JanvdW wrote: Thursday 04 February 2021 8:55 Thanks for your help and your script. It helps me to find the cause.
Given that you are on a recent dzVents version, you can also use below script. This will process the evohome script async from domoticz and therewith not blocking the eventsystem for 10 seconds when evohome connection takes too long.

Code: Select all

local scriptVar = 'pythonStarter'
return
{
    on =
    {
        devices = 
        {
            ['Smartphone Jan'] = 
            {
                'at 08:00-21:00',
            },
        },
        shellCommandResponses =
        {
            scriptVar,
        },
    },
   
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar
    },

    execute = function(dz, item)
       
        if item.isDevice and item.active then 
            dz.executeShellCommand(
            {
                command = '/home/pi/evohome-client/radiator_temp.py Voorkamer "19" ' ,
                timeout = 30,
                callback = scriptVar,
            })
        elseif item.isShellCommandResponse then
            local result = ''
            if item.data and item.data ~= '' then
                result = '\n' .. 'output: ' .. item.data 
            end    
            dz.log('returnCode: '.. item.statusCode .. ' , error Text: ' .. item.errorText .. result , dz.LOG_DEBUG)
        end 
    end
}
Thanks for thinking along; I really appreciate that! The script works perfect.

I was not aware that Blockly is working synchronous. Are Blockly scrips always running synchronous? In that case I will have a look at my other Blockly's as well.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error executing script command returned: 256

Post by waaren »

JanvdW wrote: Thursday 04 February 2021 23:22 I was not aware that Blockly is working synchronous. Are Blockly scrips always running synchronous? In that case I will have a look at my other Blockly's as well.
Yes, classic Lua and Blockly commands like os.execute, io.popen are executed synchronous. The os commands can be forced to be executed in the background on linux systems by adding a trailing ampersand to the command and something similar can be done on windows.

Problem with that approach is that quite some extra code is needed to check if the commands were successful and to process any results.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply