To do what exactly?
Hey keiron1992, please tell us how did you do that. I ask because you can’t create an automation in Apple Home to trigger a shortcut. Thats not possible at the moment.
Hi @fmon, this may be too late and I don’t tried it yet, but check out Run shortcuts from the command line - Apple Support, it says you can run Siri shortcuts from the shell, so maybe you can run via ssh or something else. Sorry for my english!!
Create a switch in HomeKit. Create an automation that runs your shortcut when that switch turns on or off.
I can’t create a Personal automation that’s triggered by a switch turning on/off, I can only create a Home automation. But a Home automation, even if I use “Convert To Shortcut”, can’t run a shortcut.
What am I missing?
Edit: The Convert to Shortcut option in a home automation only has a fraction of actions available. Significantly less than what’s available for personal automations and shortcuts. That’s why I don’t understand how having a switch in HomeKit can trigger a regular shortcut.
I’ve tried everything to get this working with a company supplied iPhone and it’s not possible to have a virtual switch trigger a Personal Automation.
Why anyone using Home Assistant would choose to use an iPhone is beyond me. It’s so restrictive and there’s so little you can do with it compared to Android.
This is interesting… what else can you do besides shortcuts?
There is no direct way but a workaround.
To run personal automations in shortcuts on iOS:
Create a dummy switch in home assistant (or dummy powerstrip if you want to run more shortcuts) and add it to your HomeKit bridge.
Have an automation in home assistant be triggered by the changed state of the previously named switch and then have the same automation send an email with a specific subject using SMTP integration from home assistant.
In shortcuts create a personal automation that checks your email for a new email from a certain sender with a certain subject and then have it run any shortcut you’d like.
I’m wondering if it really is a technical need, that we click on the notification to start a shortcut.
I bet behind the scene, a callback in the app is executed in the background that starts the shortcut.
As we already have silent notifications (this doesn’t mean no sound. It’s the term Apple uses for notifications that aren’t visible to the user, but allow the app to run a few seconds in the background. HA Companion already uses this e.g. for clearing the badge using a notification):
Wouldn’t it be possible to use a new message-identifier together with the shortcut key in the message data to run a shortcut?
For thing that doesn’t need user interaction like changing iOS focus settings …
Executing a shortcut requires launching the Shortcuts app which cannot be done in the background.
Email trigger on iPhone is not able to run without notification and confirm. You will still get a notification without any specific information from Shortcuts app.
PushCut app is able to achieve some of our goals, but it requires another iOS device as a server and always-on (app runs on front). When it becomes a server it shows all black… And there is nothing we can use with that part of black screen.
But when Home Assistant app runs on front, it could be a dashboard! I wish one day Home Assistant iOS Companion App could add this feature.
I’m using HA’s ssh integration combined with the macOS shortcuts shell command to, among other things, run an always-on Mac as a Shortcuts server. It works reliably to subvert confirmation messages and all the other folderol for which I previously relied on Pushcuts, IFTT, etc.
The shortcuts
command is just one possibility: HA can send whatever shell commands you like to any remote Mac, sending either a complete command, or for more complex applications, executing a script on the remote Mac. So far as Shortcuts (or any other app) is concerned, it’s all being run on the Mac, which subverts most if not all of Apple’s security nannying.
The only tricky part is implementing key pair encryption for secure password-free access to the Mac on the HA host. Key generation and installing HA’s public key on the Mac is as usual, but the HA server requires some fancy footwork. First, because most installations run Home Assistant in a container rather than directly on the host, and keys have to be accessible from within the container, not just on the host. Second, since HA updates have the potential to wipe out everything but the config
directory, there’s little point installing anything anywhere else.
Handily, both problems have a single, straightforward solution: on the HA side, implement keys and known_hosts
in a subdirectory of /config/
. (I use /config/.ssh
for consistency, but it’s arbitrary, provided you make sure the directory and its contents have the correct permissions.) Then specify the HA key and known hosts file to be used in the command itself.
ssh \
-i /config/.ssh/id_rsa \
-o UserKnownHostsFile=/config/.ssh/known_hosts \
[email protected] \
/usr/bin/shortcuts "Vacuum the Dog House"
Note: The above use of \ to split the command into lines for readability won’t work in a HA’s YAML, so put it all on one line.
Multiple commands can be combined using the usual 'nix ;
and &&
, or created as individual entries in /config/
.
Once set up, any script or automation can execute anything on the remote Mac simply by calling the desired command as an SSH service. HA can tell the Mac to do pretty much anything that’s executable from the command line and doesn’t require interaction. I’m experimenting with Shortcuts, AppleScript, and shell scripts, all with good results. My only complaint is that there appears to be no way to get HA to load changes to the shell_command:
configuration without restarting the server.
There are so many more sensors and options available in Android than iOS, it’s more a question of what can’t you do.
You also have notification commands that allow you to more or less anything on the phone, e.g. make a phone call.
As just a few examples:
I use sensor.phone_state
for lots of different things, like announcing my phone is ringing on my Echo speakers in case I am in another room, pausing the TV when a call comes in etc.
I use the bluetooth sensors to tell when I am getting into and out of my car (and when I am in it) and various other things like if my wallet has been left behind.
I use sensor.next_alarm
to know when I am getting up each day.
The battery sensors actually work properly on Android, unlike on iOS which only sends updates when it arbitrarily decides it wants to due to restricted background processes. I use these to announce on my Echo speakers my phone has reached full charge when it’s come from a low charge level, so I don’t need to keep checking to see if it’s full and to remind me to charge my phone when I come home and the battery is low.
When Local Push is enabled (e.g. when you are on Wi-Fi and have Local Push turned on) the app will update the sensors relatively immediately for things like battery state, so for at least the case of “when is charge finished?” you can determine that.
But at the end of the day, iOS is significantly less capable than Android when it comes to allowing third party apps to do things. Unfortunately until and unless we get permission to do things, Sandbox restrictions prevent the app from doing fun things like e.g. running a Shortcut from the background.
The macOS app could run Shortcuts though, and that’s something that could be added.
And this is why I don’t understand why anyone using Home Assistant would choose iOS over Android. You’re sacrificing so much functionality.
Easy, had an iPad laying around doing nothing and a android is something I need to buy.
Out of interest, I’m just catching up and have installed the Pushcut server on a phone as it was spare. What is the advantage of having an always on Mac vs phone ? If the sole purpose is automating the scripts is there a difference that I should consider before getting in too deep?
Lets come back to this. And also remember the problem back then:
In addition it wasn‘t possible to run automations based on email triggers without clicking on its run notification.
I don’t know when exactly Apple has implemented this but I‘m on iOS 17.2.1 and it now allows me to trigger any shortcut using specific email subjects IN THE BACKGROUND.
Since I use n8n to trigger my systems, this is my workflow:
I trigger a n8n workflow using a webhook. n8n then sends an email to my icloud email account. As soon as the email arrives on my iPhone (usually within a few seconds) the email based automation gets triggered and executes the target iOS shortcut.
No interaction required. Just turn off the email notifications for the trigger messages and regularly auto-clean the inbox. Keep in mind to use an email account type that allows fetching via „push“ to ensure near-realtime triggering. In my case I just used my icloud email account since it doesn‘t serve a purpose anyway.
Happy automating.
also wanna chime in here as I was figuring this out you can use email to text your phone number following this as the receiver List Of Email-To-SMS Addresses - AVTECH in case you have multiple shortcuts you want to run based on text message