Python events: unable to use subroutines !

Python and python framework

Moderator: leecollings

Post Reply
actyln
Posts: 5
Joined: Saturday 31 October 2020 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Python events: unable to use subroutines !

Post by actyln »

Hello,

I've been working hours on a python script outside of domoticz, which now gives me satisfaction.
Now is the time to put it in domoticz, so I copy/paste my script in the embedded Python Events editor.

And I always get the same error: (CRC being one of the subroutines I defined)

Code: Select all

2023-04-29 20:46:01.416 Error: NameError: name 'CRC' is not defined
It seems the Python interpreter used by Domoticz is not able to work with subroutines ... anyone having the same issue ?
I tried to move my script to the scripts/python folder of domoticz and I get the same issue by the way.
On the same machine, if I call from cmdline

Code: Select all

python3 script_time_myscript.py
it works perfectly .... I'm becoming crazy ...

So I did a simple test:

Code: Select all

import DomoticzEvents as DE
DE.Log("tadaaaaa")
This gives me in the domotics logs:

Code: Select all

2023-04-29 20:48:28.344 tadaaaaa
But if I modify it like this:

Code: Select all

import DomoticzEvents as DE
def message(text):
    DE.Log(text)
message("tadaaaaa")
This gives me in the domotics logs:

Code: Select all

2023-04-29 20:49:40.817 Error: Traceback (most recent call last):
2023-04-29 20:49:40.817 Error: File "Script #1", line 6, in <module>
2023-04-29 20:49:40.817 Error: File "Script #1", line 4, in message
2023-04-29 20:49:40.817 Error: NameError: name 'DE' is not defined
It's hard for me to believe that the Python interpreter used by domoticz is not supporting subroutines ....
I couldn't find any topic about this anywhere on this forum or on the net.

Anyone with ideas ?

Thank a lot guys !
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python events: unable to use subroutines !

Post by waltervl »

Yes, this have been discussed before: viewtopic.php?p=297430
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
actyln
Posts: 5
Joined: Saturday 31 October 2020 12:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python events: unable to use subroutines !

Post by actyln »

Hello,

Sorry but this is not the same issue.
My issue is not with import command.
The import works well.

My issue is when using subfunctions with "def".
Then they are not found.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest