[Solved] SSH Driver Needed

1 - Trying to get something working and I need an SSH driver for Hubitat
2 - ChatGPT is a total a hole and keeps pointing me to Hubitat community drivers that don't appear to exist. One by @bptworld and another by 'marklangston'. Both are dead links.

Can anyone help. Does a SSH driver exist? Because if I have to resort to a bloody switch bot thingamajig to push the power button on my Netgear ReadyNAS I'm gonna lose my :poop:

Angry The Office GIF

Note to self - Home automation tasks are better solved before a bottle of Shiraz

What app/driver is it pointing to? I haven't used ssh in a looooong time, there are probably better ways of doing it now.

Hi Bryan - It was 'ssh-shell-command-groovy'.

I'm having a total ball ache trying to automate my NAS. It's powered on and disks spinning 24/7 and it's used for one purpose - media server for infuse on Apple TV. So running 24/7 but probably used 3/5!

The end game:

  • ReadyNAS will be shutdown but has Wake on LAN enabled
  • Starting the 'Watch Apple TV' activity on Harmony remote will send a WOL packet
  • Switching to any other activity will gracefully shut down the ReadyNAS

I got WOL working from Hubitat, but commanding a shutdown is proving to be a PITA. I can only do it with SSH which I've tried and is working from my Mac; now I need to send the command from Hubitat.

The Sandbox is too locked down to do that on the Hub itself.

AI Explanation:

The Core Problem: The Sandbox

The Hubitat Elevation platform runs Groovy code inside a strict security sandbox . This sandbox is designed to prevent custom apps and drivers from accessing the underlying Linux operating system or the Java Virtual Machine (JVM) in an unsafe way.

Specifically, the sandbox blocks the two essential things required to build an SSH client:

  1. Socket Access: To perform the TCP handshake with an SSH server on port 22, a driver needs to open a raw Socket . Hubitat explicitly blocks all arbitrary socket connections from drivers and apps for security reasons. (The only exceptions are pre-approved HTTP/HTTPS calls via the httpGet and httpPost methods).
  2. Forbidden Imports: A proper SSH client requires cryptographic libraries (for key exchange, encryption, etc.) and streaming libraries. Any import that starts with java.security or javax.crypto is strictly prohibited in the sandbox. Even if you could open a socket, you couldn't perform the encryption handshake.

Because of these two restrictions, any attempt to write a driver like new Socket("host", 22) or import com.jcraft.jsch.* will result in a SecurityException and the driver will fail to run.

Option 1: The Cloud Relay (Most Common)

You run a small bridge service on a computer inside your network (a Raspberry Pi, an always-on PC, or a Docker container). This service is not constrained by the Hubitat sandbox and can run a full SSH client (like a Python script using paramiko or a Node.js script).

  • How it works:
    1. Hubitat Driver makes an HTTP POST request to http://192.168.1.100:8080/ssh with the command in the body.
    2. The local bridge service receives the HTTP request.
    3. The bridge establishes the SSH connection to your target server (e.g., a Proxmox host, another Pi), runs the command, and gets the output.
    4. The bridge sends the output back to the Hubitat driver in the HTTP response.

Option 2: Router/Device Native API (Best Practice)

Instead of forcing SSH, look for an API.

  • If you are targeting a router: Most routers (ASUS, DD-WRT, OpenWrt, Ubiquiti) offer a REST API or can be controlled via simple HTTP requests.
  • If you are targeting a server: Look for a web service or a database connection.
1 Like

@chrisbvt - Don't believe the AI! They just talk crap and when you point out that the solution doesn't work at all they return 'Ah yes, that's because a, b, c - do this it'll 100% work' So you try the suggestion and it doesn't work - 'Ah yes your 100% correct, that's because of x, y, z' ad infinitum.

All I asked AI is if the Groovy Sandbox limits the ability to use SSH in Hubitat code, which I already knew was true. I didn't ask for a solution, I just wanted it to explain why it cannot be done in the sandbox.

The solution it gave on its own at the end also makes total sense to me as workable, using the PI for ssh, and using HTTP POST from the sandbox to interface with it, though I didn't ask AI for a solution. I just included what it gave me since I don't see any reason that is not workable. The most common use of PIs with Hubitat is to expand the limitations of the sandbox (Like the Echo Speaks Cookie Server on a PI, for example).

Your point on AI is true, but I don't see where it is hallucinating in that answer it gave me.

AI is as useless as it is useful. Over the last month I've been mind blown by what is possible, while at the same time been stressed and frustrated beyond belief. I'll have another beer and vent my frustration at ChatGPT

bbc comedy GIF

See what I mean......

As I alluded in my OP 'ChatGPT is an A hole'

So.....Can anyone recommend a switchbot :joy:

I just got a Copilot license for MS365 at work last week. It is amazing how useful that can be, especially to search through all your Team chats to find when you or someone else mentioned something, or find emails, summarize long emails, rewrite emails to have a different tone, write emails for you given some data... I'm having fun playing with that.

I was in a Team Chat on Friday discussing a recent incident, and I was asked for a summary of my correspondence with the vendor about the issue. I was able to get AI to give me a brief summary of what we had talked about, and on what dates. I just copy pasted that into the Team chat as my response, without even looking through emails at all.

We are being pushed at work to use AI in our job, so the fact I pasted in the AI summary was not considered a bad thing, it actually shows I am using the AI tools they want us to be using.

It can do pretty extensive stuff in Excel for you too. AI is really best at performing a task, not giving factual information on a topic.

2 Likes

Have you looked into installing a webhook on that thing? Could probably be a simple python script. The webhook can trivially be called by HE.

1 Like

None of the commands would work. I 'think' I've found a solution I'm trying at the moment. I'll try and set it up in node-red and than trigger that flow from Hubitat

Which commands?

I don't have a ReadyNAS, but a long time ago I used the approached suggested by @hubitrep to shutdown/reboot a LenovoEMC ix4-300d NAS.

What OS does the ReadyNAS run?

Not a clue. I've finally got it working:

  • SSH enabled on the ReadyNAS
  • SSH key generated on Pi and copied to ReadyNAS
  • node-red flow. http in (/nas/shutdown) > exec (ssh root@ReadyNAS_IP "shutdown -h now")
  • Rule will Send GET to: http://ReadyNAS_IP:1880/nas/shutdown

So to complete what I wanted to do I just need to:

  • Have my Harmony 'Watch Apple TV' activity trigger a rule that has my Wake on LAN device send the wake command
  • Have a rule that sends the shutdown GET to the Pi when any other Harmony activity is called
  • Create two virtual switches - one for wake, one for shutdown that I'll use in dashboards/Apple home (these will be needed so I can manually turn the NAS on to transfer media files
2 Likes