domoticz.utils.osExecute problem  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

domoticz.utils.osExecute problem

Post 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
}
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: domoticz.utils.osExecute problem

Post 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?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: domoticz.utils.osExecute problem

Post 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 647 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
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: domoticz.utils.osExecute problem  [Solved]

Post 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
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest