Help with Particle "DO"(httppost) button device handler for ST


(Chris Kulakowski) #1

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)}
}


(Tony Fleisher) #2

I would use capability actuator for this.


#3

There’s already a DTH out therefor this. HTTP button handler.


(Chris Kulakowski) #4

Ok actuator and switch capabilities work in ST, but its not working in the Alexa app. Alexa thinks its a switch with states “on” and “off”. I just want a button in Alexa just like it shows in SmartThings. Any ideas?


(Chris Kulakowski) #5

OK, I got it! The work around was basically configuring “on” and “off” to both run the http post… I really dont care about state for this so It didn’t matter. Then I created a routine that triggers it “on” and it works great. Thanks for your help guys.