Jump to content

Possible to send linux commands through SSH?


TomNow2

Recommended Posts

Posted

Hi all, during quarantine I have built an arcade cabinet that runs on a rPi4 that the kids can use.  Right now I have it set up that when a button is pressed on a keypad, it turns on the outlet that the cabinet is connected to and 'starts it all up'.  Since the rPi4 is running linux, I was wondering if I could do something with programs where I would log in to the rPi, send a shutdown command, wait 10 seconds, then the outlet would turn off.  Basically trying to figure out how to automate a safe shutdown of the cabinet.  Is this possible?  Is there a Nodeserver for interacting with linux OS's?  Thank you

Posted

You could write a script for the RPI that does 2 things:  1) execute a REST API call to the ISY  2) then initiate the rPi shutdown sequence. 

 

The REST call could run an ISY programs 'then'.... example: /rest/programs/0032/runThen

the isy program can be disabled, and doesn't need an 'if' or 'else', the 'then' body should "wait" the number of minutes (or seconds) that will take the rPi to reach the safe shutdown state plus some cushion time, after the wait, it should turn off the plug.

Posted
16 minutes ago, MrBill said:

You could write a script for the RPI that does 2 things:  1) execute a REST API call to the ISY  2) then initiate the rPi shutdown sequence. 

 

The REST call could run an ISY programs 'then'.... example: /rest/programs/0032/runThen

the isy program can be disabled, and doesn't need an 'if' or 'else', the 'then' body should "wait" the number of minutes (or seconds) that will take the rPi to reach the safe shutdown state plus some cushion time, after the wait, it should turn off the plug.

Wow very interesting thanks, I guess I don't know much about rest commands. The question I have with this approach is how does the isy actually ssh into the rpi and execute the shutdown command? The other commands I understand with the then program commands.

I just reread this and you said to initiate from the Pi. See that would actually be great but not sure how I would initiate it to run, cause if I have to ssh manually, I would just issue the shutdown command. Heck, I'd love to program something where if a button is pressed for 3 seconds, then the rpi would just shutdown, but i have no idea how to do that either.

Posted (edited)
3 minutes ago, TomNow2 said:

Wow very interesting thanks, I guess I don't know much about rest commands. The question I have with this approach is how does the isy actually ssh into the rpi and execute the shutdown command? The other commands I understand with the then program commands.

I just reread this and you said to initiate from the Pi. See that would actually be great but not sure how I would initiate it to run, cause if I have to ssh manually, I would just issue the shutdown command. Heck, I'd love to program something where if a button is pressed for 3 seconds, then the rpi would just shutdown, but i have no idea how to do that either.

if you have the network module on the ISY you could go in reverse.  

the ISY program calls a network resource that SSH's to the pi and runs shutdown, then waits, then shuts off the plug.

Edited by MrBill
Posted
Just now, MrBill said:

if you have the network module on the ISY you could go in reverse.  

the ISY program calls a network resource that SSH's to the pi and runs shutdown, then waits, then shuts off the plug.

Wow fantastic, yes I do have the network module, I use it to send on and off commands to other network plugs :) Would you possibly have an references for what network commands to use for SSH or where I could read up more on this being done? This sounds like the route I want to take. Thank you 

Posted (edited)
7 minutes ago, TomNow2 said:

Wow fantastic, yes I do have the network module, I use it to send on and off commands to other network plugs :) Would you possibly have an references for what network commands to use for SSH or where I could read up more on this being done? This sounds like the route I want to take. Thank you 

I spoke too soon becuase I was thinking of the networking module being much like the cron interface and it's not.   

This is very doable still tho.  The ISY's networking module just needs to call a URL on the pi that runs a script via http, the Pi script would run shutdown on the pi.

If you need help making that happen I'm going to let someone else take over my idea and help you out.  I could get it done but it doesn't role off my fingers like I bet it will for someone else. 

the steps:

1) create a pi script that can be called via the pi's webserver that contains a single command to run shutdown.

2) create network resource on ISY that runs the pi script

3) create an ISY program that runs network resource, waits, turns off plug.

Edited by MrBill
Posted

Thanks for getting me this far, I certainly didn't even think of running a website and the network resource kicks off the website that runs the script, thank you

  • Like 1
Posted (edited)
9 minutes ago, TomNow2 said:

Looks like home assistant can do what I'm looking for so going to install it tomorrow and tinker over the weekend :)

If you can write python3 code about 20 lines of code could receive a URL sequence and reboot the RPi from a NR command. I do it in python3 by running a system command "sudo reboot" in python3 code.

Edited by larryllix
Posted

Thanks, I can read python code but am not a programmer. In the past I usually look at peoples example code and piece together something that works for me. Its ugly and time consuming for sure.

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...