Page 1 of 1

domoticz.utils.osExecute problem

Posted: Monday 27 July 2020 15:02
by Hansh
Hi there,

I am making a script. The intention is that when the switch goes off, it first stops another raspberry in the network. and then turn off another switch about 30 sec later.
In itself a fairly simple script.

The problem lies in controlling the other raspberry. the raspberry where domoticz runs on can control the other raspberry by ssh, to do that I created an ssh keypair.

the command
ssh [email protected] 'sudo poweroff'
works fine and the remote raspberry is actually stopped

When this command is processed in a dzevents script it will no longer work. Does anyone have any idea to get this working.

the script i wrote:

Code: Select all

return {
	on = {
		devices = {
			'3d printen'
		}
	},
	execute = function(domoticz, device)
	    if device.state== 'Off' then
	        domoticz.utils.osExecute("ssh [email protected] 'sudo poweroff'")
		    domoticz.log("shutting down in 30 sec")
	        domoticz.devices(139).switchOff().afterSec(30)
	    end
	end
}

Re: domoticz.utils.osExecute problem

Posted: Monday 27 July 2020 17:00
by waaren
Hansh wrote: Monday 27 July 2020 15:02 The problem lies in controlling the other raspberry. the raspberry where domoticz runs on can control the other raspberry by ssh, to do that I created an ssh keypair.
Is domoticz executed by user pi? If not did you test with the same user?

Re: domoticz.utils.osExecute problem

Posted: Monday 27 July 2020 23:06
by Hansh
Thanks for the reply
Is domoticz executed by user pi? If not did you test with the same user?
A quick scan shows that domoticz was indeed started by user root.

htop.jpg
htop.jpg (11.91 KiB) Viewed 653 times

I'm going to work on this. When I know a bit more I will let you know.

I had not yet thought of this possibility.

mvg Hans

Re: domoticz.utils.osExecute problem  [Solved]

Posted: Wednesday 29 July 2020 15:22
by Hansh
@ waaren

This was the problem. After I created an ssh keypair for the root, the script worked perfectly.

Thanks again for the help

gr Hans