Hello community, I’ve been working on an IoT project to automate feeding of our obnoxious cat in the mornings and when we are out of town. I’m using a particle photon to control a servo attached to a cereal dispenser to dispense the food. The project is 90% complete as I’ve been able to use IFTTT to feed the cat by schedule and by Alexa voice command. However, I want to take this a step further so I can use a “Feed” button in SmartThings and also invoke the action without using the word “Trigger” which IFTTT requires.
Since the command to the particle is a simple HTTP POST, I’m hung up on what capability to be using for this. I’ve tried a number of them and none work. The UI is exactly what I want, just need to get the “do” functionality to work. Any help would be great! Thanks.
/**
* Cat Feeder Device Handler for SmartThings
* Author: Chris Kulakowski
*/
preferences {
section("Your Particle credentials and device Id:") {
input("token", "text", title: "Access Token")
input("deviceId", "text", title: "Device ID")
}
}
// for the UI
metadata {
definition (name: "Pet Feeder", namespace: "smartthings", author: "Chris Kulakowski") {
command "feed"
capability "execute"
}
// tile definitions
tiles {
standardTile("feeder", "device.execute", width: 3, height: 3, canChangeIcon: true) {
state "default", label: "Feed", action: "feed", icon: "st.shields.shields.pet-feeder", backgroundColor: "#ffffff"
}
main "feeder"
details "feeder"
}
}
def parse(String description) {
log.error "This device does not support incoming events"
return null
}
def feed() {
sendToDevice "feed"
}
private sendToDevice(cmd) {
// Particle API call to photon device
// "deviceId" will be replaced with our actual device name
// feed is the name of our published function exposed by the device
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceId}/feed",
body: [access_token: token, command: cmd],
) {response -> log.debug (response.data)}
}