MacroDroid integration
MacroDroid is an Android automation app that can open a zestssh:// URL with its “Open Website / URL” action. Android hands the URL to ZestSSH, which runs the command, snippet, batch or workflow it names.
How it works
Section titled “How it works”- MacroDroid opens a
zestssh://URL, and Android routes it to ZestSSH. - ZestSSH shows Run this from a link?, naming what would run and on which host, and waits.
- When you tap Run, ZestSSH checks the API key in the URL, signs in to the host, runs the command, and logs the result in its automation history.
Any app or web page can open a URL, so a URL never runs before you tap Run. A macro on a timer or an NFC tag therefore stops at that question until you answer it.
To run with nobody at the phone, send ZestSSH an Android intent instead of opening a URL: an intent runs without the question. ZestSSH takes the intent from any app that sends it to its activity. The actions and extras are on the Tasker integration page.
Whichever way you use, a run signs in only with SSH keys switched to Allow unattended runs in Keys, and only to hosts whose host key this device already trusts.
Setup steps
Section titled “Setup steps”1. Create an API key
Section titled “1. Create an API key”- Open ZestSSH and go to More > Automation. Turn on External automation (needs Squeezed).
- Tap API keys, then + (or Create API key).
- Enter a label, for example “MacroDroid”.
- Optionally pick an expiration.
- Tap Create. In Save your API key, copy the key, tick I’ve copied this key somewhere safe, and tap Done. You need the key for the URL, and ZestSSH shows it only this once.
2. Create a MacroDroid macro
Section titled “2. Create a MacroDroid macro”- Open MacroDroid and tap Add Macro.
- Add Trigger: choose any trigger (a time, an NFC tag, a widget button, and so on).
- Add Action: select Applications > Open Website / URL.
- Paste your
zestssh://URL into the URL field (see the URL formats below). - Uncheck Use Built-in Browser, so the URL goes to ZestSSH and not to a web view.
- Save the macro.
3. Test the macro
Section titled “3. Test the macro”Tap the macro’s play button. ZestSSH opens and asks Run this from a link?. Tap Run. The result is in More > Automation > Automation history.
URL formats
Section titled “URL formats”Execute a command
Section titled “Execute a command”zestssh://execute?connection=HOST_NAME&command=COMMAND&key=API_KEYOptional: timeout (seconds, default 30, up to 300), grep (filter pattern), head (first N lines), tail (last N lines).
Run a snippet
Section titled “Run a snippet”zestssh://snippet?connection=HOST_NAME&name=SNIPPET_NAME&key=API_KEYOptional: var_NAME=value for each {{NAME}} or ${NAME} in the snippet. The question shows the snippet’s command with your values filled in.
Run a batch
Section titled “Run a batch”zestssh://batch?connections=HOST1,HOST2,HOST3&command=COMMAND&key=API_KEYOptional: parallel=true (default) or parallel=false, timeout, grep, head, tail.
Run a workflow
Section titled “Run a workflow”zestssh://workflow?name=WORKFLOW_NAME&key=API_KEYOr by ID: zestssh://workflow?id=WORKFLOW_ID&key=API_KEY.
Open a host
Section titled “Open a host”These take no API key and run nothing by themselves:
zestssh://connect?name=HOST_NAMEasks Connect to HOST_NAME? and opens a session to that saved host when you tap Connect.zestssh://connect?host=192.168.10.5&user=alex&port=22opens Quick connect with that address typed in.
Webhooks
Section titled “Webhooks”A callback parameter on a zestssh:// URL is ignored. ZestSSH sends a webhook only for a request that arrives as an Android intent (see the Tasker page).
Examples
Section titled “Examples”Morning health check
Section titled “Morning health check”Trigger: a time trigger, every day at 7:00 AM. Action: Open Website / URL:
zestssh://execute?connection=web-01&command=uptime%20%26%26%20df%20-h%20%2F&key=YOUR_API_KEY(The command, URL-encoded, is uptime && df -h /.)
Restart a Docker container from a widget
Section titled “Restart a Docker container from a widget”Trigger: a MacroDroid widget button. Action: Open Website / URL:
zestssh://snippet?connection=docker-01&name=Restart%20container&var_DOCKER=nginx-proxy&key=YOUR_API_KEYCheck disk usage on several hosts
Section titled “Check disk usage on several hosts”Trigger: any trigger. Action: Open Website / URL:
zestssh://batch?connections=web-01,web-02,db-01&command=df%20-h%20%2F¶llel=true&key=YOUR_API_KEYDeploy from an NFC tag
Section titled “Deploy from an NFC tag”Trigger: an NFC tag scan. Action: Open Website / URL:
zestssh://execute?connection=staging-01&command=cd%20%2Fapp%20%26%26%20git%20pull&key=YOUR_API_KEYURL encoding
Section titled “URL encoding”Special characters in a command must be URL-encoded. Common ones:
| Character | Encoded |
|---|---|
| space | %20 |
/ |
%2F |
& |
%26 |
= |
%3D |
| |
%7C |
A URL longer than 2,048 characters, or with any value longer than 256 characters, is refused. Put a long command into a snippet and run the snippet.
Using the Automation wizard
Section titled “Using the Automation wizard”The quickest way to a correct URL is ZestSSH’s Automation wizard:
- Go to More > Automation > Automation wizard (shown while automation is on).
- Walk through the steps: the action, the host, the command, and any filters.
- In Your automation, the MacroDroid card has the setup steps, and its copy button copies the URL. Where the URL says
YOUR_KEY, paste your API key, or use Make a new key for this to make one that the URL then holds until you close the wizard.
- Keep your URLs private: anyone with the URL and its key can ask ZestSSH to run commands on your hosts.
- For several steps, run a workflow URL instead of chaining macros.