Launch Putty from Domoticz [Solved]

Post Reply
woods
Posts: 11
Joined: Friday 30 October 2015 18:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Launch Putty from Domoticz [Solved]

Post by woods » Wednesday 12 September 2018 8:18

Hi all,
In HomeSeer it’s possible to launch Putty with parameters in one go. I would like to control the HDMI port (on/off) from another Raspberry Pi (controlling my magic mirror).

Is this possible with Domoticz?

Example from HomeSeer:

Image

Thanks

Edit. Updated the title to solved.
Last edited by woods on Wednesday 12 September 2018 15:13, edited 1 time in total.

ben53252642
Posts: 527
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 » Wednesday 12 September 2018 8:38

Something like this should do it:

Requires: apt-get install sshpass

Code: Select all

timeout 20s sshpass -p "PASSWORD" ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no "USERNAME"@"IPADDRESS" 'THECOMMANDTORUNGOESHERE'
Note the command is set not to verify the ssh keys.

SweetPants
Posts: 2351
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10216
Location: The Netherlands
Contact:

Re: Launch Putty from Domoticz

Post by SweetPants » Wednesday 12 September 2018 8:43

putty for linux?
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

User avatar
Egregius
Posts: 2740
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Launch Putty from Domoticz

Post by Egregius » Wednesday 12 September 2018 9:18

If it's just a command that you need to send you can do that by the builtin ssh client.
Something like:

Code: Select all

ssh root@192.168.2.212 -i /root/.ssh/home "find /home -type f -printf '%T@\n' | sort -n | tail -1 | cut -f1- -d\" \""
This command grabs the modification time of the last updated file in /home on a remote pi to determine if I need to run a backup or not :D
Of course, that command could be anything you like.

woods
Posts: 11
Joined: Friday 30 October 2015 18:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods » Wednesday 12 September 2018 14:11

Thanks guys, I really appreciate the help.
I ‘ve made two scripts (on/off) which I intended to use as on/off parameters on a virtual switch. I tried to call ex. “script://magicmirrorON.sh”, but I got the error 32512 in return in the logs.

Is there a better way implementing this script?
Thanks again.

Ps.
Here's my script:

Code: Select all

sshpass -p "PASSWORD" ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no "username"@"ipadress" 'vcgencmd display_power 0'

ben53252642
Posts: 527
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 » Wednesday 12 September 2018 14:33

Does the script work from terminal without Domoticz?

If you have that right I can provide a Lua script for Domoticz that can launch it.

I have many sh scripts I launch from Domoticz, it's quite common.

woods
Posts: 11
Joined: Friday 30 October 2015 18:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods » Wednesday 12 September 2018 14:37

Yes, it work's perfectly fine without Domoticz.

That would be perfect. Do you run the Lua script directly from the switch configuration?

ben53252642
Posts: 527
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 » Wednesday 12 September 2018 14:52

Put this in Domoticz events, Lua script TYPE (VERY IMPORTANT) is "device" (not the default "all").

Code: Select all

commandArray = {}

if (devicechanged['SwitchNAME'] == 'On')  then
    os.execute ('/root/scripts/zrc90/bedroom/onscript.sh &')
elseif (devicechanged['SwitchNAME'] == 'Off')  then
    os.execute ('/root/scripts/zrc90/bedroom/offscript.sh &')
end

return commandArray
SwitchNAME is a virtual switch you created, the event system will watch and when it changes to on or off execute the bash / sh script accordingly.

The & symbol should be kept after the script name, if you remove it, it will still work but could slow down the Domoticz event system.

Cheers

woods
Posts: 11
Joined: Friday 30 October 2015 18:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods » Wednesday 12 September 2018 15:12

Fixed it with a new script:

Code: Select all

#!/bin/bash
sshpass -p "PASSWORD" ssh -o StrictHostKeyChecking=no pi@ipadress "vcgencmd display_power 1"
Works perfectly. Considering making a new button which safely shutdowns all the raspberry pies as well (including Domoticz).

Case closed. Thanks all.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests