Launch Putty from Domoticz [Solved]

Moderator: leecollings

Post Reply
woods
Posts: 8
Joined: Friday 30 October 2015 17:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Launch Putty from Domoticz [Solved]

Post by woods »

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: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 »

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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
SweetPants

Re: Launch Putty from Domoticz

Post by SweetPants »

putty for linux?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Launch Putty from Domoticz

Post by Egregius »

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 [email protected] -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: 8
Joined: Friday 30 October 2015 17:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods »

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: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 »

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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
woods
Posts: 8
Joined: Friday 30 October 2015 17:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods »

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: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Launch Putty from Domoticz

Post by ben53252642 »

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
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
woods
Posts: 8
Joined: Friday 30 October 2015 17:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Launch Putty from Domoticz

Post by woods »

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 1 guest