Page 1 of 1

Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 8:17
by cmisip
If I run a regular python script (via the web UI) without using any domoticz variables, there is no error. It's like my python scripts are not seeing the domoticz python module. I get an error code 256 if I try to import DomticzEvents as DE.

I wish to be able to use domoticz variables in lua or python. I suppose I could just write python sql to adjust the status of devices in the database but working within the domoticz python framework would be easier.

I can't even find the python domoticz module. Where is it installed? it is not in dist-packages.

This is a fresh install on RPI 3 with Trixie. Any ideas?

Thanks,
Chris

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 14:14
by cmisip
Well, my scripts did not follow the naming convention. When I changed the name to "script_device_halllight.lua", it worked. I wish we had better error logging. Did the same for the python version and it worked, however, the python version is returning error 256.

From the log:

Code: Select all

2026-02-22 13:09:30.369 Error: Error executing script command (/home/pi/domoticz/scripts/python/script_device_foyerlight.py). returned: 256
2026-02-22 13:09:32.081 Executed: heyu on B9
Here is the python code:

Code: Select all

#!/usr/bin/env python3

import DomoticzEvents as DE
import os

TRIGGER_SWITCH = "Foyer Light"

HEYU_ON_CMD = "heyu on B9"
HEYU_OFF_CMD = "heyu off B9"

if DE.changed_device_name == TRIGGER_SWITCH:

    if DE.Devices["Foyer Light"].n_value_string == "On":
       os.system(HEYU_ON_CMD)
       DE.Log(f"Executed: {HEYU_ON_CMD}")
    elif DE.Devices["Foyer Light"].n_value_string == "Off":
        os.system(HEYU_OFF_CMD)
        DE.Log(f"Executed: {HEYU_OFF_CMD}")
Anybody have any ideas why its returning error 256?

Thanks,
Chris

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 14:33
by Thorgal789
Have you tried the python script included by defaut to test ?

Code: Select all

script_device_demo.py

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 14:37
by jvdz
What exactly are you expecting this line to do as that returns the 256?:
os.system(HEYU_ON_CMD)

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 15:12
by cmisip
Its expanded to

Code: Select all

heyu on B9
The device is working. I can turn it on and off via lua or python script. However, I get the 256 error in the logs for the python version of the script.

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 15:51
by jvdz
I knew that much already, but isn't "os.system('heyu on B9')" trying to run 'heyu on B9' in an os shell?
Is that an existing commandline command in your installation as that seems to returns 256.

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 21:10
by cmisip
It has to run in a shell. Its the heyu program which is used to run x10 devices. Its not providingng an error code when its run in a terminal. I am not aware of any other way to do this. It works. It's just annoying to see the errors in the log.

I switched all the scripts to lua:

Code: Select all

#!/usr/bin/lua

commandArray = {}

if (devicechanged['Hall Light'] == 'On') then
	os.execute('sudo -u pi /usr/local/bin/heyu on a6')
elseif (devicechanged['Hall Light'] == 'Off') then
	os.execute('sudo -u pi /usr/local/bin/heyu off a6')
end

return commandArray
The scripts work. But they display the error.

Code: Select all

2026-02-22 20:07:46.998 Error: Error executing script command (/home/pi/domoticz/scripts/lua/script_device_halllight.lua). returned: 256

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Sunday 22 February 2026 22:02
by jvdz
You could try shelling without waiting by adding a & at the end of the commandline.

Code: Select all

os.execute('sudo -u pi /usr/local/bin/heyu off a6 &')

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Monday 23 February 2026 3:07
by cmisip
That eliminated the 256 error in the lua scripts. There is a new error though.

Code: Select all

2026-02-23 01:48:09.078 Error: SQLHelper: Error script not found '/lua/script_device_foyerlight.lua'
This is the lua script code:

Code: Select all

commandArray = {}

if (devicechanged['Foyer Light'] == 'On') then
	os.execute('sudo -H -u pi /usr/local/bin/heyu on a1 &')
elseif (devicechanged['Foyer Light'] == 'Off') then
	os.execute('sudo -H -u pi /usr/local/bin/heyu off a1 &')
end

return commandArray


There doesn't seem to be any negative effects. The lights are still working.

I got the info from here:

https://wiki.domoticz.com/X10_with_CM11a

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Thursday 26 February 2026 1:40
by cmisip
I think I figured it out.

Scripts for devices need to created in the Event Editor. Then the on and off sections in the Device configuration should be blank. I think Domoticz links Devices and Events with the same name. The errors went away. I also noticed that Domoticz would run through all the Event scripts and run their print commands.

Code: Select all

2026-02-26 00:25:39.608 Status: User: admin (IP: 192.168.0.15) initiated a switch command (6/Porch Light/Off)
2026-02-26 00:25:39.625 X10 Dummy interface: Lighting 1 (Porch Light)
2026-02-26 00:25:39.700 Python: Changed: ID: 6 Name: Porch Light, Type: 16, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: Off, last_update_string: 2026-02-26 00:25:39
2026-02-26 00:25:50.635 Status: User: admin (IP: 192.168.0.15) initiated a switch command (6/Porch Light/On)
2026-02-26 00:25:50.648 X10 Dummy interface: Lighting 1 (Porch Light)
2026-02-26 00:25:50.722 Python: Changed: ID: 6 Name: Porch Light, Type: 16, subType: 0, switchType: 0, s_value: , n_value: 1, n_value_string: On, last_update_string: 2026-02-26 00:25:50
2026-02-26 00:26:00.201 Python: Changed: ID: 0 Name: , Type: 0, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: , last_update_string:
2026-02-26 00:26:31.579 Status: User: admin (IP: 192.168.0.15) initiated a switch command (7/Foyer Light/On)
2026-02-26 00:26:31.592 X10 Dummy interface: Lighting 1 (Foyer Light)
2026-02-26 00:26:31.648 Status: LUA: Device based event fired on 'Foyer Light', value 'On'
2026-02-26 00:26:31.692 Python: Changed: ID: 7 Name: Foyer Light, Type: 16, subType: 0, switchType: 0, s_value: , n_value: 1, n_value_string: On, last_update_string: 2026-02-26 00:26:31
2026-02-26 00:26:52.511 Status: User: admin (IP: 192.168.0.15) initiated a switch command (9/Eagle Eye 2 MS/Off)
2026-02-26 00:26:52.524 X10 Dummy interface: Lighting 1 (Eagle Eye 2 MS)
2026-02-26 00:26:58.064 Executed: sudo -u pi /usr/bin/ssh [email protected] "mpg321 -q -o alsa -a 'hw:0,0' /home/pi/bin/audio/cancelshutdown.wav"
2026-02-26 00:26:58.097 Python: Changed: ID: 9 Name: Eagle Eye 2 MS, Type: 16, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: Off, last_update_string: 2026-02-26 00:26:52
2026-02-26 00:27:00.873 Python: Changed: ID: 0 Name: , Type: 0, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: , last_update_string:
2026-02-26 00:28:00.227 Python: Changed: ID: 0 Name: , Type: 0, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: , last_update_string:
2026-02-26 00:28:00.330 Status: EventSystem: reset all events...
2026-02-26 00:28:00.342 Python: Changed: ID: 0 Name: , Type: 0, subType: 0, switchType: 0, s_value: , n_value: 0, n_value_string: , last_update_string:
I don't know why the python script for Eagle Eye 2 MS is triggering twice ( I hear the announcement twice) even if the log only shows one activation. Here is the script:

Code: Select all

import DomoticzEvents as DE
import os

DE.Log("Python: Changed: " + DE.changed_device.Describe())

if DE.changed_device_name == "Eagle Eye 2 MS":
   
    if DE.Devices["Eagle Eye 2 MS"].n_value_string == "On":
        os.system("sudo -u pi /usr/bin/ssh [email protected] \"mpg321 -q -o alsa -a 'hw:0,0' /home/pi/bin/audio/shutdownin30seconds.wav\"")
       

    if DE.Devices["Eagle Eye 2 MS"].n_value_string == "Off":
        os.system("sudo -u pi /usr/bin/ssh [email protected] \"mpg321 -q -o alsa -a 'hw:0,0' /home/pi/bin/audio/cancelshutdown.wav\"")
       
Thanks,
Chris

Re: Getting error 256 when I add import DomoticzEvents as DE

Posted: Thursday 26 February 2026 13:28
by cmisip
I figured it out. Domoticz actually runs all the events and all the scripts in the scripts directory. However, scripts in the scripts directory don't have access to Domoticz global variables and logging facility. Deleting the scripts in the scripts directory and just utilizing their counterpart events written with the editor prevented scripts running twice. sql_helper is probably tracking the events scripts which it was looking for (and not finding) when the configuration of the on/off action in device configuration was prefixed with script:/// ( three slashes).

Thanks,
Chris