Page 1 of 1

external script won't run from dzventsz

Posted: Sunday 15 June 2025 11:56
by Hansh
I hope I'm asking this question in the right place.

I have a problem with starting a script from dzvents. The script won't start no matter what I've done so far, even consulting ai hasn't provided a solution. (I end up in a cricel of solutions).
This is my latest version of the script.

Code: Select all

return {
	on = {
		devices = {
			'3d printen'
		}
	},
	logging =   
    {
        level = domoticz.LOG_INFO, -- set to LOG_ERROR when tested and OK
        marker = '3D printen', 
    },
	execute = function(domoticz, device)
	    if device.state== 'On' then
	        domoticz.devices('3D systeem').switchOn()
	    end
	    if device.state== 'Off' then
		domoticz.log("3D systeem is shutting down in progres")
	        --python3 /home/pi/scripts/octopi_shutdown.py  (
	        domoticz.utils.osExecute("/bin/bash octopi_shutdown.sh")
	        --domoticz.utils.osExecute("ssh [email protected] 'sudo poweroff'")
	        domoticz.devices('3D systeem').switchOff().afterSec(30)
		domoticz.log("3D systeem is down")
		end
	end
}
in an earlier version of domoticz the command ( now in use 2025-1)
domoticz.utils.osExecute("ssh [email protected] 'sudo poweroff'")
worked fine and stopped octopi

What I tried / did:

the two raspberries can log in via ssh without passwords also for the sudo commands no passwords are needed anymore. If I enter "ssh [email protected] 'sudo poweroff'" in a terminal then the octopi.local stops as expected. But not via dzvents. (tried as user pi and root)
tried with python intermediate step. When running this python script from a terminal the octipi.local also stops here but also not via dzvents

You would think it's a rights problem. Domoticz is executed by the owner PI and all rights are set so that the owner pi can access everything and can start all relevant folders and files have the rights 777.
Even after "sudo chmod 777 -R ./home/pi" it doesn't work from dzvents

os.Execute is recognized by domoticz.

Messages from the domoticz log are and remain the same no matter what I do. And I don't get a single message from the scripts, not even that it's running. (the scripts are full of log messages also to log files)

2025-06-15 11:22:26.786 Status: User: Hans (IP: 192.168.0.xxx) initiated a switch command (148/3d printen/Off)
2025-06-15 11:22:26.814 dzVents: Handling events for: "3d printing", value: "Off"
2025-06-15 11:22:26.814 dzVents: 3D printing: 3D system is shutting down in progress
2025-06-15 11:22:26.816 dzVents: 3D printing: 3D system is down

I'm out of options
Anyone have any ideas

Re: external script won't run from dzventsz

Posted: Sunday 15 June 2025 18:12
by willemd
So clearly your script is triggered and runs as expected, except for this line
domoticz.utils.osExecute("/bin/bash octopi_shutdown.sh")

You did not mention you tried running exactly this command from a command line but I assume this also works?
Can you put more debugging into that shell script? Can you get any error logging from that shell script? Is that shell script executed but maybe some statements that are within the shell script are not?

Re: external script won't run from dzventsz

Posted: Sunday 15 June 2025 19:55
by Hansh
thanks for the reply

yes i had already executed it via a command line. i called this a terminal in my post.
The scripts are provided with extensive log options. When executing the script in a command line i get all ok messages that i expect and the script does what it should do.
If i do it via dzvents then nothing happens at all not even a log output. only a message in the domoticz log as mentioned in the post.
it seems like a security problem but i have allowed and released everything and still it does not work from domoticz. . possibly an option in domoticz is not set right. But which one

Re: external script won't run from dzventsz

Posted: Sunday 15 June 2025 22:16
by jvdz
You also set the Execute (x) bit on the file with chmod +x ?

Re: external script won't run from dzventsz

Posted: Monday 16 June 2025 9:22
by Hansh
jvdz wrote: Sunday 15 June 2025 22:16 You also set the Execute (x) bit on the file with chmod +x ?
thanks for the reply

i had set the Executebit (+x) in both files and folders with "sudo chmod 777 -R ./home/pi" (777 stands for rwxrwxrwx) and that didn't help either

It remains a mystery to me :?:

Re: external script won't run from dzventsz

Posted: Monday 16 June 2025 10:10
by madpatrick
maybe this helps a bit

viewtopic.php?t=35237

Here they are using "os.execute" and not "domoticz.utils.osExecute"

and

https://wiki.domoticz.com/DzVents:_next ... _execution
https://wiki.domoticz.com/DzVents:_next ... _execution

Re: external script won't run from dzventsz

Posted: Monday 16 June 2025 12:01
by waltervl
Also make sure you use full paths in the scripts, also in the sub-scripts. Like for example
/bin/bash /home/pi/octopi_shutdown.sh

Re: external script won't run from dzventsz

Posted: Monday 16 June 2025 13:37
by jannl
Are you using docker?