Siri Shortcuts with iOS 12

Hi,

I’ve been tinkering with Siri Shortcuts for a couple of days and I thought I would share the news that since iOS 12 you can now interact with the Particle Cloud using your voice. I have a Photon making temperature readings inside the house that’s now read out loud by Siri. And since there is a Photon managing my boiler I can also set a new temperature using voice commands.

Quick tutorial: To read a variable from the Particle Cloud (in my case, the current temperature)

  1. Download the Shortcuts app and the Scriptable app from the App Store
  2. Create a script in Scriptable to fetch the variable
Scriptable code snippet

let url = "https://api.particle.io/v1/devices/your-device-id/your-variable?access_token=your-access-token"
let req = new Request(url)
let json = await req.loadJSON()

let SalonTemp = json.result

// My temperature is in centigrade and multiplied by 10 so that I don’t have to bother with decimals in my code
let OutputTxt = "The temperature is " + SalonTemp/10 + "°C"
QuickLook.present(OutputTxt)
Speech.speak(OutputTxt)

  1. Create a shortcut in the Shortcuts app to run the script and speak the text

Quick tutorial: To call a function in the Particle Cloud (in my case, the set the target temperature)

  1. Create a shortcut in the Shortcuts app
  2. Add a text block and copy and paste your device ID into it
  3. Add a set variable command to name your variable (in my case boiler ID)
  4. Repeat steps 2 and 3 for your Particle Cloud access_token
  5. Add a URL block and copy and paste the following URL into it: https://api.particle.io/v1/devices/your device id variable/your function
  6. Add a Get Contents of URL block and set it to Post using a Form, add two text fields to the form: arg (set this to whatever your function is expecting) ; access_token (set this to the access_token variable)
  7. Add a Get Dictionary from Input block
  8. Add a Dictionay Value block and Get the Key return_value
  9. Add a Speak Text block and Siri will read the return value to you, you can also set up conditional statements to check the result as I have done in the screenshot below

Voila, spoken commands for Particle. I’m pretty sure that Scriptable is an optional component, the Dictionary Value technique illustrated in the second example would work fine. I hope this helps someone, cheers

7 Likes

This actually gives me a reason to update to iOS 12. Thanks. I’ll try this today.

1 Like

(OT but it's actually a massive performance boost)

Thank you mayhew1955, exactly what I was looking for!!

Siri Shortcuts at work.

thanks again @mayhew1955

You’re welcome, thanks for sharing your project