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)
- Download the Shortcuts app and the Scriptable app from the App Store
- 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)
- 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)
- Create a shortcut in the Shortcuts app
- Add a text block and copy and paste your device ID into it
- Add a set variable command to name your variable (in my case boiler ID)
- Repeat steps 2 and 3 for your Particle Cloud access_token
- 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
- 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)
- Add a Get Dictionary from Input block
- Add a Dictionay Value block and Get the Key return_value
- 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