iOS Shortcuts with HA (No SSL Required)

I haven’t seen anyone post about using the new shortcuts app to control Home Assistant so I figured I would share my progress with it here in case there was any interest withing the community. This is one out of the five projects that I hope to share this month. I’m sure there’s other ways of making shortcuts that talk to HA but this is just what I’ve personally tested so far and know works.

Big thanks to @DrZzs for helping me test this without SSL!

To get started download the Shortcuts App on your iOS device

Once you have it installed and ready open it up and click Create Shortcut.

Now we’re ready to create our first shortcut! We’ll start off with an easy Service Call to toggle a light using the Rest API!

Toggling the state of an entity

  1. Tap the search button and then type in URL.

  2. Fill in the URL to match your HA address and service call.

Examples:
https://yourhomeassistanturl.com/api/services/light/toggle http://yourexternalip:8123/api/services/light/toggle

  1. Then click the search bar again and this time type in Get Contents of URL.
  2. Once you have the new block added click Adavnced and change the Method type to POST.
  3. After that click on Headers and add a new header.
  4. Change the name of the key block to Authorization
  5. Change the name of the text block to Bearer your long-lived access token

Example:
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwMTg1blahblahblah

  1. Then in the Request Body click add new field and select text.
  2. Change the name of the key block to entity_id
  3. Change the name of the text block to match the name of the light you would like to toggle.

And that’s it… If you just wanna toggle Lights, Switches, Input Booleans, etc…

If you also want to receive the state back of the entity of choice then follow the rest of this tutorial. If you just care about turning stuff on and off then just leave now and go have fun with your new shortcuts.

Receiving the state of an entity

Follow these screenshots if you would like to also receive the state of the entity.
I will update this tutorial with written documentation tomorrow but for now I will just post the screenshots as at this point you should have the idea of how to do this.

Add the shortcut to Siri or the home screen

If you would like to be able to control your new shortcut with Siri or from the home screen then click the icon at the top right and click either add to sir, add to home screen, or both.

6 Likes

I’ve been using this for a few years and my best use-case is having a button to unlock the front door on the widgets screen (you used to be able to do it with your iWatch but that was removed. Feel free to yell at Apple!!).

I’d be curious what other uses people have found for this.

I came across this thread while watching @DrZzs stream rewind. Instead of Get Text From Input I am using Get Dictionary Value.

Add Get Dictionary Value
Choose Value
Set Key to ‘state’.

The output I get is either on or off. Since I am getting a reliable report, I skip the If statement and display the state with Show Notification.

Add Show Notification
Enter Light State for the Title
Choose the Dictionary Value variable

Based on @frenck’s suggestion on the stream, I attempted to make a Webhook Automation. But I can’t seem to get Shortcuts to trigger it.

alias: light_toggle
initial_state: True
trigger:
  platform: webhook
  webhook_id: light_toggle
action:
  - service: light.toggle
    entity_id: light.family_room_table_lamp
    #entity_id: "{{ trigger.payload_json.entity_id }}"
    #entity_id: "{{ trigger.payload }}"

I can’t even get it to work with the entity_id hard coded, but I assume we should be able to pass JSON values into it. Unfortunately I cannot find any fully working webhooks examples for reference. :frowning:

1 Like


Great app, I have been using it for a while. I use a reusable script in shortcuts to trigger scripts and automations. This cuts down on the amount of shortcut admin and makes things a bit simpler.

I also have a decision tree that checks if I am at home or out of my house. If at home, it targets my HA local ip address; otherwise it targets my external IP.

2 Likes

any tips on how to use Siri Shortcut to run direct commands to devices with tasmota
for example. Siri Shortcut to turn on a sonoff switch to execute this URL

http://sonoff/cm?&user=put_username_here&password=put_password_here&cmnd=Power%20On

Above examle is for hass urls…i just want to try direct to tasmota firmware. Thanks

Hmmm I’m not really sure about that. @DrZzs or @TheHookUp might have an answer for that.

I wrote a Shortcut to quickly adjust a Home Assistant thermostat from the Shortcuts widget a while back. It’s way faster than waiting for the HA/Nest/Ecobee/etc app to load! https://www.reddit.com/r/shortcuts/comments/apet77/thermostat_quick_adjust_for_home_assistant/

Thanks for the great post, it added much fun to home automation as I can build dialogs with Siri saying custom phrases and getting funny responses.
I would also add a link here on how to get values from JSON data you receive from HA https://support.apple.com/guide/shortcuts/get-dictionary-value-action-apdf01294032/ios

I’m getting a “401: Unauthorized”
Anyone know if the api access method has changed or if I’m missing something?

Figured out my issue, be careful when filling out the field using auto correct or suggested spelling on a phone. The “Authorization” field was entered with a space after it.

Here’s a shortcut link.
https://www.icloud.com/shortcuts/f13333d4866a481b818d8ddc6500392d

Quick question about this, if you have no SSL, wouldn’t it send your HA token over plaintext ?

Thanks for this! Is there a way to change Siri’s confirmation message? Right now the answer is “OK. Called light.turn_on” or “OK. Called service”. Would it be possible to have the response be “OK. Turned light on” or something similarly natural?

This is awesome. I have been trying to create a toggle button for my locks. I am able to do lock and unlock independently using the call service option but not able to find it to do with one button. If anyone has done this, please send me some tips on how to do it.