Getting error 256 when I add import DomoticzEvents as DE

Python and python framework

Moderator: leecollings

Post Reply
cmisip
Posts: 7
Joined: Sunday 22 February 2026 8:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Getting error 256 when I add import DomoticzEvents as DE

Post 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
cmisip
Posts: 7
Joined: Sunday 22 February 2026 8:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
Thorgal789
Posts: 881
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

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

Post by Thorgal789 »

Have you tried the python script included by defaut to test ?

Code: Select all

script_device_demo.py
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

What exactly are you expecting this line to do as that returns the 256?:
os.system(HEYU_ON_CMD)
cmisip
Posts: 7
Joined: Sunday 22 February 2026 8:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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.
cmisip
Posts: 7
Joined: Sunday 22 February 2026 8:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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 &')
cmisip
Posts: 7
Joined: Sunday 22 February 2026 8:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest